Repository: rust-analyzer/rust-analyzer
Pull request #7153 (2021-01-04 13:41:08)

rename exrtract_assignment -> pull
bors r+
🤖

matklad: cc @Jesse-Bakker 

Patch:
diff --git a/crates/assists/src/handlers/extract_assignment.rs b/crates/assists/src/handlers/pull_assignment_up.rs
similarity index 84%
rename from crates/assists/src/handlers/extract_assignment.rs
rename to crates/assists/src/handlers/pull_assignment_up.rs
index ae99598c00..560d93e101 100644
--- a/crates/assists/src/handlers/extract_assignment.rs
+++ b/crates/assists/src/handlers/pull_assignment_up.rs
@@ -9,9 +9,9 @@ use crate::{
     AssistId, AssistKind,
 };
 
-// Assist: extract_assignment
+// Assist: pull_assignment_up
 //
-// Extracts variable assigment to outside an if or match statement.
+// Extracts variable assignment to outside an if or match statement.
 //
 // ```
 // fn main() {
@@ -36,7 +36,7 @@ use crate::{
 //     };
 // }
 // ```
-pub(crate) fn extract_assigment(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
+pub(crate) fn pull_assignment_up(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
     let assign_expr = ctx.find_node_at_offset::<ast::BinExpr>()?;
     let name_expr = if assign_expr.op_kind()? == ast::BinOp::Assignment {
         assign_expr.lhs()?
@@ -61,8 +61,8 @@ pub(crate) fn extract_assigment(acc: &mut Assists, ctx: &AssistContext) -> Optio
     let expr_stmt = make::expr_stmt(new_stmt);
 
     acc.add(
-        AssistId("extract_assignment", AssistKind::RefactorExtract),
-        "Extract assignment",
+        AssistId("pull_assignment_up", AssistKind::RefactorExtract),
+        "Pull assignment up",
         old_stmt.syntax().text_range(),
         move |edit| {
             edit.replace(old_stmt.syntax().text_range(), format!("{} = {};", name_expr, expr_stmt));
@@ -104,7 +104,7 @@ fn exprify_if(
             ast::ElseBranch::Block(exprify_block(block, sema, name)?)
         }
         ast::ElseBranch::IfExpr(expr) => {
-            mark::hit!(test_extract_assigment_chained_if);
+            mark::hit!(test_pull_assignment_up_chained_if);
             ast::ElseBranch::IfExpr(ast::IfExpr::cast(
                 exprify_if(&expr, sema, name)?.syntax().to_owned(),
             )?)
@@ -144,7 +144,7 @@ fn is_equivalent(
 ) -> bool {
     match (expr0, expr1) {
         (ast::Expr::FieldExpr(field_expr0), ast::Expr::FieldExpr(field_expr1)) => {
-            mark::hit!(test_extract_assignment_field_assignment);
+            mark::hit!(test_pull_assignment_up_field_assignment);
             sema.resolve_field(field_expr0) == sema.resolve_field(field_expr1)
         }
         (ast::Expr::PathExpr(path0), ast::Expr::PathExpr(path1)) => {
@@ -167,9 +167,9 @@ mod tests {
     use crate::tests::{check_assist, check_assist_not_applicable};
 
     #[test]
-    fn test_extract_assignment_if() {
+    fn test_pull_assignment_up_if() {
         check_assist(
-            extract_assigment,
+            pull_assignment_up,
             r#"
 fn foo() {
     let mut a = 1;
@@ -194,9 +194,9 @@ fn foo() {
     }
 
     #[test]
-    fn test_extract_assignment_match() {
+    fn test_pull_assignment_up_match() {
         check_assist(
-            extract_assigment,
+            pull_assignment_up,
             r#"
 fn foo() {
     let mut a = 1;
@@ -233,9 +233,9 @@ fn foo() {
     }
 
     #[test]
-    fn test_extract_assignment_not_last_not_applicable() {
+    fn test_pull_assignment_up_not_last_not_applicable() {
         check_assist_not_applicable(
-            extract_assigment,
+            pull_assignment_up,
             r#"
 fn foo() {
     let mut a = 1;
@@ -251,10 +251,10 @@ fn foo() {
     }
 
     #[test]
-    fn test_extract_assignment_chained_if() {
-        mark::check!(test_extract_assigment_chained_if);
+    fn test_pull_assignment_up_chained_if() {
+        mark::check!(test_pull_assignment_up_chained_if);
         check_assist(
-            extract_assigment,
+            pull_assignment_up,
             r#"
 fn foo() {
     let mut a = 1;
@@ -283,9 +283,9 @@ fn foo() {
     }
 
     #[test]
-    fn test_extract_assigment_retains_stmts() {
+    fn test_pull_assignment_up_retains_stmts() {
         check_assist(
-            extract_assigment,
+            pull_assignment_up,
             r#"
 fn foo() {
     let mut a = 1;
@@ -314,9 +314,9 @@ fn foo() {
     }
 
     #[test]
-    fn extract_assignment_let_stmt_not_applicable() {
+    fn pull_assignment_up_let_stmt_not_applicable() {
         check_assist_not_applicable(
-            extract_assigment,
+            pull_assignment_up,
             r#"
 fn foo() {
     let mut a = 1;
@@ -331,9 +331,9 @@ fn foo() {
     }
 
     #[test]
-    fn extract_assignment_if_missing_assigment_not_applicable() {
+    fn pull_assignment_up_if_missing_assigment_not_applicable() {
         check_assist_not_applicable(
-            extract_assigment,
+            pull_assignment_up,
             r#"
 fn foo() {
     let mut a = 1;
@@ -346,9 +346,9 @@ fn foo() {
     }
 
     #[test]
-    fn extract_assignment_match_missing_assigment_not_applicable() {
+    fn pull_assignment_up_match_missing_assigment_not_applicable() {
         check_assist_not_applicable(
-            extract_assigment,
+            pull_assignment_up,
             r#"
 fn foo() {
     let mut a = 1;
@@ -367,10 +367,10 @@ fn foo() {
     }
 
     #[test]
-    fn test_extract_assignment_field_assignment() {
-        mark::check!(test_extract_assignment_field_assignment);
+    fn test_pull_assignment_up_field_assignment() {
+        mark::check!(test_pull_assignment_up_field_assignment);
         check_assist(
-            extract_assigment,
+            pull_assignment_up,
             r#"
 struct A(usize);
 
diff --git a/crates/assists/src/lib.rs b/crates/assists/src/lib.rs
index 212464f859..01baa65fe0 100644
--- a/crates/assists/src/lib.rs
+++ b/crates/assists/src/lib.rs
@@ -116,7 +116,6 @@ mod handlers {
     mod convert_integer_literal;
     mod early_return;
     mod expand_glob_import;
-    mod extract_assignment;
     mod extract_module_to_file;
     mod extract_struct_from_enum_variant;
     mod extract_variable;
@@ -125,8 +124,8 @@ mod handlers {
     mod flip_binexpr;
     mod flip_comma;
     mod flip_trait_bound;
-    mod generate_derive;
     mod generate_default_from_enum_variant;
+    mod generate_derive;
     mod generate_from_impl_for_enum;
     mod generate_function;
     mod generate_impl;
@@ -139,6 +138,7 @@ mod handlers {
     mod merge_match_arms;
     mod move_bounds;
     mod move_guard;
+    mod pull_assignment_up;
     mod qualify_path;
     mod raw_string;
     mod remove_dbg;
@@ -168,7 +168,6 @@ mod handlers {
             convert_integer_literal::convert_integer_literal,
             early_return::convert_to_guarded_return,
             expand_glob_import::expand_glob_import,
-            extract_assignment::extract_assigment,
             extract_module_to_file::extract_module_to_file,
             extract_struct_from_enum_variant::extract_struct_from_enum_variant,
             extract_variable::extract_variable,
@@ -177,8 +176,8 @@ mod handlers {
             flip_binexpr::flip_binexpr,
             flip_comma::flip_comma,
             flip_trait_bound::flip_trait_bound,
-            generate_derive::generate_derive,
             generate_default_from_enum_variant::generate_default_from_enum_variant,
+            generate_derive::generate_derive,
             generate_from_impl_for_enum::generate_from_impl_for_enum,
             generate_function::generate_function,
             generate_impl::generate_impl,
@@ -192,6 +191,7 @@ mod handlers {
             move_bounds::move_bounds_to_where_clause,
             move_guard::move_arm_cond_to_match_guard,
             move_guard::move_guard_to_arm_body,
+            pull_assignment_up::pull_assignment_up,
             qualify_path::qualify_path,
             raw_string::add_hash,
             raw_string::make_usual_string,


Test patch:
diff --git a/crates/assists/src/tests/generated.rs b/crates/assists/src/tests/generated.rs
index b91a816e89..85e3c67429 100644
--- a/crates/assists/src/tests/generated.rs
+++ b/crates/assists/src/tests/generated.rs
@@ -237,35 +237,6 @@ fn qux(bar: Bar, baz: Baz) {}
     )
 }
 
-#[test]
-fn doctest_extract_assignment() {
-    check_doc_test(
-        "extract_assignment",
-        r#####"
-fn main() {
-    let mut foo = 6;
-
-    if true {
-        <|>foo = 5;
-    } else {
-        foo = 4;
-    }
-}
-"#####,
-        r#####"
-fn main() {
-    let mut foo = 6;
-
-    foo = if true {
-        5
-    } else {
-        4
-    };
-}
-"#####,
-    )
-}
-
 #[test]
 fn doctest_extract_module_to_file() {
     check_doc_test(
@@ -766,6 +737,35 @@ fn handle(action: Action) {
     )
 }
 
+#[test]
+fn doctest_pull_assignment_up() {
+    check_doc_test(
+        "pull_assignment_up",
+        r#####"
+fn main() {
+    let mut foo = 6;
+
+    if true {
+        <|>foo = 5;
+    } else {
+        foo = 4;
+    }
+}
+"#####,
+        r#####"
+fn main() {
+    let mut foo = 6;
+
+    foo = if true {
+        5
+    } else {
+        4
+    };
+}
+"#####,
+    )
+}
+
 #[test]
 fn doctest_qualify_path() {
     check_doc_test(