@@ -155,6 +155,7 @@ mod index;
155
155
mod place;
156
156
mod range;
157
157
mod try;
158
+ mod unsize;
158
159
159
160
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
160
161
pub use self :: arith:: { Add , Sub , Mul , Div , Rem , Neg } ;
@@ -190,7 +191,8 @@ pub use self::try::Try;
190
191
#[ unstable( feature = "placement_new_protocol" , issue = "27779" ) ]
191
192
pub use self :: place:: { Place , Placer , InPlace , Boxed , BoxPlace } ;
192
193
193
- use marker:: Unsize ;
194
+ #[ unstable( feature = "coerce_unsized" , issue = "27732" ) ]
195
+ pub use self :: unsize:: CoerceUnsized ;
194
196
195
197
/// The `Drop` trait is used to run some code when a value goes out of scope.
196
198
/// This is sometimes called a 'destructor'.
@@ -281,71 +283,3 @@ pub trait Drop {
281
283
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
282
284
fn drop ( & mut self ) ;
283
285
}
284
-
285
- /// Trait that indicates that this is a pointer or a wrapper for one,
286
- /// where unsizing can be performed on the pointee.
287
- ///
288
- /// See the [DST coercion RfC][dst-coerce] and [the nomicon entry on coercion][nomicon-coerce]
289
- /// for more details.
290
- ///
291
- /// For builtin pointer types, pointers to `T` will coerce to pointers to `U` if `T: Unsize<U>`
292
- /// by converting from a thin pointer to a fat pointer.
293
- ///
294
- /// For custom types, the coercion here works by coercing `Foo<T>` to `Foo<U>`
295
- /// provided an impl of `CoerceUnsized<Foo<U>> for Foo<T>` exists.
296
- /// Such an impl can only be written if `Foo<T>` has only a single non-phantomdata
297
- /// field involving `T`. If the type of that field is `Bar<T>`, an implementation
298
- /// of `CoerceUnsized<Bar<U>> for Bar<T>` must exist. The coercion will work by
299
- /// by coercing the `Bar<T>` field into `Bar<U>` and filling in the rest of the fields
300
- /// from `Foo<T>` to create a `Foo<U>`. This will effectively drill down to a pointer
301
- /// field and coerce that.
302
- ///
303
- /// Generally, for smart pointers you will implement
304
- /// `CoerceUnsized<Ptr<U>> for Ptr<T> where T: Unsize<U>, U: ?Sized`, with an
305
- /// optional `?Sized` bound on `T` itself. For wrapper types that directly embed `T`
306
- /// like `Cell<T>` and `RefCell<T>`, you
307
- /// can directly implement `CoerceUnsized<Wrap<U>> for Wrap<T> where T: CoerceUnsized<U>`.
308
- /// This will let coercions of types like `Cell<Box<T>>` work.
309
- ///
310
- /// [`Unsize`][unsize] is used to mark types which can be coerced to DSTs if behind
311
- /// pointers. It is implemented automatically by the compiler.
312
- ///
313
- /// [dst-coerce]: https://github.com/rust-lang/rfcs/blob/master/text/0982-dst-coercion.md
314
- /// [unsize]: ../marker/trait.Unsize.html
315
- /// [nomicon-coerce]: ../../nomicon/coercions.html
316
- #[ unstable( feature = "coerce_unsized" , issue = "27732" ) ]
317
- #[ lang="coerce_unsized" ]
318
- pub trait CoerceUnsized < T > {
319
- // Empty.
320
- }
321
-
322
- // &mut T -> &mut U
323
- #[ unstable( feature = "coerce_unsized" , issue = "27732" ) ]
324
- impl < ' a , T : ?Sized +Unsize < U > , U : ?Sized > CoerceUnsized < & ' a mut U > for & ' a mut T { }
325
- // &mut T -> &U
326
- #[ unstable( feature = "coerce_unsized" , issue = "27732" ) ]
327
- impl < ' a , ' b : ' a , T : ?Sized +Unsize < U > , U : ?Sized > CoerceUnsized < & ' a U > for & ' b mut T { }
328
- // &mut T -> *mut U
329
- #[ unstable( feature = "coerce_unsized" , issue = "27732" ) ]
330
- impl < ' a , T : ?Sized +Unsize < U > , U : ?Sized > CoerceUnsized < * mut U > for & ' a mut T { }
331
- // &mut T -> *const U
332
- #[ unstable( feature = "coerce_unsized" , issue = "27732" ) ]
333
- impl < ' a , T : ?Sized +Unsize < U > , U : ?Sized > CoerceUnsized < * const U > for & ' a mut T { }
334
-
335
- // &T -> &U
336
- #[ unstable( feature = "coerce_unsized" , issue = "27732" ) ]
337
- impl < ' a , ' b : ' a , T : ?Sized +Unsize < U > , U : ?Sized > CoerceUnsized < & ' a U > for & ' b T { }
338
- // &T -> *const U
339
- #[ unstable( feature = "coerce_unsized" , issue = "27732" ) ]
340
- impl < ' a , T : ?Sized +Unsize < U > , U : ?Sized > CoerceUnsized < * const U > for & ' a T { }
341
-
342
- // *mut T -> *mut U
343
- #[ unstable( feature = "coerce_unsized" , issue = "27732" ) ]
344
- impl < T : ?Sized +Unsize < U > , U : ?Sized > CoerceUnsized < * mut U > for * mut T { }
345
- // *mut T -> *const U
346
- #[ unstable( feature = "coerce_unsized" , issue = "27732" ) ]
347
- impl < T : ?Sized +Unsize < U > , U : ?Sized > CoerceUnsized < * const U > for * mut T { }
348
-
349
- // *const T -> *const U
350
- #[ unstable( feature = "coerce_unsized" , issue = "27732" ) ]
351
- impl < T : ?Sized +Unsize < U > , U : ?Sized > CoerceUnsized < * const U > for * const T { }
0 commit comments