about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAdenine <22418744+adenine-dev@users.noreply.github.com>2023-07-08 12:21:38 -0400
committerGitHub <noreply@github.com>2023-07-08 12:21:38 -0400
commit514bab504e81f1b62bff7dd335022f4495e8fba3 (patch)
tree52f7751fb021e2577578899528e5dee01fe4be24
parent2e515d0ac9549fa9ff39f5ab86e7856914ddc23f (diff)
parentfdb8aa2ea6aa4335f4b7251f0ac02c946833b095 (diff)
downloadrust-514bab504e81f1b62bff7dd335022f4495e8fba3.tar.gz
rust-514bab504e81f1b62bff7dd335022f4495e8fba3.zip
Merge branch 'rust-lang:master' into master
-rw-r--r--crates/ide-assists/src/handlers/extract_function.rs36
-rw-r--r--docs/user/manual.adoc3
2 files changed, 33 insertions, 6 deletions
diff --git a/crates/ide-assists/src/handlers/extract_function.rs b/crates/ide-assists/src/handlers/extract_function.rs
index 2a67909e637..e9db38aca0f 100644
--- a/crates/ide-assists/src/handlers/extract_function.rs
+++ b/crates/ide-assists/src/handlers/extract_function.rs
@@ -1360,14 +1360,15 @@ fn make_call(ctx: &AssistContext<'_>, fun: &Function, indent: IndentLevel) -> St
     }
 
     format_to!(buf, "{expr}");
-    let insert_comma = fun
-        .body
-        .parent()
-        .and_then(ast::MatchArm::cast)
-        .map_or(false, |it| it.comma_token().is_none());
+    let parent_match_arm = fun.body.parent().and_then(ast::MatchArm::cast);
+    let insert_comma = parent_match_arm.as_ref().is_some_and(|it| it.comma_token().is_none());
+
     if insert_comma {
         buf.push(',');
-    } else if fun.ret_ty.is_unit() && (!fun.outliving_locals.is_empty() || !expr.is_block_like()) {
+    } else if parent_match_arm.is_none()
+        && fun.ret_ty.is_unit()
+        && (!fun.outliving_locals.is_empty() || !expr.is_block_like())
+    {
         buf.push(';');
     }
     buf
@@ -4611,6 +4612,29 @@ fn $0fun_name() -> i32 {
 }
 "#,
         );
+
+        // Makes sure no semicolon is added for unit-valued match arms
+        check_assist(
+            extract_function,
+            r#"
+fn main() {
+    match () {
+        _ => $0()$0,
+    }
+}
+"#,
+            r#"
+fn main() {
+    match () {
+        _ => fun_name(),
+    }
+}
+
+fn $0fun_name() {
+    ()
+}
+"#,
+        )
     }
 
     #[test]
diff --git a/docs/user/manual.adoc b/docs/user/manual.adoc
index bd924031e03..b23c7c35d5d 100644
--- a/docs/user/manual.adoc
+++ b/docs/user/manual.adoc
@@ -141,6 +141,9 @@ If you're not using Code, you can compile and install only the LSP server:
 $ cargo xtask install --server
 ----
 
+Make sure that `.cargo/bin` is in `$PATH` and precedes paths where `rust-analyzer` may also be installed.
+Specifically, `rustup` includes a proxy called `rust-analyzer`, which can cause problems if you're planning to use a source build or even a downloaded binary.
+
 === rust-analyzer Language Server Binary
 
 Other editors generally require the `rust-analyzer` binary to be in `$PATH`.