Clean up E0376 explanation
This commit is contained in:
parent
abc3073c92
commit
dd142b1dc4
@ -1,14 +1,6 @@
|
||||
The type you are trying to impl `CoerceUnsized` for is not a struct.
|
||||
`CoerceUnsized` can only be implemented for a struct. Unsized types are
|
||||
already able to be coerced without an implementation of `CoerceUnsized`
|
||||
whereas a struct containing an unsized type needs to know the unsized type
|
||||
field it's containing is able to be coerced. An [unsized type][1]
|
||||
is any type that the compiler doesn't know the length or alignment of at
|
||||
compile time. Any struct containing an unsized type is also unsized.
|
||||
`CoerceUnsized` was implemented on something that isn't a struct.
|
||||
|
||||
[1]: https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait
|
||||
|
||||
Example of erroneous code:
|
||||
Erroneous code example:
|
||||
|
||||
```compile_fail,E0376
|
||||
#![feature(coerce_unsized)]
|
||||
@ -22,6 +14,15 @@ struct Foo<T: ?Sized> {
|
||||
impl<T, U> CoerceUnsized<U> for Foo<T> {}
|
||||
```
|
||||
|
||||
`CoerceUnsized` can only be implemented for a struct. Unsized types are
|
||||
already able to be coerced without an implementation of `CoerceUnsized`
|
||||
whereas a struct containing an unsized type needs to know the unsized type
|
||||
field it's containing is able to be coerced. An [unsized type][1]
|
||||
is any type that the compiler doesn't know the length or alignment of at
|
||||
compile time. Any struct containing an unsized type is also unsized.
|
||||
|
||||
[1]: https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait
|
||||
|
||||
The `CoerceUnsized` trait takes a struct type. Make sure the type you are
|
||||
providing to `CoerceUnsized` is a struct with only the last field containing an
|
||||
unsized type.
|
||||
|
Loading…
x
Reference in New Issue
Block a user