-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
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`A-trait-systemArea: Trait systemArea: Trait systemC-bugCategory: This is a bug.Category: This is a bug.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.Diagnostics: A structured suggestion resulting in incorrect code.T-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
I tried this code:
trait Trait: SuperTrait {
fn array() -> [u8; Self::SIZE];
}
trait SuperTrait {
const SIZE: usize;
}
I expected to see this happen: an error that would help me write the correct code.
Instead, this happened: rustc tells me to duplicate the supertrait bound:
error[E0599]: no associated item named `SIZE` found for type parameter `Self` in the current scope
--> src/lib.rs:2:30
|
2 | fn array() -> [u8; Self::SIZE];
| ^^^^ associated item not found in `Self`
|
= help: items from traits can only be used if the type parameter is bounded by the trait
help: the following trait defines an item `SIZE`, perhaps you need to add another supertrait for it:
|
1 | trait Trait: SuperTrait + SuperTrait {
| ^^^^^^^^^^^^
This happens on both stable and nightly.
(I think it should potentially suggest <Self as SuperTrait>::Size
in this case, but that doesn't seem to work either, see #72192.)
Metadata
Metadata
Assignees
Labels
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`A-trait-systemArea: Trait systemArea: Trait systemC-bugCategory: This is a bug.Category: This is a bug.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.Diagnostics: A structured suggestion resulting in incorrect code.T-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.