File tree Expand file tree Collapse file tree 1 file changed +11
-10
lines changed
src/librustc_error_codes/error_codes Expand file tree Collapse file tree 1 file changed +11
-10
lines changed Original file line number Diff line number Diff line change 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.
102
11- Example of erroneous code:
3+ Erroneous code example :
124
135``` compile_fail,E0376
146#![feature(coerce_unsized)]
@@ -22,6 +14,15 @@ struct Foo<T: ?Sized> {
2214impl<T, U> CoerceUnsized<U> for Foo<T> {}
2315```
2416
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+
2526The ` CoerceUnsized ` trait takes a struct type. Make sure the type you are
2627providing to ` CoerceUnsized ` is a struct with only the last field containing an
2728unsized type.
You can’t perform that action at this time.
0 commit comments