Lifetime elision is too greedy without explicit type declaration #39943
Labels
A-closures
Area: Closures (`|…| { … }`)
A-inference
Area: Type inference
A-lifetimes
Area: Lifetimes / regions
C-bug
Category: This is a bug.
NLL-fixed-by-NLL
Bugs fixed, but only when NLL is enabled.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
In the next example the closure borrows the value for longer than it should do:
Which causes compilation error:
However, if we declare the argument type explicitly, it works just as expected:
Not sure if that is a bug or expected behaviour. Neither could I find explanation of this effect in the documentation.
Meta
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: