Skip to content

Remove parenthesis should ensure space #15844

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
omertuc opened this issue Nov 7, 2023 · 1 comment · Fixed by #15857
Closed

Remove parenthesis should ensure space #15844

omertuc opened this issue Nov 7, 2023 · 1 comment · Fixed by #15857
Assignees
Labels
A-assists C-bug Category: bug

Comments

@omertuc
Copy link
Contributor

omertuc commented Nov 7, 2023

rust-analyzer version: rust-analyzer 1.73.0 (cc66ad4 2023-10-03)

rustc version: rustc 1.73.0 (cc66ad468 2023-10-03)

relevant settings: n/a

Input

fn f() {
    match$0(true) {}
}

Expected output

fn f() {
    match true {}
}

Output

fn f() {
    matchtrue {}
}

Notes

Looks like the code assist that rust-analyzer generates from the compiler warning ("remove these parentheses") does handle this case correctly, so it's maybe it's possible to take notes from the compiler implementation

Test Patch

diff --git a/crates/ide-assists/src/handlers/remove_parentheses.rs b/crates/ide-assists/src/handlers/remove_parentheses.rs
index ffc32f804..f93e8ecbb 100644
--- a/crates/ide-assists/src/handlers/remove_parentheses.rs
+++ b/crates/ide-assists/src/handlers/remove_parentheses.rs
@@ -218,4 +218,13 @@ mod tests {
 
         check_assist_not_applicable(remove_parentheses, r#"fn f() { $0(return 2) + 2 }"#);
     }
+
+    #[test]
+    fn remove_parens_space() {
+        check_assist(
+            remove_parentheses,
+            r#"fn f() { match$0(true) {} }"#,
+            r#"fn f() { match$0 true {} }"#,
+        );
+    }
 }
@Young-Flash
Copy link
Member

@rustbot claim

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-assists C-bug Category: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants