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

Borrow checker: borrows in else branch of if let #38159

Closed
theduke opened this issue Dec 4, 2016 · 2 comments
Closed

Borrow checker: borrows in else branch of if let #38159

theduke opened this issue Dec 4, 2016 · 2 comments

Comments

@theduke
Copy link
Contributor

theduke commented Dec 4, 2016

If there already is an issue for this, I apologize. I couldn't find one, but searching for this is a bit hard.

Right now, the borrow checker does not allow a borrow of a variable in the else branch if the let binding borrows the variable.

Example:

  let mut m = HashMap::<i64, bool>::new();
  if let Some(x) = m.get(&10) {
    // do something...
  }
  else {
    m.insert(10, true);
  }

The m.insert is invalid, because the borrow checker assumes an active borrow for the hashmap.

The Some(x) binding is not in scope anymore, though, and there's no way to access x, so this should be allowed.

@theduke theduke changed the title Borrow checker: mutable borrows in else branch of if let Borrow checker: borrows in else branch of if let Dec 4, 2016
@sfackler
Copy link
Member

sfackler commented Dec 4, 2016

I believe this is covered by rust-lang/rfcs#811

@theduke
Copy link
Contributor Author

theduke commented Dec 4, 2016

@sfackler yup, appear to be.

Closing as duplicate...

@theduke theduke closed this as completed Dec 4, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants