mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 12:54:58 +00:00
Fix explicit deref problems in closure capture
This commit is contained in:
parent
1ee88db412
commit
7cb4318331
4 changed files with 90 additions and 4 deletions
|
@ -851,6 +851,43 @@ fn f() {
|
|||
}
|
||||
"#,
|
||||
);
|
||||
check_diagnostics(
|
||||
r#"
|
||||
//- minicore: copy, fn, deref_mut
|
||||
struct X(i32, i64);
|
||||
|
||||
fn f() {
|
||||
let mut x = &mut 5;
|
||||
//^^^^^ 💡 weak: variable does not need to be mutable
|
||||
let closure1 = || { *x = 2; };
|
||||
let _ = closure1();
|
||||
//^^^^^^^^ 💡 error: cannot mutate immutable variable `closure1`
|
||||
let mut x = &mut 5;
|
||||
//^^^^^ 💡 weak: variable does not need to be mutable
|
||||
let closure1 = move || { *x = 2; };
|
||||
let _ = closure1();
|
||||
//^^^^^^^^ 💡 error: cannot mutate immutable variable `closure1`
|
||||
let mut x = &mut X(1, 2);
|
||||
//^^^^^ 💡 weak: variable does not need to be mutable
|
||||
let closure1 = || { x.0 = 2; };
|
||||
let _ = closure1();
|
||||
//^^^^^^^^ 💡 error: cannot mutate immutable variable `closure1`
|
||||
}
|
||||
"#,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn allow_unused_mut_for_identifiers_starting_with_underline() {
|
||||
check_diagnostics(
|
||||
r#"
|
||||
fn f(_: i32) {}
|
||||
fn main() {
|
||||
let mut _x = 2;
|
||||
f(_x);
|
||||
}
|
||||
"#,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue