@@ -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
@@ -303,7 +307,9 @@ impl<T: ?Sized> Arc<T> {
303
307
304
308
if self . inner ( ) . weak . fetch_sub ( 1 , Release ) == 1 {
305
309
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) )
307
313
}
308
314
}
309
315
}
@@ -348,7 +354,9 @@ impl<T: ?Sized> Clone for Arc<T> {
348
354
// We abort because such a program is incredibly degenerate, and we
349
355
// don't care to support it.
350
356
if old_size > MAX_REFCOUNT {
351
- unsafe { abort ( ) ; }
357
+ unsafe {
358
+ abort ( ) ;
359
+ }
352
360
}
353
361
354
362
Arc { _ptr : self . _ptr }
@@ -556,7 +564,9 @@ impl<T: ?Sized> Drop for Arc<T> {
556
564
// Because `fetch_sub` is already atomic, we do not need to synchronize
557
565
// with other threads unless we are going to delete the object. This
558
566
// 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
+ }
560
570
561
571
// This fence is needed to prevent reordering of use of the data and
562
572
// deletion of the data. Because it is marked `Release`, the decreasing
@@ -578,7 +588,7 @@ impl<T: ?Sized> Drop for Arc<T> {
578
588
atomic:: fence ( Acquire ) ;
579
589
580
590
unsafe {
581
- self . drop_slow ( )
591
+ self . drop_slow ( ) ;
582
592
}
583
593
}
584
594
}
@@ -613,11 +623,15 @@ impl<T: ?Sized> Weak<T> {
613
623
// "stale" read of 0 is fine), and any other value is
614
624
// confirmed via the CAS below.
615
625
let n = inner. strong . load ( Relaxed ) ;
616
- if n == 0 { return None }
626
+ if n == 0 {
627
+ return None
628
+ }
617
629
618
630
// Relaxed is valid for the same reason it is on Arc's Clone impl
619
631
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
+ }
621
635
}
622
636
}
623
637
@@ -653,7 +667,9 @@ impl<T: ?Sized> Clone for Weak<T> {
653
667
654
668
// See comments in Arc::clone() for why we do this (for mem::forget).
655
669
if old_size > MAX_REFCOUNT {
656
- unsafe { abort ( ) ; }
670
+ unsafe {
671
+ abort ( ) ;
672
+ }
657
673
}
658
674
659
675
return Weak { _ptr : self . _ptr }
@@ -705,9 +721,11 @@ impl<T: ?Sized> Drop for Weak<T> {
705
721
// ref, which can only happen after the lock is released.
706
722
if self . inner ( ) . weak . fetch_sub ( 1 , Release ) == 1 {
707
723
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
+ }
711
729
}
712
730
}
713
731
}
@@ -727,7 +745,9 @@ impl<T: ?Sized + PartialEq> PartialEq for Arc<T> {
727
745
///
728
746
/// five == Arc::new(5);
729
747
/// ```
730
- fn eq ( & self , other : & Arc < T > ) -> bool { * ( * self ) == * ( * other) }
748
+ fn eq ( & self , other : & Arc < T > ) -> bool {
749
+ * ( * self ) == * ( * other)
750
+ }
731
751
732
752
/// Inequality for two `Arc<T>`s.
733
753
///
@@ -742,7 +762,9 @@ impl<T: ?Sized + PartialEq> PartialEq for Arc<T> {
742
762
///
743
763
/// five != Arc::new(5);
744
764
/// ```
745
- fn ne ( & self , other : & Arc < T > ) -> bool { * ( * self ) != * ( * other) }
765
+ fn ne ( & self , other : & Arc < T > ) -> bool {
766
+ * ( * self ) != * ( * other)
767
+ }
746
768
}
747
769
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
748
770
impl < T : ?Sized + PartialOrd > PartialOrd for Arc < T > {
@@ -776,7 +798,9 @@ impl<T: ?Sized + PartialOrd> PartialOrd for Arc<T> {
776
798
///
777
799
/// five < Arc::new(5);
778
800
/// ```
779
- fn lt ( & self , other : & Arc < T > ) -> bool { * ( * self ) < * ( * other) }
801
+ fn lt ( & self , other : & Arc < T > ) -> bool {
802
+ * ( * self ) < * ( * other)
803
+ }
780
804
781
805
/// 'Less-than or equal to' comparison for two `Arc<T>`s.
782
806
///
@@ -791,7 +815,9 @@ impl<T: ?Sized + PartialOrd> PartialOrd for Arc<T> {
791
815
///
792
816
/// five <= Arc::new(5);
793
817
/// ```
794
- fn le ( & self , other : & Arc < T > ) -> bool { * ( * self ) <= * ( * other) }
818
+ fn le ( & self , other : & Arc < T > ) -> bool {
819
+ * ( * self ) <= * ( * other)
820
+ }
795
821
796
822
/// Greater-than comparison for two `Arc<T>`s.
797
823
///
@@ -806,7 +832,9 @@ impl<T: ?Sized + PartialOrd> PartialOrd for Arc<T> {
806
832
///
807
833
/// five > Arc::new(5);
808
834
/// ```
809
- fn gt ( & self , other : & Arc < T > ) -> bool { * ( * self ) > * ( * other) }
835
+ fn gt ( & self , other : & Arc < T > ) -> bool {
836
+ * ( * self ) > * ( * other)
837
+ }
810
838
811
839
/// 'Greater-than or equal to' comparison for two `Arc<T>`s.
812
840
///
@@ -821,11 +849,15 @@ impl<T: ?Sized + PartialOrd> PartialOrd for Arc<T> {
821
849
///
822
850
/// five >= Arc::new(5);
823
851
/// ```
824
- fn ge ( & self , other : & Arc < T > ) -> bool { * ( * self ) >= * ( * other) }
852
+ fn ge ( & self , other : & Arc < T > ) -> bool {
853
+ * ( * self ) >= * ( * other)
854
+ }
825
855
}
826
856
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
827
857
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
+ }
829
861
}
830
862
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
831
863
impl < T : ?Sized + Eq > Eq for Arc < T > { }
@@ -854,7 +886,9 @@ impl<T> fmt::Pointer for Arc<T> {
854
886
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
855
887
impl < T : Default > Default for Arc < T > {
856
888
#[ 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
+ }
858
892
}
859
893
860
894
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
@@ -1015,7 +1049,7 @@ mod tests {
1015
1049
#[ test]
1016
1050
fn weak_self_cyclic ( ) {
1017
1051
struct Cycle {
1018
- x : Mutex < Option < Weak < Cycle > > >
1052
+ x : Mutex < Option < Weak < Cycle > > > ,
1019
1053
}
1020
1054
1021
1055
let a = Arc :: new ( Cycle { x : Mutex :: new ( None ) } ) ;
@@ -1095,7 +1129,9 @@ mod tests {
1095
1129
1096
1130
// Make sure deriving works with Arc<T>
1097
1131
#[ derive( Eq , Ord , PartialEq , PartialOrd , Clone , Debug , Default ) ]
1098
- struct Foo { inner : Arc < i32 > }
1132
+ struct Foo {
1133
+ inner : Arc < i32 > ,
1134
+ }
1099
1135
1100
1136
#[ test]
1101
1137
fn test_unsized ( ) {
@@ -1108,5 +1144,7 @@ mod tests {
1108
1144
}
1109
1145
1110
1146
impl < T : ?Sized > borrow:: Borrow < T > for Arc < T > {
1111
- fn borrow ( & self ) -> & T { & * * self }
1147
+ fn borrow ( & self ) -> & T {
1148
+ & * * self
1149
+ }
1112
1150
}
0 commit comments