Strange interaction between matching and lifetimes #58787
Labels
A-NLL
Area: Non-lexical lifetimes (NLL)
NLL-polonius
Issues related for using Polonius in the borrow checker
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
I ran into some baffling issues when matching on a mutable reference and assigning to the mutable reference in the match arms. It seems that the inferred lifetime bound escapes the match. Playpen:
https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=4428e0752f518ba02ed12c77560d8afb
I tried three ways of matching on a borrowed value
list.0
. The first two work only without the "if true" block (1b, 1c). Should an if-block affect the inferred lifetime of the borrow oflist.0
?The last method does not work with (3a) or without (3b) the if-block, but I am still confused: why is
list.0
still borrowed after the match? Is this expected behavior?I would expect all six variants to be accepted by the borrow checker, and I'm confused about why only two of them are.
The text was updated successfully, but these errors were encountered: