-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Misleading error when a trait method implementation has explicit lifetime parameters but the trait signature does not. #41343
Comments
Current output is still mistifying:
|
The error from this Stack Overflow question might be related: OP is seeing an error with lifetimes but actually he has just got the trait signature wrong. |
That OP has edited their question to no longer be meaningful to this discussion. This is the relevant revision: use std::ops::Index;
enum J_List<T> {
Cons(T, Box<J_List<T>>),
Nil,
}
struct List<T> {
value: J_List<T>,
}
impl<T> Index<usize> for List<T> {
type Output = T;
fn index(self, x: usize) -> &T {
unimplemented!();
}
} |
Triage: no change for the OP. For the case brought up in StackOverflow, the current output is
and if you follow the compiler advice you get
which nudges you in the right direction:
The first message already mentions "this function's return type contains a borrowed value with an elided lifetime, but the lifetime cannot be derived from the arguments", which could use a rephrase, but tells you what's wrong here. |
…nikomatsakis Custom lifetime error for `impl` item doesn't conform to `trait` Partly addresses rust-lang#42706, rust-lang#41343, fix rust-lang#40900.
…nikomatsakis Custom lifetime error for `impl` item doesn't conform to `trait` Partly addresses rust-lang#42706, rust-lang#41343, fix rust-lang#40900.
…nikomatsakis Custom lifetime error for `impl` item doesn't conform to `trait` Partly addresses rust-lang#42706, rust-lang#41343, fix rust-lang#40900.
The current output still fails to differentiate the lifetimes involved:
|
|
Current output:
|
Consider this example (playground):
The error message is:
All of the text of the error is focussed on the body of the function, even though there are no lifetime problems in the body with respect to the signature of the surrounding function. The actual error is that the signatures of the trait method and its implementation do not match.
The text was updated successfully, but these errors were encountered: