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.
8
-
9
- [ 1 ] : https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait
1
+ ` CoerceUnsized ` was implemented on something that isn't a struct.
10
2
11
- Example of erroneous code:
3
+ Erroneous code example :
12
4
13
5
``` compile_fail,E0376
14
6
#![feature(coerce_unsized)]
@@ -22,6 +14,15 @@ struct Foo<T: ?Sized> {
22
14
impl<T, U> CoerceUnsized<U> for Foo<T> {}
23
15
```
24
16
17
+ ` CoerceUnsized ` can only be implemented for a struct. Unsized types are
18
+ already able to be coerced without an implementation of ` CoerceUnsized `
19
+ whereas a struct containing an unsized type needs to know the unsized type
20
+ field it's containing is able to be coerced. An [ unsized type] [ 1 ]
21
+ is any type that the compiler doesn't know the length or alignment of at
22
+ compile time. Any struct containing an unsized type is also unsized.
23
+
24
+ [ 1 ] : https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait
25
+
25
26
The ` CoerceUnsized ` trait takes a struct type. Make sure the type you are
26
27
providing to ` CoerceUnsized ` is a struct with only the last field containing an
27
28
unsized type.
0 commit comments