Skip to content

Commit d8b970f

Browse files
committed
Skip mutable diagnostics on synthetic bindings
1 parent 6d333e5 commit d8b970f

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

crates/hir/src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1661,6 +1661,14 @@ impl DefWithBody {
16611661
let Some(&local) = mir_body.binding_locals.get(binding_id) else {
16621662
continue;
16631663
};
1664+
if body[binding_id]
1665+
.definitions
1666+
.iter()
1667+
.any(|&pat| source_map.pat_syntax(pat).is_err())
1668+
{
1669+
// Skip synthetic bindings
1670+
continue;
1671+
}
16641672
let need_mut = &mol[local];
16651673
let local = Local { parent: self.into(), binding_id };
16661674
match (need_mut, local.is_mut(db)) {

crates/ide-diagnostics/src/handlers/mutability_errors.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,6 +1091,19 @@ fn main() {
10911091
//^^^^^ 💡 weak: variable does not need to be mutable
10921092
f(x);
10931093
}
1094+
"#,
1095+
);
1096+
}
1097+
1098+
#[test]
1099+
fn regression_15099() {
1100+
check_diagnostics(
1101+
r#"
1102+
//- minicore: iterator, range
1103+
fn f() {
1104+
loop {}
1105+
for _ in 0..2 {}
1106+
}
10941107
"#,
10951108
);
10961109
}

0 commit comments

Comments
 (0)