Skip to content

Commit 1bd04d9

Browse files
committed
Don't inline mutable locals in 'inline_local_variable'
1 parent 98395f2 commit 1bd04d9

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

crates/ide_assists/src/handlers/inline_local_variable.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,10 @@ fn inline_usage(ctx: &AssistContext) -> Option<InlineData> {
182182
PathResolution::Local(local) => local,
183183
_ => return None,
184184
};
185+
if local.is_mut(ctx.sema.db) {
186+
cov_mark::hit!(test_not_inline_mut_variable_use);
187+
return None;
188+
}
185189

186190
let bind_pat = match local.source(ctx.db()).value {
187191
Either::Left(ident) => ident,
@@ -426,6 +430,19 @@ fn foo() {
426430
);
427431
}
428432

433+
#[test]
434+
fn test_not_inline_mut_variable_use() {
435+
cov_mark::check!(test_not_inline_mut_variable_use);
436+
check_assist_not_applicable(
437+
inline_local_variable,
438+
r"
439+
fn foo() {
440+
let mut a = 1 + 1;
441+
a$0 + 1;
442+
}",
443+
);
444+
}
445+
429446
#[test]
430447
fn test_call_expr() {
431448
check_assist(

0 commit comments

Comments
 (0)