1 The type you are trying to impl `CoerceUnsized` for is not a struct.
2 `CoerceUnsized` can only be implemented for a struct. Unsized types are
3 already able to be coerced without an implementation of `CoerceUnsized`
4 whereas a struct containing an unsized type needs to know the unsized type
5 field it's containing is able to be coerced. An [unsized type][1]
6 is any type that the compiler doesn't know the length or alignment of at
7 compile time. Any struct containing an unsized type is also unsized.
9 [1]: https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait
11 Example of erroneous code:
14 #![feature(coerce_unsized)]
15 use std::ops::CoerceUnsized;
17 struct Foo<T: ?Sized> {
21 // error: The type `U` is not a struct
22 impl<T, U> CoerceUnsized<U> for Foo<T> {}
25 The `CoerceUnsized` trait takes a struct type. Make sure the type you are
26 providing to `CoerceUnsized` is a struct with only the last field containing an
32 #![feature(coerce_unsized)]
33 use std::ops::CoerceUnsized;
39 // The `Foo<U>` is a struct so `CoerceUnsized` can be implemented
40 impl<T, U> CoerceUnsized<Foo<U>> for Foo<T> where T: CoerceUnsized<U> {}
43 Note that in Rust, structs can only contain an unsized type if the field
44 containing the unsized type is the last and only unsized type field in the