Closed
Description
I understand this shouldn't be possible in some occasions, because you might be able to modify what you're matching, which can cause the match to break. Why would it be disallowed to mutably borrow something that only exists within the match though?
fn main() {
let a = 3u8;
match a {
0 => (),
3 if compare(&a, &mut 3) => (),
_ => (),
}
}
fn compare(a: &u8, b: &mut u8) -> bool {
a == b
}
I have constructed this minimal case. In my actual code I am running .iter().any()
on a variable form outside the match, which isn't allowed because .any()
requires a mutable borrow. As the thing I am mutably borrowing only exists within the match, this makes even less sense to me.
Compiler bug?
Metadata
Metadata
Assignees
Labels
No labels