@@ -2710,6 +2710,35 @@ mod impls {
27102710
27112711/// Trait that indicates that this is a pointer or a wrapper for one, 
27122712/// where unsizing can be performed on the pointee. 
2713+ /// 
2714+ /// See the [DST coercion RfC][dst-coerce] and [the nomicon entry on coercion][nomicon-coerce] 
2715+ /// for more details. 
2716+ /// 
2717+ /// For builtin pointer types, pointers to `T` will coerce to pointers to `U` if `T: Unsize<U>` 
2718+ /// by converting from a thin pointer to a fat pointer. 
2719+ /// 
2720+ /// For custom types, the coercion here works by coercing `Foo<T>` to `Foo<U>` 
2721+ /// provided an impl of `CoerceUnsized<Foo<U>> for Foo<T>` exists. 
2722+ /// Such an impl can only be written if `Foo<T>` has only a single non-phantomdata 
2723+ /// field involving `T`. If the type of that field is `Bar<T>`, an implementation 
2724+ /// of `CoerceUnsized<Bar<U>> for Bar<T>` must exist. The coercion will work by 
2725+ /// by coercing the `Bar<T>` field into `Bar<U>` and filling in the rest of the fields 
2726+ /// from `Foo<T>` to create a `Foo<U>`. This will effectively drill down to a pointer 
2727+ /// field and coerce that. 
2728+ /// 
2729+ /// Generally, for smart pointers you will implement 
2730+ /// `CoerceUnsized<Ptr<U>> for Ptr<T> where T: Unsize<U>, U: ?Sized`, with an 
2731+ /// optional `?Sized` bound on `T` itself. For wrapper types that directly embed `T` 
2732+ /// like `Cell<T>` and `RefCell<T>`, you 
2733+ /// can directly implement `CoerceUnsized<Wrap<U>> for Wrap<T> where T: CoerceUnsized<U>`. 
2734+ /// This will let coercions of types like `Cell<Box<T>>` work. 
2735+ /// 
2736+ /// [`Unsize`][unsize] is used to mark types which can be coerced to DSTs if behind 
2737+ /// pointers. It is implemented automatically by the compiler. 
2738+ /// 
2739+ /// [dst-coerce]: https://github.com/rust-lang/rfcs/blob/master/text/0982-dst-coercion.md 
2740+ /// [unsize]: ../marker/trait.Unsize.html 
2741+ /// [nomicon-coerce]: ../../nomicon/coercions.html 
27132742#[ unstable( feature = "coerce_unsized" ,  issue = "27732" ) ]  
27142743#[ lang="coerce_unsized" ]  
27152744pub  trait  CoerceUnsized < T >  { 
0 commit comments