Repository: rust-analyzer/rust-analyzer
Pull request #3705 (2020-03-24 11:56:24)

Align naming


bors r+
🤖


Patch:
diff --git a/crates/ra_assists/src/handlers/add_missing_impl_members.rs b/crates/ra_assists/src/handlers/add_missing_impl_members.rs
index e5920b6f67..722f207e24 100644
--- a/crates/ra_assists/src/handlers/add_missing_impl_members.rs
+++ b/crates/ra_assists/src/handlers/add_missing_impl_members.rs
@@ -151,7 +151,7 @@ fn add_missing_impl_members_inner(
                 ast::ImplItem::FnDef(def) => ast::ImplItem::FnDef(add_body(def)),
                 _ => it,
             })
-            .map(|it| edit::strip_attrs_and_docs(&it));
+            .map(|it| edit::remove_attrs_and_docs(&it));
         let new_impl_item_list = impl_item_list.append_items(items);
         let cursor_position = {
             let first_new_item = new_impl_item_list.impl_items().nth(n_existing_items).unwrap();
diff --git a/crates/ra_assists/src/handlers/fill_match_arms.rs b/crates/ra_assists/src/handlers/fill_match_arms.rs
index add82e5b1b..88b4c89260 100644
--- a/crates/ra_assists/src/handlers/fill_match_arms.rs
+++ b/crates/ra_assists/src/handlers/fill_match_arms.rs
@@ -30,8 +30,8 @@ use ast::{MatchArm, Pat};
 //
 // fn handle(action: Action) {
 //     match action {
-//         Action::Move { distance } => {}
-//         Action::Stop => {}
+//         Action::Move { distance } => (),
+//         Action::Stop => (),
 //     }
 // }
 // ```
@@ -57,7 +57,7 @@ pub(crate) fn fill_match_arms(ctx: AssistCtx) -> Option<Assist> {
             .into_iter()
             .filter_map(|variant| build_pat(ctx.db, module, variant))
             .filter(|variant_pat| is_variant_missing(&mut arms, variant_pat))
-            .map(|pat| make::match_arm(iter::once(pat), make::expr_empty_block()))
+            .map(|pat| make::match_arm(iter::once(pat), make::expr_unit()))
             .collect()
     } else if let Some(enum_defs) = resolve_tuple_of_enum_def(&ctx.sema, &expr) {
         // Partial fill not currently supported for tuple of enums.
@@ -86,7 +86,7 @@ pub(crate) fn fill_match_arms(ctx: AssistCtx) -> Option<Assist> {
                 ast::Pat::from(make::tuple_pat(patterns))
             })
             .filter(|variant_pat| is_variant_missing(&mut arms, variant_pat))
-            .map(|pat| make::match_arm(iter::once(pat), make::expr_empty_block()))
+            .map(|pat| make::match_arm(iter::once(pat), make::expr_unit()))
             .collect()
     } else {
         return None;
@@ -192,8 +192,8 @@ mod tests {
             fn main() {
                 match A::As<|> {
                     A::As,
-                    A::Bs{x,y:Some(_)} => {}
-                    A::Cs(_, Some(_)) => {}
+                    A::Bs{x,y:Some(_)} => (),
+                    A::Cs(_, Some(_)) => (),
                 }
             }
             "#,
@@ -227,8 +227,8 @@ mod tests {
             }
             fn main() {
                 match A::As<|> {
-                    A::Bs{x,y:Some(_)} => {}
-                    A::Cs(_, Some(_)) => {}
+                    A::Bs{x,y:Some(_)} => (),
+                    A::Cs(_, Some(_)) => (),
                 }
             }
             "#,
@@ -240,9 +240,9 @@ mod tests {
             }
             fn main() {
                 match <|>A::As {
-                    A::Bs{x,y:Some(_)} => {}
-                    A::Cs(_, Some(_)) => {}
-                    A::As => {}
+                    A::Bs{x,y:Some(_)} => (),
+                    A::Cs(_, Some(_)) => (),
+                    A::As => (),
                 }
             }
             "#,
@@ -261,7 +261,7 @@ mod tests {
             }
             fn main() {
                 match A::As<|> {
-                    A::Cs(_) | A::Bs => {}
+                    A::Cs(_) | A::Bs => (),
                 }
             }
             "#,
@@ -273,8 +273,8 @@ mod tests {
             }
             fn main() {
                 match <|>A::As {
-                    A::Cs(_) | A::Bs => {}
-                    A::As => {}
+                    A::Cs(_) | A::Bs => (),
+                    A::As => (),
                 }
             }
             "#,
@@ -299,8 +299,8 @@ mod tests {
             }
             fn main() {
                 match A::As<|> {
-                    A::Bs if 0 < 1 => {}
-                    A::Ds(_value) => { let x = 1; }
+                    A::Bs if 0 < 1 => (),
+                    A::Ds(_value) => (),
                     A::Es(B::Xs) => (),
                 }
             }
@@ -319,11 +319,11 @@ mod tests {
             }
             fn main() {
                 match <|>A::As {
-                    A::Bs if 0 < 1 => {}
-                    A::Ds(_value) => { let x = 1; }
+                    A::Bs if 0 < 1 => (),
+                    A::Ds(_value) => (),
                     A::Es(B::Xs) => (),
-                    A::As => {}
-                    A::Cs => {}
+                    A::As => (),
+                    A::Cs => (),
                 }
             }
             "#,
@@ -360,11 +360,11 @@ mod tests {
             fn main() {
                 let a = A::As;
                 match <|>a {
-                    A::As => {}
-                    A::Bs => {}
-                    A::Cs(_) => {}
-                    A::Ds(_, _) => {}
-                    A::Es { x, y } => {}
+                    A::As => (),
+                    A::Bs => (),
+                    A::Cs(_) => (),
+                    A::Ds(_, _) => (),
+                    A::Es { x, y } => (),
                 }
             }
             "#,
@@ -405,10 +405,10 @@ mod tests {
                 let a = A::One;
                 let b = B::One;
                 match <|>(a, b) {
-                    (A::One, B::One) => {}
-                    (A::One, B::Two) => {}
-                    (A::Two, B::One) => {}
-                    (A::Two, B::Two) => {}
+                    (A::One, B::One) => (),
+                    (A::One, B::Two) => (),
+                    (A::Two, B::One) => (),
+                    (A::Two, B::Two) => (),
                 }
             }
             "#,
@@ -449,10 +449,10 @@ mod tests {
                 let a = A::One;
                 let b = B::One;
                 match <|>(&a, &b) {
-                    (A::One, B::One) => {}
-                    (A::One, B::Two) => {}
-                    (A::Two, B::One) => {}
-                    (A::Two, B::Two) => {}
+                    (A::One, B::One) => (),
+                    (A::One, B::Two) => (),
+                    (A::Two, B::One) => (),
+                    (A::Two, B::Two) => (),
                 }
             }
             "#,
@@ -477,7 +477,7 @@ mod tests {
                 let a = A::One;
                 let b = B::One;
                 match (a<|>, b) {
-                    (A::Two, B::One) => {}
+                    (A::Two, B::One) => (),
                 }
             }
             "#,
@@ -502,10 +502,10 @@ mod tests {
                 let a = A::One;
                 let b = B::One;
                 match (a<|>, b) {
-                    (A::Two, B::One) => {}
-                    (A::One, B::One) => {}
-                    (A::One, B::Two) => {}
-                    (A::Two, B::Two) => {}
+                    (A::Two, B::One) => (),
+                    (A::One, B::One) => (),
+                    (A::One, B::Two) => (),
+                    (A::Two, B::Two) => (),
                 }
             }
             "#,
@@ -555,7 +555,7 @@ mod tests {
 
             fn foo(a: &A) {
                 match <|>a {
-                    A::As => {}
+                    A::As => (),
                 }
             }
             "#,
@@ -580,7 +580,7 @@ mod tests {
 
             fn foo(a: &mut A) {
                 match <|>a {
-                    A::Es { x, y } => {}
+                    A::Es { x, y } => (),
                 }
             }
             "#,
@@ -611,7 +611,7 @@ mod tests {
 
             fn main() {
                 match E::X {
-                    <|>_ => {}
+                    <|>_ => {},
                 }
             }
             "#,
@@ -620,8 +620,8 @@ mod tests {
 
             fn main() {
                 match <|>E::X {
-                    E::X => {}
-                    E::Y => {}
+                    E::X => (),
+                    E::Y => (),
                 }
             }
             "#,
@@ -648,8 +648,8 @@ mod tests {
 
             fn main() {
                 match <|>X {
-                    X => {}
-                    foo::E::Y => {}
+                    X => (),
+                    foo::E::Y => (),
                 }
             }
             "#,
diff --git a/crates/ra_ide/src/completion/complete_trait_impl.rs b/crates/ra_ide/src/completion/complete_trait_impl.rs
index 7fefa2c7a8..ded1ff3bcc 100644
--- a/crates/ra_ide/src/completion/complete_trait_impl.rs
+++ b/crates/ra_ide/src/completion/complete_trait_impl.rs
@@ -193,7 +193,7 @@ fn add_const_impl(
 }
 
 fn make_const_compl_syntax(const_: &ast::ConstDef) -> String {
-    let const_ = edit::strip_attrs_and_docs(const_);
+    let const_ = edit::remove_attrs_and_docs(const_);
 
     let const_start = const_.syntax().text_range().start();
     let const_end = const_.syntax().text_range().end();
diff --git a/crates/ra_syntax/src/ast/edit.rs b/crates/ra_syntax/src/ast/edit.rs
index 68dae008f3..324327162c 100644
--- a/crates/ra_syntax/src/ast/edit.rs
+++ b/crates/ra_syntax/src/ast/edit.rs
@@ -296,11 +296,11 @@ impl ast::UseTree {
 }
 
 #[must_use]
-pub fn strip_attrs_and_docs<N: ast::AttrsOwner>(node: &N) -> N {
-    N::cast(strip_attrs_and_docs_inner(node.syntax().clone())).unwrap()
+pub fn remove_attrs_and_docs<N: ast::AttrsOwner>(node: &N) -> N {
+    N::cast(remove_attrs_and_docs_inner(node.syntax().clone())).unwrap()
 }
 
-fn strip_attrs_and_docs_inner(mut node: SyntaxNode) -> SyntaxNode {
+fn remove_attrs_and_docs_inner(mut node: SyntaxNode) -> SyntaxNode {
     while let Some(start) =
         node.children_with_tokens().find(|it| it.kind() == ATTR || it.kind() == COMMENT)
     {
diff --git a/crates/ra_syntax/src/ast/make.rs b/crates/ra_syntax/src/ast/make.rs
index 1145b69e89..9257ccd1a4 100644
--- a/crates/ra_syntax/src/ast/make.rs
+++ b/crates/ra_syntax/src/ast/make.rs
@@ -87,9 +87,6 @@ pub fn block_from_expr(e: ast::Expr) -> ast::Block {
 pub fn expr_unit() -> ast::Expr {
     expr_from_text("()")
 }
-pub fn expr_empty_block() -> ast::Expr {
-    expr_from_text("{}")
-}
 pub fn expr_unimplemented() -> ast::Expr {
     expr_from_text("unimplemented!()")
 }
diff --git a/docs/user/assists.md b/docs/user/assists.md
index f3ce6b0e0f..e2850b4dde 100644
--- a/docs/user/assists.md
+++ b/docs/user/assists.md
@@ -267,8 +267,8 @@ enum Action { Move { distance: u32 }, Stop }
 
 fn handle(action: Action) {
     match action {
-        Action::Move { distance } => {}
-        Action::Stop => {}
+        Action::Move { distance } => (),
+        Action::Stop => (),
     }
 }
 ```


Test patch:
diff --git a/crates/ra_assists/src/doc_tests/generated.rs b/crates/ra_assists/src/doc_tests/generated.rs
index 62dcb38089..aef6793e89 100644
--- a/crates/ra_assists/src/doc_tests/generated.rs
+++ b/crates/ra_assists/src/doc_tests/generated.rs
@@ -275,8 +275,8 @@ enum Action { Move { distance: u32 }, Stop }
 
 fn handle(action: Action) {
     match action {
-        Action::Move { distance } => {}
-        Action::Stop => {}
+        Action::Move { distance } => (),
+        Action::Stop => (),
     }
 }
 "#####,