@@ -77,12 +77,11 @@ use core::atomic;
77
77
use core:: atomic:: Ordering :: { Relaxed , Release , Acquire , SeqCst } ;
78
78
use core:: fmt;
79
79
use core:: cmp:: Ordering ;
80
- use core:: mem:: { min_align_of_val, size_of_val} ;
81
- use core:: intrinsics:: drop_in_place;
80
+ use core:: mem:: { min_align_of, size_of} ;
82
81
use core:: mem;
83
82
use core:: nonzero:: NonZero ;
84
- use core:: ops:: { Deref , CoerceUnsized } ;
85
- use core:: marker :: Unsize ;
83
+ use core:: ops:: Deref ;
84
+ use core:: ptr ;
86
85
use core:: hash:: { Hash , Hasher } ;
87
86
use heap:: deallocate;
88
87
@@ -119,16 +118,15 @@ use heap::deallocate;
119
118
/// ```
120
119
#[ unsafe_no_drop_flag]
121
120
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
122
- pub struct Arc < T : ? Sized > {
121
+ pub struct Arc < T > {
123
122
// FIXME #12808: strange name to try to avoid interfering with
124
123
// field accesses of the contained type via Deref
125
124
_ptr : NonZero < * mut ArcInner < T > > ,
126
125
}
127
126
128
- unsafe impl < T : ? Sized + Sync + Send > Send for Arc < T > { }
129
- unsafe impl < T : ? Sized + Sync + Send > Sync for Arc < T > { }
127
+ unsafe impl < T : Sync + Send > Send for Arc < T > { }
128
+ unsafe impl < T : Sync + Send > Sync for Arc < T > { }
130
129
131
- impl < T : ?Sized + Unsize < U > , U : ?Sized > CoerceUnsized < Arc < U > > for Arc < T > { }
132
130
133
131
/// A weak pointer to an `Arc`.
134
132
///
@@ -137,30 +135,30 @@ impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<Arc<U>> for Arc<T> {}
137
135
#[ unsafe_no_drop_flag]
138
136
#[ unstable( feature = "alloc" ,
139
137
reason = "Weak pointers may not belong in this module." ) ]
140
- pub struct Weak < T : ? Sized > {
138
+ pub struct Weak < T > {
141
139
// FIXME #12808: strange name to try to avoid interfering with
142
140
// field accesses of the contained type via Deref
143
141
_ptr : NonZero < * mut ArcInner < T > > ,
144
142
}
145
143
146
- unsafe impl < T : ? Sized + Sync + Send > Send for Weak < T > { }
147
- unsafe impl < T : ? Sized + Sync + Send > Sync for Weak < T > { }
144
+ unsafe impl < T : Sync + Send > Send for Weak < T > { }
145
+ unsafe impl < T : Sync + Send > Sync for Weak < T > { }
148
146
149
147
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
150
- impl < T : ? Sized + fmt:: Debug > fmt:: Debug for Weak < T > {
148
+ impl < T : fmt:: Debug > fmt:: Debug for Weak < T > {
151
149
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
152
150
write ! ( f, "(Weak)" )
153
151
}
154
152
}
155
153
156
- struct ArcInner < T : ? Sized > {
154
+ struct ArcInner < T > {
157
155
strong : atomic:: AtomicUsize ,
158
156
weak : atomic:: AtomicUsize ,
159
157
data : T ,
160
158
}
161
159
162
- unsafe impl < T : ? Sized + Sync + Send > Send for ArcInner < T > { }
163
- unsafe impl < T : ? Sized + Sync + Send > Sync for ArcInner < T > { }
160
+ unsafe impl < T : Sync + Send > Send for ArcInner < T > { }
161
+ unsafe impl < T : Sync + Send > Sync for ArcInner < T > { }
164
162
165
163
impl < T > Arc < T > {
166
164
/// Constructs a new `Arc<T>`.
@@ -184,9 +182,7 @@ impl<T> Arc<T> {
184
182
} ;
185
183
Arc { _ptr : unsafe { NonZero :: new ( mem:: transmute ( x) ) } }
186
184
}
187
- }
188
185
189
- impl < T : ?Sized > Arc < T > {
190
186
/// Downgrades the `Arc<T>` to a `Weak<T>` reference.
191
187
///
192
188
/// # Examples
@@ -208,7 +204,7 @@ impl<T: ?Sized> Arc<T> {
208
204
}
209
205
}
210
206
211
- impl < T : ? Sized > Arc < T > {
207
+ impl < T > Arc < T > {
212
208
#[ inline]
213
209
fn inner ( & self ) -> & ArcInner < T > {
214
210
// This unsafety is ok because while this arc is alive we're guaranteed
@@ -226,24 +222,24 @@ impl<T: ?Sized> Arc<T> {
226
222
227
223
// Destroy the data at this time, even though we may not free the box
228
224
// allocation itself (there may still be weak pointers lying around).
229
- drop_in_place ( & mut ( * ptr ) . data ) ;
225
+ drop ( ptr :: read ( & self . inner ( ) . data ) ) ;
230
226
231
227
if self . inner ( ) . weak . fetch_sub ( 1 , Release ) == 1 {
232
228
atomic:: fence ( Acquire ) ;
233
- deallocate ( ptr as * mut u8 , size_of_val ( & * ptr ) , min_align_of_val ( & * ptr ) )
229
+ deallocate ( ptr as * mut u8 , size_of :: < ArcInner < T > > ( ) , min_align_of :: < ArcInner < T > > ( ) )
234
230
}
235
231
}
236
232
}
237
233
238
234
/// Get the number of weak references to this value.
239
235
#[ inline]
240
236
#[ unstable( feature = "alloc" ) ]
241
- pub fn weak_count < T : ? Sized > ( this : & Arc < T > ) -> usize { this. inner ( ) . weak . load ( SeqCst ) - 1 }
237
+ pub fn weak_count < T > ( this : & Arc < T > ) -> usize { this. inner ( ) . weak . load ( SeqCst ) - 1 }
242
238
243
239
/// Get the number of strong references to this value.
244
240
#[ inline]
245
241
#[ unstable( feature = "alloc" ) ]
246
- pub fn strong_count < T : ? Sized > ( this : & Arc < T > ) -> usize { this. inner ( ) . strong . load ( SeqCst ) }
242
+ pub fn strong_count < T > ( this : & Arc < T > ) -> usize { this. inner ( ) . strong . load ( SeqCst ) }
247
243
248
244
249
245
/// Returns a mutable reference to the contained value if the `Arc<T>` is unique.
@@ -268,7 +264,7 @@ pub fn strong_count<T: ?Sized>(this: &Arc<T>) -> usize { this.inner().strong.loa
268
264
/// ```
269
265
#[ inline]
270
266
#[ unstable( feature = "alloc" ) ]
271
- pub fn get_mut < T : ? Sized > ( this : & mut Arc < T > ) -> Option < & mut T > {
267
+ pub fn get_mut < T > ( this : & mut Arc < T > ) -> Option < & mut T > {
272
268
if strong_count ( this) == 1 && weak_count ( this) == 0 {
273
269
// This unsafety is ok because we're guaranteed that the pointer
274
270
// returned is the *only* pointer that will ever be returned to T. Our
@@ -283,7 +279,7 @@ pub fn get_mut<T: ?Sized>(this: &mut Arc<T>) -> Option<&mut T> {
283
279
}
284
280
285
281
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
286
- impl < T : ? Sized > Clone for Arc < T > {
282
+ impl < T > Clone for Arc < T > {
287
283
/// Makes a clone of the `Arc<T>`.
288
284
///
289
285
/// This increases the strong reference count.
@@ -317,7 +313,7 @@ impl<T: ?Sized> Clone for Arc<T> {
317
313
}
318
314
319
315
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
320
- impl < T : ? Sized > Deref for Arc < T > {
316
+ impl < T > Deref for Arc < T > {
321
317
type Target = T ;
322
318
323
319
#[ inline]
@@ -360,7 +356,7 @@ impl<T: Clone> Arc<T> {
360
356
}
361
357
362
358
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
363
- impl < T : ? Sized > Drop for Arc < T > {
359
+ impl < T > Drop for Arc < T > {
364
360
/// Drops the `Arc<T>`.
365
361
///
366
362
/// This will decrement the strong reference count. If the strong reference
@@ -394,7 +390,7 @@ impl<T: ?Sized> Drop for Arc<T> {
394
390
// it's run more than once)
395
391
let ptr = * self . _ptr ;
396
392
// if ptr.is_null() { return }
397
- if ptr as usize == 0 || ptr as usize == mem:: POST_DROP_USIZE { return }
393
+ if ptr. is_null ( ) || ptr as usize == mem:: POST_DROP_USIZE { return }
398
394
399
395
// Because `fetch_sub` is already atomic, we do not need to synchronize
400
396
// with other threads unless we are going to delete the object. This
@@ -428,7 +424,7 @@ impl<T: ?Sized> Drop for Arc<T> {
428
424
429
425
#[ unstable( feature = "alloc" ,
430
426
reason = "Weak pointers may not belong in this module." ) ]
431
- impl < T : ? Sized > Weak < T > {
427
+ impl < T > Weak < T > {
432
428
/// Upgrades a weak reference to a strong reference.
433
429
///
434
430
/// Upgrades the `Weak<T>` reference to an `Arc<T>`, if possible.
@@ -469,7 +465,7 @@ impl<T: ?Sized> Weak<T> {
469
465
470
466
#[ unstable( feature = "alloc" ,
471
467
reason = "Weak pointers may not belong in this module." ) ]
472
- impl < T : ? Sized > Clone for Weak < T > {
468
+ impl < T > Clone for Weak < T > {
473
469
/// Makes a clone of the `Weak<T>`.
474
470
///
475
471
/// This increases the weak reference count.
@@ -493,7 +489,7 @@ impl<T: ?Sized> Clone for Weak<T> {
493
489
}
494
490
495
491
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
496
- impl < T : ? Sized > Drop for Weak < T > {
492
+ impl < T > Drop for Weak < T > {
497
493
/// Drops the `Weak<T>`.
498
494
///
499
495
/// This will decrement the weak reference count.
@@ -524,22 +520,21 @@ impl<T: ?Sized> Drop for Weak<T> {
524
520
let ptr = * self . _ptr ;
525
521
526
522
// see comments above for why this check is here
527
- if ptr as usize == 0 || ptr as usize == mem:: POST_DROP_USIZE { return }
523
+ if ptr. is_null ( ) || ptr as usize == mem:: POST_DROP_USIZE { return }
528
524
529
525
// If we find out that we were the last weak pointer, then its time to
530
526
// deallocate the data entirely. See the discussion in Arc::drop() about
531
527
// the memory orderings
532
528
if self . inner ( ) . weak . fetch_sub ( 1 , Release ) == 1 {
533
529
atomic:: fence ( Acquire ) ;
534
- unsafe { deallocate ( ptr as * mut u8 ,
535
- size_of_val ( & * ptr) ,
536
- min_align_of_val ( & * ptr) ) }
530
+ unsafe { deallocate ( ptr as * mut u8 , size_of :: < ArcInner < T > > ( ) ,
531
+ min_align_of :: < ArcInner < T > > ( ) ) }
537
532
}
538
533
}
539
534
}
540
535
541
536
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
542
- impl < T : ? Sized + PartialEq > PartialEq for Arc < T > {
537
+ impl < T : PartialEq > PartialEq for Arc < T > {
543
538
/// Equality for two `Arc<T>`s.
544
539
///
545
540
/// Two `Arc<T>`s are equal if their inner value are equal.
@@ -571,7 +566,7 @@ impl<T: ?Sized + PartialEq> PartialEq for Arc<T> {
571
566
fn ne ( & self , other : & Arc < T > ) -> bool { * ( * self ) != * ( * other) }
572
567
}
573
568
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
574
- impl < T : ? Sized + PartialOrd > PartialOrd for Arc < T > {
569
+ impl < T : PartialOrd > PartialOrd for Arc < T > {
575
570
/// Partial comparison for two `Arc<T>`s.
576
571
///
577
572
/// The two are compared by calling `partial_cmp()` on their inner values.
@@ -650,21 +645,21 @@ impl<T: ?Sized + PartialOrd> PartialOrd for Arc<T> {
650
645
fn ge ( & self , other : & Arc < T > ) -> bool { * ( * self ) >= * ( * other) }
651
646
}
652
647
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
653
- impl < T : ? Sized + Ord > Ord for Arc < T > {
648
+ impl < T : Ord > Ord for Arc < T > {
654
649
fn cmp ( & self , other : & Arc < T > ) -> Ordering { ( * * self ) . cmp ( & * * other) }
655
650
}
656
651
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
657
- impl < T : ? Sized + Eq > Eq for Arc < T > { }
652
+ impl < T : Eq > Eq for Arc < T > { }
658
653
659
654
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
660
- impl < T : ? Sized + fmt:: Display > fmt:: Display for Arc < T > {
655
+ impl < T : fmt:: Display > fmt:: Display for Arc < T > {
661
656
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
662
657
fmt:: Display :: fmt ( & * * self , f)
663
658
}
664
659
}
665
660
666
661
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
667
- impl < T : ? Sized + fmt:: Debug > fmt:: Debug for Arc < T > {
662
+ impl < T : fmt:: Debug > fmt:: Debug for Arc < T > {
668
663
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
669
664
fmt:: Debug :: fmt ( & * * self , f)
670
665
}
@@ -684,7 +679,7 @@ impl<T: Default> Default for Arc<T> {
684
679
}
685
680
686
681
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
687
- impl < T : ? Sized + Hash > Hash for Arc < T > {
682
+ impl < T : Hash > Hash for Arc < T > {
688
683
fn hash < H : Hasher > ( & self , state : & mut H ) {
689
684
( * * self ) . hash ( state)
690
685
}
@@ -911,13 +906,4 @@ mod tests {
911
906
// Make sure deriving works with Arc<T>
912
907
#[ derive( Eq , Ord , PartialEq , PartialOrd , Clone , Debug , Default ) ]
913
908
struct Foo { inner : Arc < i32 > }
914
-
915
- #[ test]
916
- fn test_unsized ( ) {
917
- let x: Arc < [ i32 ] > = Arc :: new ( [ 1 , 2 , 3 ] ) ;
918
- assert_eq ! ( format!( "{:?}" , x) , "[1, 2, 3]" ) ;
919
- let y = x. clone ( ) . downgrade ( ) ;
920
- drop ( x) ;
921
- assert ! ( y. upgrade( ) . is_none( ) ) ;
922
- }
923
909
}
0 commit comments