Skip to content
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

Strange interaction between matching and lifetimes #58787

Open
justhsu opened this issue Feb 27, 2019 · 0 comments
Open

Strange interaction between matching and lifetimes #58787

justhsu opened this issue Feb 27, 2019 · 0 comments
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.

Comments

@justhsu
Copy link

justhsu commented Feb 27, 2019

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 of list.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.

@matthewjasper matthewjasper added A-NLL Area: Non-lexical lifetimes (NLL) NLL-polonius Issues related for using Polonius in the borrow checker labels Feb 27, 2019
@crlf0710 crlf0710 added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jun 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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.
Projects
None yet
Development

No branches or pull requests

3 participants