@@ -214,7 +214,9 @@ impl<T> Arc<T> {
214
214
#[ stable( feature = "arc_unique" , since = "1.4.0" ) ]
215
215
pub fn try_unwrap ( this : Self ) -> Result < T , Self > {
216
216
// 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
+ }
218
220
219
221
atomic:: fence ( Acquire ) ;
220
222
@@ -251,7 +253,9 @@ impl<T: ?Sized> Arc<T> {
251
253
let cur = this. inner ( ) . weak . load ( Relaxed ) ;
252
254
253
255
// 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
+ }
255
259
256
260
// NOTE: this code currently ignores the possibility of overflow
257
261
// into usize::MAX; in general both Rc and Arc need to be adjusted
@@ -348,7 +352,9 @@ impl<T: ?Sized> Clone for Arc<T> {
348
352
// We abort because such a program is incredibly degenerate, and we
349
353
// don't care to support it.
350
354
if old_size > MAX_REFCOUNT {
351
- unsafe { abort ( ) ; }
355
+ unsafe {
356
+ abort ( ) ;
357
+ }
352
358
}
353
359
354
360
Arc { _ptr : self . _ptr }
@@ -556,7 +562,9 @@ impl<T: ?Sized> Drop for Arc<T> {
556
562
// Because `fetch_sub` is already atomic, we do not need to synchronize
557
563
// with other threads unless we are going to delete the object. This
558
564
// 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
+ }
560
568
561
569
// This fence is needed to prevent reordering of use of the data and
562
570
// deletion of the data. Because it is marked `Release`, the decreasing
@@ -577,9 +585,7 @@ impl<T: ?Sized> Drop for Arc<T> {
577
585
// [1]: (www.boost.org/doc/libs/1_55_0/doc/html/atomic/usage_examples.html)
578
586
atomic:: fence ( Acquire ) ;
579
587
580
- unsafe {
581
- self . drop_slow ( )
582
- }
588
+ unsafe { self . drop_slow ( ) }
583
589
}
584
590
}
585
591
@@ -613,11 +619,15 @@ impl<T: ?Sized> Weak<T> {
613
619
// "stale" read of 0 is fine), and any other value is
614
620
// confirmed via the CAS below.
615
621
let n = inner. strong . load ( Relaxed ) ;
616
- if n == 0 { return None }
622
+ if n == 0 {
623
+ return None
624
+ }
617
625
618
626
// Relaxed is valid for the same reason it is on Arc's Clone impl
619
627
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
+ }
621
631
}
622
632
}
623
633
@@ -653,7 +663,9 @@ impl<T: ?Sized> Clone for Weak<T> {
653
663
654
664
// See comments in Arc::clone() for why we do this (for mem::forget).
655
665
if old_size > MAX_REFCOUNT {
656
- unsafe { abort ( ) ; }
666
+ unsafe {
667
+ abort ( ) ;
668
+ }
657
669
}
658
670
659
671
return Weak { _ptr : self . _ptr }
@@ -705,9 +717,7 @@ impl<T: ?Sized> Drop for Weak<T> {
705
717
// ref, which can only happen after the lock is released.
706
718
if self . inner ( ) . weak . fetch_sub ( 1 , Release ) == 1 {
707
719
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) ) }
711
721
}
712
722
}
713
723
}
@@ -727,7 +737,9 @@ impl<T: ?Sized + PartialEq> PartialEq for Arc<T> {
727
737
///
728
738
/// five == Arc::new(5);
729
739
/// ```
730
- fn eq ( & self , other : & Arc < T > ) -> bool { * ( * self ) == * ( * other) }
740
+ fn eq ( & self , other : & Arc < T > ) -> bool {
741
+ * ( * self ) == * ( * other)
742
+ }
731
743
732
744
/// Inequality for two `Arc<T>`s.
733
745
///
@@ -742,7 +754,9 @@ impl<T: ?Sized + PartialEq> PartialEq for Arc<T> {
742
754
///
743
755
/// five != Arc::new(5);
744
756
/// ```
745
- fn ne ( & self , other : & Arc < T > ) -> bool { * ( * self ) != * ( * other) }
757
+ fn ne ( & self , other : & Arc < T > ) -> bool {
758
+ * ( * self ) != * ( * other)
759
+ }
746
760
}
747
761
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
748
762
impl < T : ?Sized + PartialOrd > PartialOrd for Arc < T > {
@@ -776,7 +790,9 @@ impl<T: ?Sized + PartialOrd> PartialOrd for Arc<T> {
776
790
///
777
791
/// five < Arc::new(5);
778
792
/// ```
779
- fn lt ( & self , other : & Arc < T > ) -> bool { * ( * self ) < * ( * other) }
793
+ fn lt ( & self , other : & Arc < T > ) -> bool {
794
+ * ( * self ) < * ( * other)
795
+ }
780
796
781
797
/// 'Less-than or equal to' comparison for two `Arc<T>`s.
782
798
///
@@ -791,7 +807,9 @@ impl<T: ?Sized + PartialOrd> PartialOrd for Arc<T> {
791
807
///
792
808
/// five <= Arc::new(5);
793
809
/// ```
794
- fn le ( & self , other : & Arc < T > ) -> bool { * ( * self ) <= * ( * other) }
810
+ fn le ( & self , other : & Arc < T > ) -> bool {
811
+ * ( * self ) <= * ( * other)
812
+ }
795
813
796
814
/// Greater-than comparison for two `Arc<T>`s.
797
815
///
@@ -806,7 +824,9 @@ impl<T: ?Sized + PartialOrd> PartialOrd for Arc<T> {
806
824
///
807
825
/// five > Arc::new(5);
808
826
/// ```
809
- fn gt ( & self , other : & Arc < T > ) -> bool { * ( * self ) > * ( * other) }
827
+ fn gt ( & self , other : & Arc < T > ) -> bool {
828
+ * ( * self ) > * ( * other)
829
+ }
810
830
811
831
/// 'Greater-than or equal to' comparison for two `Arc<T>`s.
812
832
///
@@ -821,11 +841,15 @@ impl<T: ?Sized + PartialOrd> PartialOrd for Arc<T> {
821
841
///
822
842
/// five >= Arc::new(5);
823
843
/// ```
824
- fn ge ( & self , other : & Arc < T > ) -> bool { * ( * self ) >= * ( * other) }
844
+ fn ge ( & self , other : & Arc < T > ) -> bool {
845
+ * ( * self ) >= * ( * other)
846
+ }
825
847
}
826
848
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
827
849
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
+ }
829
853
}
830
854
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
831
855
impl < T : ?Sized + Eq > Eq for Arc < T > { }
@@ -854,7 +878,9 @@ impl<T> fmt::Pointer for Arc<T> {
854
878
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
855
879
impl < T : Default > Default for Arc < T > {
856
880
#[ 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
+ }
858
884
}
859
885
860
886
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
@@ -1015,7 +1041,7 @@ mod tests {
1015
1041
#[ test]
1016
1042
fn weak_self_cyclic ( ) {
1017
1043
struct Cycle {
1018
- x : Mutex < Option < Weak < Cycle > > >
1044
+ x : Mutex < Option < Weak < Cycle > > > ,
1019
1045
}
1020
1046
1021
1047
let a = Arc :: new ( Cycle { x : Mutex :: new ( None ) } ) ;
@@ -1095,7 +1121,9 @@ mod tests {
1095
1121
1096
1122
// Make sure deriving works with Arc<T>
1097
1123
#[ derive( Eq , Ord , PartialEq , PartialOrd , Clone , Debug , Default ) ]
1098
- struct Foo { inner : Arc < i32 > }
1124
+ struct Foo {
1125
+ inner : Arc < i32 > ,
1126
+ }
1099
1127
1100
1128
#[ test]
1101
1129
fn test_unsized ( ) {
@@ -1108,5 +1136,7 @@ mod tests {
1108
1136
}
1109
1137
1110
1138
impl < T : ?Sized > borrow:: Borrow < T > for Arc < T > {
1111
- fn borrow ( & self ) -> & T { & * * self }
1139
+ fn borrow ( & self ) -> & T {
1140
+ & * * self
1141
+ }
1112
1142
}
0 commit comments