Poor suggestions wrt closure type/lifetime inference #58525
Labels
A-closures
Area: Closures (`|…| { … }`)
A-diagnostics
Area: Messages for errors, warnings, and lints
A-inference
Area: Type inference
A-suggestion-diagnostics
Area: Suggestions generated by the compiler applied by `cargo fix`
C-enhancement
Category: An issue proposing an enhancement or a PR with one.
D-newcomer-roadblock
Diagnostics: Confusing error or lint; hard to understand for new users.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Given the following code:
rustc suggests:
Unfortunately, specifying a closure parameter type casts the user from the frying pan into the fire:
Helpful contributors on #rust-beginners found #55526 #56537 and the following simple workaround:
The underlying problem with lifetime inference in closures seems quite tricky and I guess it will remain like this for a while.
Under the circumstances, it would be nice if the compiler could make more helpful suggestions, including the trick with the let binding to nail the type.
Something like this maybe:
(for outputting, in addition to the other messages, in the more complicated lifetime problem case)
The text was updated successfully, but these errors were encountered: