-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Shadowing lifetimes should be disallowed or linted #18824
Comments
@nikomatsakis is working on a RFC that forbids shadowing of generic parameters (types/lifetimes). |
Great! :D |
@Manishearth There is now a discussion topic on the forums. |
And an rfc: rust-lang/rfcs#459 |
Looks like this got implemented in #19777 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The following code compiles:
However, in the event of a lifetime mismatch, this can lead to confusing error messages.
This gives a tautological recommendation along with a confusing error:
It's not really the error's fault for being so confusing, after all, we have shadowed the
'a
from the impl with a'a
from the definition ofbaz()
. This should probably be disallowed or at least linted.The recommendation is flawed in two ways
'a
, a lifetime which is already being used there (twice, actually). That's adding to the confusion. It clearly means to recommend a new lifetime ('b
?)bar()
to use'b
, it's still wrong, but then it gives the correct recommendation to usefn bar(self, other: Foo<'a>) -> bool
on recompiling.This probably needs better error reporting (don't recommend lifetimes which are already being used in that context)
@glennw came across this in Servo, getting tautological errors like this and this. The former is due to lifetime shadowing (and can be fixed by disallowing shadowing). I'm not yet sure what prompted the latter one, one of the lifetimes is elided but the other one is named
'a
in the surrounding impl and should have turned up in the error message instead of being underscored.The text was updated successfully, but these errors were encountered: