File tree 2 files changed +12
-3
lines changed
2 files changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -522,21 +522,21 @@ impl<T> PartialOrd for *mut T {
522
522
/// Useful for building abstractions like `Vec<T>` or `Box<T>`, which
523
523
/// internally use raw pointers to manage the memory that they own.
524
524
#[ unstable( feature = "core" , reason = "recently added to this module" ) ]
525
- pub struct Unique < T > ( pub * mut T ) ;
525
+ pub struct Unique < T : ? Sized > ( pub * mut T ) ;
526
526
527
527
/// `Unique` pointers are `Send` if `T` is `Send` because the data they
528
528
/// reference is unaliased. Note that this aliasing invariant is
529
529
/// unenforced by the type system; the abstraction using the
530
530
/// `Unique` must enforce it.
531
531
#[ unstable( feature = "core" , reason = "recently added to this module" ) ]
532
- unsafe impl < T : Send > Send for Unique < T > { }
532
+ unsafe impl < T : Send + ? Sized > Send for Unique < T > { }
533
533
534
534
/// `Unique` pointers are `Sync` if `T` is `Sync` because the data they
535
535
/// reference is unaliased. Note that this aliasing invariant is
536
536
/// unenforced by the type system; the abstraction using the
537
537
/// `Unique` must enforce it.
538
538
#[ unstable( feature = "core" , reason = "recently added to this module" ) ]
539
- unsafe impl < T : Sync > Sync for Unique < T > { }
539
+ unsafe impl < T : Sync + ? Sized > Sync for Unique < T > { }
540
540
541
541
impl < T > Unique < T > {
542
542
/// Returns a null Unique.
Original file line number Diff line number Diff line change @@ -167,3 +167,12 @@ fn test_set_memory() {
167
167
unsafe { set_memory ( ptr, 5u8 , xs. len ( ) ) ; }
168
168
assert ! ( xs == [ 5u8 ; 20 ] ) ;
169
169
}
170
+
171
+ #[ test]
172
+ fn test_unsized_unique ( ) {
173
+ let xs: & mut [ _ ] = & mut [ 1 , 2 , 3 ] ;
174
+ let ptr = Unique ( xs as * mut [ _ ] ) ;
175
+ let ys = unsafe { & mut * ptr. 0 } ;
176
+ let zs: & mut [ _ ] = & mut [ 1 , 2 , 3 ] ;
177
+ assert ! ( ys == zs) ;
178
+ }
You can’t perform that action at this time.
0 commit comments