-
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 lintsC-bugCategory: This is a bug.Category: This is a bug.D-inconsistentDiagnostics: Inconsistency in formatting, grammar or style between diagnostic messages.Diagnostics: Inconsistency in formatting, grammar or style between diagnostic messages.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
The following code:
trait MyTrait {
type Item;
}
trait OtherTrait {
type OtherItem;
}
/*impl OtherTrait for bool {
type OtherItem = (<u8 as MyTrait>::Item, bool);
}*/
fn main() {
let a: (<u8 as MyTrait>::Item, bool);
}
produces the following error:
error[E0277]: the trait bound `u8: MyTrait` is not satisfied
--> src/main.rs:14:13
|
14 | let a: (<u8 as MyTrait>::Item, bool);
| ^^^^^^^^^^^^^^^^^^^^^ the trait `MyTrait` is not implemented for `u8`
error: aborting due to previous error
Note that the span points directly at <u8 as MyTrait>::Item
However, if the same projection <u8 as MyTrait>::Item
is used in associated type position:
trait MyTrait {
type Item;
}
trait OtherTrait {
type OtherItem;
}
impl OtherTrait for bool {
type OtherItem = (<u8 as MyTrait>::Item, bool);
}
/*fn main() {
let a: (<u8 as MyTrait>::Item, bool);
}*/
produces this error:
error[E0277]: the trait bound `u8: MyTrait` is not satisfied
--> src/lib.rs:10:5
|
10 | type OtherItem = (<u8 as MyTrait>::Item, bool);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `MyTrait` is not implemented for `u8`
error: aborting due to previous error
Here, the span points to the entire associated type, instead of just the projection.
This can lead to unhelpful errors in macro-generated code, since the span of the associated type may be completely different from the span of the projection.
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.Category: This is a bug.D-inconsistentDiagnostics: Inconsistency in formatting, grammar or style between diagnostic messages.Diagnostics: Inconsistency in formatting, grammar or style between diagnostic messages.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.
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
Aaron1011 commentedon Jul 24, 2021
As of the latest nightly, this now produces:
pointing directly to the affected projection.