@@ -2450,16 +2450,11 @@ impl<'a, T: ?Sized> From<&'a T> for Unique<T> {
24502450 }
24512451}
24522452
2453- /// A wrapper around a raw `*mut T` that indicates that the possessor
2454- /// of this wrapper has shared ownership of the referent. Useful for
2455- /// building abstractions like `Rc<T>`, `Arc<T>`, or doubly-linked lists, which
2456- /// internally use aliased raw pointers to manage the memory that they own.
2453+ /// `*mut T` but non-zero and covariant.
24572454///
2458- /// This is similar to `Unique`, except that it doesn't make any aliasing
2459- /// guarantees, and doesn't derive Send and Sync. Note that unlike `&T`,
2460- /// Shared has no special mutability requirements. Shared may mutate data
2461- /// aliased by other Shared pointers. More precise rules require Rust to
2462- /// develop an actual aliasing model.
2455+ /// This is often the correct thing to use when building data structures using
2456+ /// raw pointers, but is ultimately more dangerous to use because of its additional
2457+ /// properties. If you're not sure if you should use `Shared<T>`, just use `*mut T`!
24632458///
24642459/// Unlike `*mut T`, the pointer must always be non-null, even if the pointer
24652460/// is never dereferenced. This is so that enums may use this forbidden value
@@ -2469,20 +2464,14 @@ impl<'a, T: ?Sized> From<&'a T> for Unique<T> {
24692464/// Unlike `*mut T`, `Shared<T>` is covariant over `T`. If this is incorrect
24702465/// for your use case, you should include some PhantomData in your type to
24712466/// provide invariance, such as `PhantomData<Cell<T>>` or `PhantomData<&'a mut T>`.
2472- /// Usually this won't be necessary; covariance is correct for Rc, Arc, and LinkedList
2473- /// because they provide a public API that follows the normal shared XOR mutable
2474- /// rules of Rust.
2467+ /// Usually this won't be necessary; covariance is correct for most safe abstractions,
2468+ /// such as Box, Rc, Arc, Vec, and LinkedList. This is the case because they
2469+ /// provide a public API that follows the normal shared XOR mutable rules of Rust.
24752470#[ allow( missing_debug_implementations) ]
24762471#[ unstable( feature = "shared" , reason = "needs an RFC to flesh out design" ,
24772472 issue = "27730" ) ]
24782473pub struct Shared < T : ?Sized > {
24792474 pointer : NonZero < * const T > ,
2480- // NOTE: this marker has no consequences for variance, but is necessary
2481- // for dropck to understand that we logically own a `T`.
2482- //
2483- // For details, see:
2484- // https://github.com/rust-lang/rfcs/blob/master/text/0769-sound-generic-drop.md#phantom-data
2485- _marker : PhantomData < T > ,
24862475}
24872476
24882477/// `Shared` pointers are not `Send` because the data they reference may be aliased.
@@ -2518,12 +2507,12 @@ impl<T: ?Sized> Shared<T> {
25182507 /// `ptr` must be non-null.
25192508 #[ unstable( feature = "shared" , issue = "27730" ) ]
25202509 pub const unsafe fn new_unchecked ( ptr : * mut T ) -> Self {
2521- Shared { pointer : NonZero :: new_unchecked ( ptr) , _marker : PhantomData }
2510+ Shared { pointer : NonZero :: new_unchecked ( ptr) }
25222511 }
25232512
25242513 /// Creates a new `Shared` if `ptr` is non-null.
25252514 pub fn new ( ptr : * mut T ) -> Option < Self > {
2526- NonZero :: new ( ptr as * const T ) . map ( |nz| Shared { pointer : nz, _marker : PhantomData } )
2515+ NonZero :: new ( ptr as * const T ) . map ( |nz| Shared { pointer : nz } )
25272516 }
25282517
25292518 /// Acquires the underlying `*mut` pointer.
@@ -2580,20 +2569,20 @@ impl<T: ?Sized> fmt::Pointer for Shared<T> {
25802569#[ unstable( feature = "shared" , issue = "27730" ) ]
25812570impl < T : ?Sized > From < Unique < T > > for Shared < T > {
25822571 fn from ( unique : Unique < T > ) -> Self {
2583- Shared { pointer : unique. pointer , _marker : PhantomData }
2572+ Shared { pointer : unique. pointer }
25842573 }
25852574}
25862575
25872576#[ unstable( feature = "shared" , issue = "27730" ) ]
25882577impl < ' a , T : ?Sized > From < & ' a mut T > for Shared < T > {
25892578 fn from ( reference : & ' a mut T ) -> Self {
2590- Shared { pointer : NonZero :: from ( reference) , _marker : PhantomData }
2579+ Shared { pointer : NonZero :: from ( reference) }
25912580 }
25922581}
25932582
25942583#[ unstable( feature = "shared" , issue = "27730" ) ]
25952584impl < ' a , T : ?Sized > From < & ' a T > for Shared < T > {
25962585 fn from ( reference : & ' a T ) -> Self {
2597- Shared { pointer : NonZero :: from ( reference) , _marker : PhantomData }
2586+ Shared { pointer : NonZero :: from ( reference) }
25982587 }
25992588}
0 commit comments