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