-
Notifications
You must be signed in to change notification settings - Fork 13.3k
borrow checker too restrictive in match statements, with confusing/confused compile errors #17462
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
Comments
This seems to be the same issue I'm having:
The example is a bit useless, but that's about as minimal as I could get it. The actual case was a Binary Search Tree. Playground link, but the short version is you get the error This is despite the fact that all the |
Perhaps the title should be changed to something like "Borrow checker is too sensitive to borrows in pattern matching." Another example has shown up on stack overflow. |
Doesn't look there anything diagnostic-related to do here. |
Triage: this code still does not compile |
Note that this will be fine once NLL stabilizes: struct Node {
left: Option<Box<Node>>,
}
fn leftmost_child(n: &mut Node) -> &mut Node {
let mut leftest = n;
loop {
match leftest.left {
Some(ref mut nl) => leftest = &mut **nl,
None => break,
}
}
leftest
}
fn main() {} Or more idiomatically: struct Node {
left: Option<Box<Node>>,
}
fn leftmost_child(n: &mut Node) -> &mut Node {
let mut leftest = n;
while let Some(ref mut nl) = leftest.left {
leftest = nl;
}
leftest
}
fn main() {} See also the canonical answer for this on Stack Overflow, which shows how to make it work before NLL. |
NLL (migrate mode) is enabled in all editions as of PR #59114. Verified that test case compiled in Nightly 2015 edition; closing as fixed. |
fix: Fix IDE features breaking in some attr macros Fixes rust-lang/rust-analyzer#17453, Fixes rust-lang/rust-analyzer#17458
yeilds
http://is.gd/7aqog5
Note that there's another error about being unable to assign to leftest within the match body. Should borrowing forbid reassignment here?
The text was updated successfully, but these errors were encountered: