Skip to content

Commit 0683d36

Browse files
committed
Auto merge of #28610 - nrc:fmt6, r=brson
2 parents 6a21874 + 459f772 commit 0683d36

File tree

7 files changed

+258
-106
lines changed

7 files changed

+258
-106
lines changed

src/liballoc/arc.rs

Lines changed: 61 additions & 23 deletions
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
@@ -303,7 +307,9 @@ impl<T: ?Sized> Arc<T> {
303307

304308
if self.inner().weak.fetch_sub(1, Release) == 1 {
305309
atomic::fence(Acquire);
306-
deallocate(ptr as *mut u8, size_of_val(&*ptr), align_of_val(&*ptr))
310+
deallocate(ptr as *mut u8,
311+
size_of_val(&*ptr),
312+
align_of_val(&*ptr))
307313
}
308314
}
309315
}
@@ -348,7 +354,9 @@ impl<T: ?Sized> Clone for Arc<T> {
348354
// We abort because such a program is incredibly degenerate, and we
349355
// don't care to support it.
350356
if old_size > MAX_REFCOUNT {
351-
unsafe { abort(); }
357+
unsafe {
358+
abort();
359+
}
352360
}
353361

354362
Arc { _ptr: self._ptr }
@@ -556,7 +564,9 @@ impl<T: ?Sized> Drop for Arc<T> {
556564
// Because `fetch_sub` is already atomic, we do not need to synchronize
557565
// with other threads unless we are going to delete the object. This
558566
// same logic applies to the below `fetch_sub` to the `weak` count.
559-
if self.inner().strong.fetch_sub(1, Release) != 1 { return }
567+
if self.inner().strong.fetch_sub(1, Release) != 1 {
568+
return
569+
}
560570

561571
// This fence is needed to prevent reordering of use of the data and
562572
// deletion of the data. Because it is marked `Release`, the decreasing
@@ -578,7 +588,7 @@ impl<T: ?Sized> Drop for Arc<T> {
578588
atomic::fence(Acquire);
579589

580590
unsafe {
581-
self.drop_slow()
591+
self.drop_slow();
582592
}
583593
}
584594
}
@@ -613,11 +623,15 @@ impl<T: ?Sized> Weak<T> {
613623
// "stale" read of 0 is fine), and any other value is
614624
// confirmed via the CAS below.
615625
let n = inner.strong.load(Relaxed);
616-
if n == 0 { return None }
626+
if n == 0 {
627+
return None
628+
}
617629

618630
// Relaxed is valid for the same reason it is on Arc's Clone impl
619631
let old = inner.strong.compare_and_swap(n, n + 1, Relaxed);
620-
if old == n { return Some(Arc { _ptr: self._ptr }) }
632+
if old == n {
633+
return Some(Arc { _ptr: self._ptr })
634+
}
621635
}
622636
}
623637

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

654668
// See comments in Arc::clone() for why we do this (for mem::forget).
655669
if old_size > MAX_REFCOUNT {
656-
unsafe { abort(); }
670+
unsafe {
671+
abort();
672+
}
657673
}
658674

659675
return Weak { _ptr: self._ptr }
@@ -705,9 +721,11 @@ impl<T: ?Sized> Drop for Weak<T> {
705721
// ref, which can only happen after the lock is released.
706722
if self.inner().weak.fetch_sub(1, Release) == 1 {
707723
atomic::fence(Acquire);
708-
unsafe { deallocate(ptr as *mut u8,
709-
size_of_val(&*ptr),
710-
align_of_val(&*ptr)) }
724+
unsafe {
725+
deallocate(ptr as *mut u8,
726+
size_of_val(&*ptr),
727+
align_of_val(&*ptr))
728+
}
711729
}
712730
}
713731
}
@@ -727,7 +745,9 @@ impl<T: ?Sized + PartialEq> PartialEq for Arc<T> {
727745
///
728746
/// five == Arc::new(5);
729747
/// ```
730-
fn eq(&self, other: &Arc<T>) -> bool { *(*self) == *(*other) }
748+
fn eq(&self, other: &Arc<T>) -> bool {
749+
*(*self) == *(*other)
750+
}
731751

732752
/// Inequality for two `Arc<T>`s.
733753
///
@@ -742,7 +762,9 @@ impl<T: ?Sized + PartialEq> PartialEq for Arc<T> {
742762
///
743763
/// five != Arc::new(5);
744764
/// ```
745-
fn ne(&self, other: &Arc<T>) -> bool { *(*self) != *(*other) }
765+
fn ne(&self, other: &Arc<T>) -> bool {
766+
*(*self) != *(*other)
767+
}
746768
}
747769
#[stable(feature = "rust1", since = "1.0.0")]
748770
impl<T: ?Sized + PartialOrd> PartialOrd for Arc<T> {
@@ -776,7 +798,9 @@ impl<T: ?Sized + PartialOrd> PartialOrd for Arc<T> {
776798
///
777799
/// five < Arc::new(5);
778800
/// ```
779-
fn lt(&self, other: &Arc<T>) -> bool { *(*self) < *(*other) }
801+
fn lt(&self, other: &Arc<T>) -> bool {
802+
*(*self) < *(*other)
803+
}
780804

781805
/// 'Less-than or equal to' comparison for two `Arc<T>`s.
782806
///
@@ -791,7 +815,9 @@ impl<T: ?Sized + PartialOrd> PartialOrd for Arc<T> {
791815
///
792816
/// five <= Arc::new(5);
793817
/// ```
794-
fn le(&self, other: &Arc<T>) -> bool { *(*self) <= *(*other) }
818+
fn le(&self, other: &Arc<T>) -> bool {
819+
*(*self) <= *(*other)
820+
}
795821

796822
/// Greater-than comparison for two `Arc<T>`s.
797823
///
@@ -806,7 +832,9 @@ impl<T: ?Sized + PartialOrd> PartialOrd for Arc<T> {
806832
///
807833
/// five > Arc::new(5);
808834
/// ```
809-
fn gt(&self, other: &Arc<T>) -> bool { *(*self) > *(*other) }
835+
fn gt(&self, other: &Arc<T>) -> bool {
836+
*(*self) > *(*other)
837+
}
810838

811839
/// 'Greater-than or equal to' comparison for two `Arc<T>`s.
812840
///
@@ -821,11 +849,15 @@ impl<T: ?Sized + PartialOrd> PartialOrd for Arc<T> {
821849
///
822850
/// five >= Arc::new(5);
823851
/// ```
824-
fn ge(&self, other: &Arc<T>) -> bool { *(*self) >= *(*other) }
852+
fn ge(&self, other: &Arc<T>) -> bool {
853+
*(*self) >= *(*other)
854+
}
825855
}
826856
#[stable(feature = "rust1", since = "1.0.0")]
827857
impl<T: ?Sized + Ord> Ord for Arc<T> {
828-
fn cmp(&self, other: &Arc<T>) -> Ordering { (**self).cmp(&**other) }
858+
fn cmp(&self, other: &Arc<T>) -> Ordering {
859+
(**self).cmp(&**other)
860+
}
829861
}
830862
#[stable(feature = "rust1", since = "1.0.0")]
831863
impl<T: ?Sized + Eq> Eq for Arc<T> {}
@@ -854,7 +886,9 @@ impl<T> fmt::Pointer for Arc<T> {
854886
#[stable(feature = "rust1", since = "1.0.0")]
855887
impl<T: Default> Default for Arc<T> {
856888
#[stable(feature = "rust1", since = "1.0.0")]
857-
fn default() -> Arc<T> { Arc::new(Default::default()) }
889+
fn default() -> Arc<T> {
890+
Arc::new(Default::default())
891+
}
858892
}
859893

860894
#[stable(feature = "rust1", since = "1.0.0")]
@@ -1015,7 +1049,7 @@ mod tests {
10151049
#[test]
10161050
fn weak_self_cyclic() {
10171051
struct Cycle {
1018-
x: Mutex<Option<Weak<Cycle>>>
1052+
x: Mutex<Option<Weak<Cycle>>>,
10191053
}
10201054

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

10961130
// Make sure deriving works with Arc<T>
10971131
#[derive(Eq, Ord, PartialEq, PartialOrd, Clone, Debug, Default)]
1098-
struct Foo { inner: Arc<i32> }
1132+
struct Foo {
1133+
inner: Arc<i32>,
1134+
}
10991135

11001136
#[test]
11011137
fn test_unsized() {
@@ -1108,5 +1144,7 @@ mod tests {
11081144
}
11091145

11101146
impl<T: ?Sized> borrow::Borrow<T> for Arc<T> {
1111-
fn borrow(&self) -> &T { &**self }
1147+
fn borrow(&self) -> &T {
1148+
&**self
1149+
}
11121150
}

0 commit comments

Comments
 (0)