]> git.lizzy.rs Git - rust.git/commitdiff
Don't inline mutable locals in 'inline_local_variable'
authorLukas Wirth <lukastw97@gmail.com>
Fri, 4 Jun 2021 18:36:43 +0000 (20:36 +0200)
committerLukas Wirth <lukastw97@gmail.com>
Fri, 4 Jun 2021 18:43:48 +0000 (20:43 +0200)
crates/ide_assists/src/handlers/inline_local_variable.rs

index f5dafc8cb1fd8e05d84d2a347917fcfdf61024a6..2441dbb8b286a7c0bfb49e7d21712761bc072fad 100644 (file)
@@ -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,
@@ -426,6 +430,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(