-
-
Notifications
You must be signed in to change notification settings - Fork 14.4k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-lifetimesArea: Lifetimes / regionsArea: Lifetimes / regionsA-trait-systemArea: Trait systemArea: Trait systemC-bugCategory: This is a bug.Category: This is a bug.D-confusingDiagnostics: Confusing error or lint that should be reworked.Diagnostics: Confusing error or lint that should be reworked.D-newcomer-roadblockDiagnostics: Confusing error or lint; hard to understand for new users.Diagnostics: Confusing error or lint; hard to understand for new users.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 Foo<T> {
fn make_it(&self) -> T;
}
impl Foo<&u8> for () {
fn make_it(&self) -> &u8 {
&25
}
}produces the following error:
error: `impl` item signature doesn't match `trait` item signature
--> src/lib.rs:6:5
|
2 | fn make_it(&self) -> T;
| ----------------------- expected fn(&()) -> &u8
...
6 | fn make_it(&self) -> &u8 {
| ^^^^^^^^^^^^^^^^^^^^^^^^ found fn(&()) -> &u8
|
= note: expected `fn(&()) -> &u8`
found `fn(&()) -> &u8`
The issue is that the elided lifetimes in the impl header (impl Foo<&u8> for ()) and the method implementation fn make_it(&self) -> &u8 do not desugar to the same lifetime. However, we currently emit a nonsensical error message instead of explaining this.
We should explain the behavior of lifetime elision, and suggest introducing a lifetime parameter in the impl header.
jplattesffc and voronaam
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-lifetimesArea: Lifetimes / regionsArea: Lifetimes / regionsA-trait-systemArea: Trait systemArea: Trait systemC-bugCategory: This is a bug.Category: This is a bug.D-confusingDiagnostics: Confusing error or lint that should be reworked.Diagnostics: Confusing error or lint that should be reworked.D-newcomer-roadblockDiagnostics: Confusing error or lint; hard to understand for new users.Diagnostics: Confusing error or lint; hard to understand for new users.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.