Temporary lifetime extension applies to the last expression of a for
loop body, causing unnecessary errors
#118544
Labels
for
loop body, causing unnecessary errors
#118544
I tried this code (reduced from https://users.rust-lang.org/t/lifetime-of-refcell-borrows/103346):
The following error results:
The suggested added semicolon does indeed let the code compile, but it really shouldn't be necessary because:
for
loop cannot ever return a value other than()
if let
withoutelse
cannot ever return a value other than()
(even if the pattern is irrefutable)It's also weird that
let cell = cell;
(or some other locallet
binding) is needed to trigger the problem; presumably this happens because there's a drop scope in between the binding of the loop's pattern and the body block, but it's not at all obvious that the pattern should be longer-lived in that way.Meta
rustc --version --verbose
:Also tested on stable 1.74.0 on the Playground.
The text was updated successfully, but these errors were encountered: