about summary refs log tree commit diff
path: root/tests/ui/lint
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2025-09-16 18:43:49 +0000
committerbors <bors@rust-lang.org>2025-09-16 18:43:49 +0000
commita9d0a6f15533a364816c4d81e2192009ef601d33 (patch)
tree37aad937b063deadab2f8703c90aaaa8f3658511 /tests/ui/lint
parenteec6bd9d69832f57341c6de6a93fa7b9f47e2111 (diff)
parent9991ec282f3ff08c895e4a5262259139fe689953 (diff)
downloadrust-a9d0a6f15533a364816c4d81e2192009ef601d33.tar.gz
rust-a9d0a6f15533a364816c4d81e2192009ef601d33.zip
Auto merge of #138271 - mu001999-contrib:fix-138234, r=jackh726
Keep space if arg does not follow punctuation when lint unused parens

Fixes rust-lang/rust#138234

If the arg follows punctuation, still pass `left_pos` with `None` and no space will be added, else then pass `left_pos` with `Some(arg.span.lo())`, so that we can add the space as expected.

And `emit_unused_delims` can make sure no more space will be added if the expr follows space.

---

Edited:

Directly use the `value_span` to check whether the expr removed parens will follow identifier or be followed by identifier.
Diffstat (limited to 'tests/ui/lint')
-rw-r--r--tests/ui/lint/unused_parens_follow_ident.fixed17
-rw-r--r--tests/ui/lint/unused_parens_follow_ident.rs17
-rw-r--r--tests/ui/lint/unused_parens_follow_ident.stderr31
3 files changed, 65 insertions, 0 deletions
diff --git a/tests/ui/lint/unused_parens_follow_ident.fixed b/tests/ui/lint/unused_parens_follow_ident.fixed
new file mode 100644
index 00000000000..e61b287e5a6
--- /dev/null
+++ b/tests/ui/lint/unused_parens_follow_ident.fixed
@@ -0,0 +1,17 @@
+//@ run-rustfix
+
+#![deny(unused_parens)]
+
+macro_rules! wrap {
+    ($name:ident $arg:expr) => {
+        $name($arg);
+    };
+}
+
+fn main() {
+    wrap!(unary routine()); //~ ERROR unnecessary parentheses around function argument
+    wrap!(unary routine()); //~ ERROR unnecessary parentheses around function argument
+}
+
+fn unary(_: ()) {}
+fn routine() {}
diff --git a/tests/ui/lint/unused_parens_follow_ident.rs b/tests/ui/lint/unused_parens_follow_ident.rs
new file mode 100644
index 00000000000..32a163345b2
--- /dev/null
+++ b/tests/ui/lint/unused_parens_follow_ident.rs
@@ -0,0 +1,17 @@
+//@ run-rustfix
+
+#![deny(unused_parens)]
+
+macro_rules! wrap {
+    ($name:ident $arg:expr) => {
+        $name($arg);
+    };
+}
+
+fn main() {
+    wrap!(unary(routine())); //~ ERROR unnecessary parentheses around function argument
+    wrap!(unary (routine())); //~ ERROR unnecessary parentheses around function argument
+}
+
+fn unary(_: ()) {}
+fn routine() {}
diff --git a/tests/ui/lint/unused_parens_follow_ident.stderr b/tests/ui/lint/unused_parens_follow_ident.stderr
new file mode 100644
index 00000000000..ce7bb26778c
--- /dev/null
+++ b/tests/ui/lint/unused_parens_follow_ident.stderr
@@ -0,0 +1,31 @@
+error: unnecessary parentheses around function argument
+  --> $DIR/unused_parens_follow_ident.rs:12:16
+   |
+LL |     wrap!(unary(routine()));
+   |                ^         ^
+   |
+note: the lint level is defined here
+  --> $DIR/unused_parens_follow_ident.rs:3:9
+   |
+LL | #![deny(unused_parens)]
+   |         ^^^^^^^^^^^^^
+help: remove these parentheses
+   |
+LL -     wrap!(unary(routine()));
+LL +     wrap!(unary routine());
+   |
+
+error: unnecessary parentheses around function argument
+  --> $DIR/unused_parens_follow_ident.rs:13:17
+   |
+LL |     wrap!(unary (routine()));
+   |                 ^         ^
+   |
+help: remove these parentheses
+   |
+LL -     wrap!(unary (routine()));
+LL +     wrap!(unary routine());
+   |
+
+error: aborting due to 2 previous errors
+