mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 12:54:58 +00:00
fix need-mut
false positive in closure capture of match scrutinee
This commit is contained in:
parent
7ef185d65e
commit
780349bdaf
4 changed files with 72 additions and 14 deletions
|
@ -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(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue