]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_error_codes/src/error_codes/E0328.md
Rollup merge of #92310 - ehuss:rustdoc-ice, r=estebank
[rust.git] / compiler / rustc_error_codes / src / error_codes / E0328.md
1 The Unsize trait should not be implemented directly. All implementations of
2 Unsize are provided automatically by the compiler.
3
4 Erroneous code example:
5
6 ```compile_fail,E0328
7 #![feature(unsize)]
8
9 use std::marker::Unsize;
10
11 pub struct MyType;
12
13 impl<T> Unsize<T> for MyType {}
14 ```
15
16 If you are defining your own smart pointer type and would like to enable
17 conversion from a sized to an unsized type with the
18 [DST coercion system][RFC 982], use [`CoerceUnsized`] instead.
19
20 ```
21 #![feature(coerce_unsized)]
22
23 use std::ops::CoerceUnsized;
24
25 pub struct MyType<T: ?Sized> {
26     field_with_unsized_type: T,
27 }
28
29 impl<T, U> CoerceUnsized<MyType<U>> for MyType<T>
30     where T: CoerceUnsized<U> {}
31 ```
32
33 [RFC 982]: https://github.com/rust-lang/rfcs/blob/master/text/0982-dst-coercion.md
34 [`CoerceUnsized`]: https://doc.rust-lang.org/std/ops/trait.CoerceUnsized.html