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

match guard is lengthening borrow unexpectedly under NLL #62170

Open
pnkfelix opened this issue Jun 27, 2019 · 1 comment
Open

match guard is lengthening borrow unexpectedly under NLL #62170

pnkfelix opened this issue Jun 27, 2019 · 1 comment
Labels
A-NLL Area: Non-lexical lifetimes (NLL) C-bug Category: This is a bug. NLL-complete Working towards the "valid code works" goal 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

@pnkfelix
Copy link
Member

Spawned off of #60914, namely the regression of the cs_review crate

I was looking for examples of soundness issues fixed by NLL for a blog post that I'm working on, and the first crate I looked at stymied me.

Maybe I'm forgetting something crucial, but I would think we might be able to accept this code (play):

struct Node(String, Option<Box<Node>>, Option<Box<Node>>);

fn main() {
    let mut data = Some(Box::new(Node("input1".to_string(), None, None)));
    let mut input1 = &mut data;
    loop {
        match {input1} { // the `{ }` fool AST-borrowck into accepting w/o NLL
            
            &mut Some(ref mut n) if {true} => { input1 = &mut n.1; }
        //            ~~~~~~~~~  ~~~~~~~~~ combo of 1. borrow, 2. guard, ... 

            _other => { break; }
        //  ~~~~~~                         ... and 3. move cause NLL to reject

        // Why does guard cause borrow last longer than it would otherwise here?
        }
    }
}

Note: I don't think we're going to hit this "regression" too often, because it critically depends on some bug in AST-borrowck where I believe AST-borrowck mishandled { ... } around the match input. Since I do not think that is a common pattern in match inputs, we probably can get away with not addressing this for a while.

@pnkfelix pnkfelix added A-NLL Area: Non-lexical lifetimes (NLL) NLL-complete Working towards the "valid code works" goal labels Jun 27, 2019
@pnkfelix
Copy link
Member Author

cc #60680

@jonas-schievink jonas-schievink added C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 27, 2019
@matthewjasper matthewjasper added the NLL-polonius Issues related for using Polonius in the borrow checker label Jun 27, 2019
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) C-bug Category: This is a bug. NLL-complete Working towards the "valid code works" goal 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