Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upShadowing lifetimes should be disallowed or linted #18824
Comments
This comment has been minimized.
This comment has been minimized.
|
@nikomatsakis is working on a RFC that forbids shadowing of generic parameters (types/lifetimes). |
This comment has been minimized.
This comment has been minimized.
|
Great! :D |
This comment has been minimized.
This comment has been minimized.
|
@Manishearth There is now a discussion topic on the forums. |
This comment has been minimized.
This comment has been minimized.
|
And an rfc: rust-lang/rfcs#459 |
This comment has been minimized.
This comment has been minimized.
|
Looks like this got implemented in #19777 |
Gankro
closed this
Jan 5, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Manishearth commentedNov 10, 2014
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
'afrom the impl with a'afrom 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>) -> boolon 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
'ain the surrounding impl and should have turned up in the error message instead of being underscored.