Closed
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.
Metadata
Metadata
Assignees
Labels
Area: Messages for errors, warnings, and lintsArea: Lifetimes / regionsArea: Trait systemCategory: This is a bug.Diagnostics: Confusing error or lint that should be reworked.Diagnostics: Confusing error or lint; hard to understand for new users.Relevant to the compiler team, which will review and decide on the PR/issue.