Closed
Description
Repro:
trait O {
type M;
}
trait U<A: O> {
const N: A::M;
}
impl<D> O for D {
type M = u8;
}
impl<C: O> U<C> for u16 {
const N: C::M = 4;
}
This caused E0277 "the trait bound is not satisfied" error:
error[E0277]: the trait bound `C: std::marker::Sized` is not satisfied
--> src/main.rs:11:5
|
11 | const N: C::M = 4;
| ^^^^^^^^^^^^^^^^^^ `C` does not have a constant size known at compile-time
|
= help: the trait `std::marker::Sized` is not implemented for `C`
= help: consider adding a `where C: std::marker::Sized` bound
= note: required because of the requirements on the impl of `O` for `C`
The error doesn't make sense because C
is obviously Sized
. It seems the associated const type is evaluated before the generic bounds are added, causing this error.
Changing both A::M
and C::M
to u8
makes the error go away.
Reproducible on all 3 versions on playground (1.23.0, 1.24.0-beta, 1.25.0-nightly).
Metadata
Metadata
Assignees
Labels
Area: Associated items (types, constants & functions)Area: Messages for errors, warnings, and lintsArea: Suggestions generated by the compiler applied by `cargo fix`Category: An issue proposing an enhancement or a PR with one.Diagnostics: An error or lint that needs small tweaks.Low priorityRelevant to the compiler team, which will review and decide on the PR/issue.