-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Lifetime suggestion hint interacts weirdly with closures #17811
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
Comments
fn main() {
let closure = |x: &u32| -> &u32 { x };
} Same issue today. |
Given the name give_suggestion here which sounds too general, I think we'd better stop giving advice for this case, but I'm not sure.
In real coding I may try to make a helper function to retrieve the context by reference or even use a macro if I'm in a good mood (which I know might not really be a Rust way). Of course, better to avoid a closure here since lifetimes work better in real context rather than being used as arguments. |
I think it's also a valid option that we refactor the error_reporting.rs here to use proper method names, as this "give_suggestion" is not the only method name that looks misleading here. |
maybe related: #25005 |
#25005 is probably not related. ast_map's parenting is conceptually broken, but the current rustc code basically relies on this broken code (It uses |
Triage: no change. |
I don't see any errors after changing uint to u32 today; closing. |
fix: Panic while rendering function type hint with impl trait arg Fixes rust-lang#17811
Produces:
This is suggesting to put a lifetime on the
main
function, which certainly is not going to solve the problem here. The real solution is to giveclosure
an explicit type declaration:let closure: <'a>|&'a uint| -> &'a uint = ...;
.Incidentally, is lifetime elision supposed to work on closures, too? Evidently it does not.
The text was updated successfully, but these errors were encountered: