about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLukas Wirth <lukastw97@gmail.com>2021-06-04 20:36:43 +0200
committerLukas Wirth <lukastw97@gmail.com>2021-06-04 20:43:48 +0200
commit1bd04d9064399cc2e1c490906b897397ff6929b1 (patch)
tree9eb4a1f061f9dd2c07244a41b7788776272a7fe0
parent98395f29a417b37a5969594f0cac5ae23585da85 (diff)
downloadrust-1bd04d9064399cc2e1c490906b897397ff6929b1.tar.gz
rust-1bd04d9064399cc2e1c490906b897397ff6929b1.zip
Don't inline mutable locals in 'inline_local_variable'
-rw-r--r--crates/ide_assists/src/handlers/inline_local_variable.rs17
1 files changed, 17 insertions, 0 deletions
diff --git a/crates/ide_assists/src/handlers/inline_local_variable.rs b/crates/ide_assists/src/handlers/inline_local_variable.rs
index f5dafc8cb1f..2441dbb8b28 100644
--- a/crates/ide_assists/src/handlers/inline_local_variable.rs
+++ b/crates/ide_assists/src/handlers/inline_local_variable.rs
@@ -182,6 +182,10 @@ fn inline_usage(ctx: &AssistContext) -> Option<InlineData> {
         PathResolution::Local(local) => local,
         _ => return None,
     };
+    if local.is_mut(ctx.sema.db) {
+        cov_mark::hit!(test_not_inline_mut_variable_use);
+        return None;
+    }
 
     let bind_pat = match local.source(ctx.db()).value {
         Either::Left(ident) => ident,
@@ -427,6 +431,19 @@ fn foo() {
     }
 
     #[test]
+    fn test_not_inline_mut_variable_use() {
+        cov_mark::check!(test_not_inline_mut_variable_use);
+        check_assist_not_applicable(
+            inline_local_variable,
+            r"
+fn foo() {
+    let mut a = 1 + 1;
+    a$0 + 1;
+}",
+        );
+    }
+
+    #[test]
     fn test_call_expr() {
         check_assist(
             inline_local_variable,