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 upWarn when elided lifetime is shorter than it could have been. #42287
Comments
This comment has been minimized.
This comment has been minimized.
|
I don't think this is going to be a good fit for Rust, since I think there could be false positives. I'm going to close this issue -- feel free to file either an RFC or ask Clippy if they'd like something like this. |
Mark-Simulacrum
closed this
Jun 23, 2017
This comment has been minimized.
This comment has been minimized.
|
@Mark-Simulacrum Any case in which this is a false positive is special and should be documented with explicit lifetimes anyhow, this seems like a very good lint for rustc. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
matklad commentedMay 28, 2017
•
edited
Hi! Several times I've faced this interesting case of lifetime miselision:
http://play.integer32.com/?gist=3aba0526aff729bb9d62483a10732826&version=undefined
Here, we want to use
'alifetime for the returnedBarreference, but lifetime elision gives use lifetime of the self reference. The problem here is that code with elided lifetimes compiles flawlessly by itself, but may fail at the call site, and this is tremendously confusing, because you get a misleading compiler error in the completely wrong place! I've hit this issues several times in practice (the latest one).I wonder if we can warn about this? That is, we issue a warning if a lifetime in a returned position is elided, but the lifetime of the returned value from the function can actually be larger (alternatively, if the actual lifetime is among the input lifetimes, and is not the same as the one inferred by elision). The fix for warning would be to specify lifetimes explicitly (I suppose that "I did mean to use a shorter lifetime here" is a rather rare use-case).