Closed
Description
Given the following code: (playground)
struct A<T: Sized>(T);
struct B(A<[u8]>);
The current output is:
error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
--> src/lib.rs:2:10
|
1 | struct A<T: Sized>(T);
| - required by this bound in `A`
2 | struct B(A<[u8]>);
| ^^^^^^^ doesn't have a size known at compile-time
|
= help: the trait `Sized` is not implemented for `[u8]`
Ideally the output should look like:
error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
--> src/lib.rs:2:10
|
1 | struct A<T: Sized>(T);
| ----- required by this bound in `A`
2 | struct B(A<[u8]>);
| ^^^^^^^ doesn't have a size known at compile-time
|
= help: the trait `Sized` is not implemented for `[u8]`
When the implicit Sized
bound is added for generic type parameters, it goes at the front of the emitted predicate list. This means that its span, which is limited to the identifier of the generic, is what shows up in the error. It would be better if the error span pointed to the actual occurrence of the explicit Sized
bound. Moving that implicit predicate to the end of the list would improve at least some of the error spans where there is an explicit Sized
bound.
I'm working on a pull request for this issue.
@rustbot claim
@rustbot label +A-traits +A-typesystem +D-papercut