File tree Expand file tree Collapse file tree 2 files changed +12
-3
lines changed Expand file tree Collapse file tree 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 {
522522/// Useful for building abstractions like `Vec<T>` or `Box<T>`, which
523523/// internally use raw pointers to manage the memory that they own.
524524#[ 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 ) ;
526526
527527/// `Unique` pointers are `Send` if `T` is `Send` because the data they
528528/// reference is unaliased. Note that this aliasing invariant is
529529/// unenforced by the type system; the abstraction using the
530530/// `Unique` must enforce it.
531531#[ 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 > { }
533533
534534/// `Unique` pointers are `Sync` if `T` is `Sync` because the data they
535535/// reference is unaliased. Note that this aliasing invariant is
536536/// unenforced by the type system; the abstraction using the
537537/// `Unique` must enforce it.
538538#[ 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 > { }
540540
541541impl < T > Unique < T > {
542542 /// Returns a null Unique.
Original file line number Diff line number Diff line change @@ -167,3 +167,12 @@ fn test_set_memory() {
167167 unsafe { set_memory ( ptr, 5u8 , xs. len ( ) ) ; }
168168 assert ! ( xs == [ 5u8 ; 20 ] ) ;
169169}
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