-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Closed
Copy link
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsT-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
struct State;
trait Foo<T> {
fn foo<'a>(&self, state: &'a State) -> &'a T
where
T: 'a;
}
impl<F, T> Foo<T> for F
where
F: Fn(&State) -> &T,
{
fn foo<'a>(&self, state: &'a State) -> &'a T {
self(state)
}
}
The current output is:
error[E0195]: lifetime parameters or bounds on method `foo` do not match the trait declaration
--> src/lib.rs:13:11
|
4 | fn foo<'a>(&self, state: &'a State) -> &'a T
| ---- lifetimes in impl do not match this method in trait
...
13 | fn foo<'a>(&self, state: &'a State) -> &'a T {
| ^^^^ lifetimes do not match method in trait
For more information about this error, try `rustc --explain E0195`.
This error message, especially due to the highlighted code, makes me believe that there is some problem with the generic lifetime itself. However, the problem is the missing where bound that never appears in the error message.
Ideally, the error message should highlight the where clause of the trait that is missing from the implementation, along the lines of this:
error[E0195]: lifetime parameters or bounds on method `foo` do not match the trait declaration
--> src/lib.rs:13:11
|
4 | fn foo<'a>(&self, state: &'a State) -> &'a T
| ---- lifetimes in impl do not match this method in trait
...
13 | fn foo<'a>(&self, state: &'a State) -> &'a T {
| ^^^^ lifetimes do not match method in trait
help: Try adding the following bound:
--> src/lib.rs:6:
|
6 | T: 'a;
| ^^^^^
For more information about this error, try `rustc --explain E0195`.
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsT-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.