Skip to content

Commit 8f51c8d

Browse files
committed
rustfmt liballoc
1 parent afae2ff commit 8f51c8d

File tree

7 files changed

+244
-115
lines changed

7 files changed

+244
-115
lines changed

src/liballoc/arc.rs

+54-24
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,9 @@ impl<T> Arc<T> {
214214
#[stable(feature = "arc_unique", since = "1.4.0")]
215215
pub fn try_unwrap(this: Self) -> Result<T, Self> {
216216
// See `drop` for why all these atomics are like this
217-
if this.inner().strong.compare_and_swap(1, 0, Release) != 1 { return Err(this) }
217+
if this.inner().strong.compare_and_swap(1, 0, Release) != 1 {
218+
return Err(this)
219+
}
218220

219221
atomic::fence(Acquire);
220222

@@ -251,7 +253,9 @@ impl<T: ?Sized> Arc<T> {
251253
let cur = this.inner().weak.load(Relaxed);
252254

253255
// check if the weak counter is currently "locked"; if so, spin.
254-
if cur == usize::MAX { continue }
256+
if cur == usize::MAX {
257+
continue
258+
}
255259

256260
// NOTE: this code currently ignores the possibility of overflow
257261
// into usize::MAX; in general both Rc and Arc need to be adjusted
@@ -348,7 +352,9 @@ impl<T: ?Sized> Clone for Arc<T> {
348352
// We abort because such a program is incredibly degenerate, and we
349353
// don't care to support it.
350354
if old_size > MAX_REFCOUNT {
351-
unsafe { abort(); }
355+
unsafe {
356+
abort();
357+
}
352358
}
353359

354360
Arc { _ptr: self._ptr }
@@ -556,7 +562,9 @@ impl<T: ?Sized> Drop for Arc<T> {
556562
// Because `fetch_sub` is already atomic, we do not need to synchronize
557563
// with other threads unless we are going to delete the object. This
558564
// same logic applies to the below `fetch_sub` to the `weak` count.
559-
if self.inner().strong.fetch_sub(1, Release) != 1 { return }
565+
if self.inner().strong.fetch_sub(1, Release) != 1 {
566+
return
567+
}
560568

561569
// This fence is needed to prevent reordering of use of the data and
562570
// deletion of the data. Because it is marked `Release`, the decreasing
@@ -577,9 +585,7 @@ impl<T: ?Sized> Drop for Arc<T> {
577585
// [1]: (www.boost.org/doc/libs/1_55_0/doc/html/atomic/usage_examples.html)
578586
atomic::fence(Acquire);
579587

580-
unsafe {
581-
self.drop_slow()
582-
}
588+
unsafe { self.drop_slow() }
583589
}
584590
}
585591

@@ -613,11 +619,15 @@ impl<T: ?Sized> Weak<T> {
613619
// "stale" read of 0 is fine), and any other value is
614620
// confirmed via the CAS below.
615621
let n = inner.strong.load(Relaxed);
616-
if n == 0 { return None }
622+
if n == 0 {
623+
return None
624+
}
617625

618626
// Relaxed is valid for the same reason it is on Arc's Clone impl
619627
let old = inner.strong.compare_and_swap(n, n + 1, Relaxed);
620-
if old == n { return Some(Arc { _ptr: self._ptr }) }
628+
if old == n {
629+
return Some(Arc { _ptr: self._ptr })
630+
}
621631
}
622632
}
623633

@@ -653,7 +663,9 @@ impl<T: ?Sized> Clone for Weak<T> {
653663

654664
// See comments in Arc::clone() for why we do this (for mem::forget).
655665
if old_size > MAX_REFCOUNT {
656-
unsafe { abort(); }
666+
unsafe {
667+
abort();
668+
}
657669
}
658670

659671
return Weak { _ptr: self._ptr }
@@ -705,9 +717,7 @@ impl<T: ?Sized> Drop for Weak<T> {
705717
// ref, which can only happen after the lock is released.
706718
if self.inner().weak.fetch_sub(1, Release) == 1 {
707719
atomic::fence(Acquire);
708-
unsafe { deallocate(ptr as *mut u8,
709-
size_of_val(&*ptr),
710-
align_of_val(&*ptr)) }
720+
unsafe { deallocate(ptr as *mut u8, size_of_val(&*ptr), align_of_val(&*ptr)) }
711721
}
712722
}
713723
}
@@ -727,7 +737,9 @@ impl<T: ?Sized + PartialEq> PartialEq for Arc<T> {
727737
///
728738
/// five == Arc::new(5);
729739
/// ```
730-
fn eq(&self, other: &Arc<T>) -> bool { *(*self) == *(*other) }
740+
fn eq(&self, other: &Arc<T>) -> bool {
741+
*(*self) == *(*other)
742+
}
731743

732744
/// Inequality for two `Arc<T>`s.
733745
///
@@ -742,7 +754,9 @@ impl<T: ?Sized + PartialEq> PartialEq for Arc<T> {
742754
///
743755
/// five != Arc::new(5);
744756
/// ```
745-
fn ne(&self, other: &Arc<T>) -> bool { *(*self) != *(*other) }
757+
fn ne(&self, other: &Arc<T>) -> bool {
758+
*(*self) != *(*other)
759+
}
746760
}
747761
#[stable(feature = "rust1", since = "1.0.0")]
748762
impl<T: ?Sized + PartialOrd> PartialOrd for Arc<T> {
@@ -776,7 +790,9 @@ impl<T: ?Sized + PartialOrd> PartialOrd for Arc<T> {
776790
///
777791
/// five < Arc::new(5);
778792
/// ```
779-
fn lt(&self, other: &Arc<T>) -> bool { *(*self) < *(*other) }
793+
fn lt(&self, other: &Arc<T>) -> bool {
794+
*(*self) < *(*other)
795+
}
780796

781797
/// 'Less-than or equal to' comparison for two `Arc<T>`s.
782798
///
@@ -791,7 +807,9 @@ impl<T: ?Sized + PartialOrd> PartialOrd for Arc<T> {
791807
///
792808
/// five <= Arc::new(5);
793809
/// ```
794-
fn le(&self, other: &Arc<T>) -> bool { *(*self) <= *(*other) }
810+
fn le(&self, other: &Arc<T>) -> bool {
811+
*(*self) <= *(*other)
812+
}
795813

796814
/// Greater-than comparison for two `Arc<T>`s.
797815
///
@@ -806,7 +824,9 @@ impl<T: ?Sized + PartialOrd> PartialOrd for Arc<T> {
806824
///
807825
/// five > Arc::new(5);
808826
/// ```
809-
fn gt(&self, other: &Arc<T>) -> bool { *(*self) > *(*other) }
827+
fn gt(&self, other: &Arc<T>) -> bool {
828+
*(*self) > *(*other)
829+
}
810830

811831
/// 'Greater-than or equal to' comparison for two `Arc<T>`s.
812832
///
@@ -821,11 +841,15 @@ impl<T: ?Sized + PartialOrd> PartialOrd for Arc<T> {
821841
///
822842
/// five >= Arc::new(5);
823843
/// ```
824-
fn ge(&self, other: &Arc<T>) -> bool { *(*self) >= *(*other) }
844+
fn ge(&self, other: &Arc<T>) -> bool {
845+
*(*self) >= *(*other)
846+
}
825847
}
826848
#[stable(feature = "rust1", since = "1.0.0")]
827849
impl<T: ?Sized + Ord> Ord for Arc<T> {
828-
fn cmp(&self, other: &Arc<T>) -> Ordering { (**self).cmp(&**other) }
850+
fn cmp(&self, other: &Arc<T>) -> Ordering {
851+
(**self).cmp(&**other)
852+
}
829853
}
830854
#[stable(feature = "rust1", since = "1.0.0")]
831855
impl<T: ?Sized + Eq> Eq for Arc<T> {}
@@ -854,7 +878,9 @@ impl<T> fmt::Pointer for Arc<T> {
854878
#[stable(feature = "rust1", since = "1.0.0")]
855879
impl<T: Default> Default for Arc<T> {
856880
#[stable(feature = "rust1", since = "1.0.0")]
857-
fn default() -> Arc<T> { Arc::new(Default::default()) }
881+
fn default() -> Arc<T> {
882+
Arc::new(Default::default())
883+
}
858884
}
859885

860886
#[stable(feature = "rust1", since = "1.0.0")]
@@ -1015,7 +1041,7 @@ mod tests {
10151041
#[test]
10161042
fn weak_self_cyclic() {
10171043
struct Cycle {
1018-
x: Mutex<Option<Weak<Cycle>>>
1044+
x: Mutex<Option<Weak<Cycle>>>,
10191045
}
10201046

10211047
let a = Arc::new(Cycle { x: Mutex::new(None) });
@@ -1095,7 +1121,9 @@ mod tests {
10951121

10961122
// Make sure deriving works with Arc<T>
10971123
#[derive(Eq, Ord, PartialEq, PartialOrd, Clone, Debug, Default)]
1098-
struct Foo { inner: Arc<i32> }
1124+
struct Foo {
1125+
inner: Arc<i32>,
1126+
}
10991127

11001128
#[test]
11011129
fn test_unsized() {
@@ -1108,5 +1136,7 @@ mod tests {
11081136
}
11091137

11101138
impl<T: ?Sized> borrow::Borrow<T> for Arc<T> {
1111-
fn borrow(&self) -> &T { &**self }
1139+
fn borrow(&self) -> &T {
1140+
&**self
1141+
}
11121142
}

0 commit comments

Comments
 (0)