fix need-mut false positive in closure capture of match scrutinee

This commit is contained in:
hkalbasi 2023-05-26 02:08:33 +03:30
parent 7ef185d65e
commit 780349bdaf
4 changed files with 72 additions and 14 deletions

View file

@ -352,6 +352,32 @@ fn main() {
);
}
#[test]
fn match_closure_capture() {
check_diagnostics(
r#"
//- minicore: option
fn main() {
let mut v = &mut Some(2);
//^^^^^ 💡 weak: variable does not need to be mutable
let _ = || match v {
Some(k) => {
*k = 5;
}
None => {}
};
let v = &mut Some(2);
let _ = || match v {
//^ 💡 error: cannot mutate immutable variable `v`
ref mut k => {
*k = &mut Some(5);
}
};
}
"#,
);
}
#[test]
fn match_bindings() {
check_diagnostics(