-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-associated-itemsArea: Associated items (types, constants & functions)Area: Associated items (types, constants & functions)A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`Area: Suggestions generated by the compiler applied by `cargo fix`C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.D-papercutDiagnostics: An error or lint that needs small tweaks.Diagnostics: An error or lint that needs small tweaks.P-lowLow priorityLow priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
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).
bergus, mjbshaw, phimuemue and Robbepop
Metadata
Metadata
Assignees
Labels
A-associated-itemsArea: Associated items (types, constants & functions)Area: Associated items (types, constants & functions)A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`Area: Suggestions generated by the compiler applied by `cargo fix`C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.D-papercutDiagnostics: An error or lint that needs small tweaks.Diagnostics: An error or lint that needs small tweaks.P-lowLow priorityLow priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.