-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Mutable borrows in an else if
after an if let
are disallowed
#28449
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
match f {
Some(a) => {}
_ if f.as_mut().is_some() {}
_ => {}
} |
duplicate #6393 |
actually, not. Why is this a pattern guard rather than an |
@arielb1 it's a pattern guard because this works: if let Some(1) = foo {
} else if check(&foo) {
} else if let Some(a) = foo {
} Obviously this doesn't require desugaring to a single match, but it does explain why it does right now. |
# for free
to join this conversation on GitHub.
Already have an account?
# to comment
Gives:
This is an unexpected result of how
if let
desugaring works, presumably. It’s unexpected because mutable borrowing is normally allowed inelse if
conditions, but becauseif let
seems to desugar a followingelse if
into a pattern guard, this is disallowed.To me it would make more sense for this to be treated like any other
else if
, and be permitted, or at the very least have a clearer message (because it’s not obvious (and is really just an implementation detail) how anelse if
condition is a pattern guard).The text was updated successfully, but these errors were encountered: