about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorTrevor Gross <t.gross35@gmail.com>2024-10-11 23:57:46 -0400
committerGitHub <noreply@github.com>2024-10-11 23:57:46 -0400
commitfcbf4ac6f9071baa2a48799d697cbf74f81f30e1 (patch)
tree91c5555fc6077be0b7eca1ab2fa87ec8f85ea6db /tests
parent9e72070f77b0d5a71dca91f359b599bab150e3e5 (diff)
parent1e8d6d1ec3cad6bc7d88c0a8a993f69835e8422f (diff)
downloadrust-fcbf4ac6f9071baa2a48799d697cbf74f81f30e1.tar.gz
rust-fcbf4ac6f9071baa2a48799d697cbf74f81f30e1.zip
Rollup merge of #131546 - surechen:fix_129833, r=jieyouxu
Make unused_parens's suggestion considering expr's attributes.

For the expr with attributes,
like `let _ = (#[inline] || println!("Hello!"));`,
the suggestion's span should contains the attributes, or the suggestion will remove them.

fixes #129833
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/lint/unused/unused-parens-for-stmt-expr-attributes-issue-129833.fixed15
-rw-r--r--tests/ui/lint/unused/unused-parens-for-stmt-expr-attributes-issue-129833.rs15
-rw-r--r--tests/ui/lint/unused/unused-parens-for-stmt-expr-attributes-issue-129833.stderr31
3 files changed, 61 insertions, 0 deletions
diff --git a/tests/ui/lint/unused/unused-parens-for-stmt-expr-attributes-issue-129833.fixed b/tests/ui/lint/unused/unused-parens-for-stmt-expr-attributes-issue-129833.fixed
new file mode 100644
index 00000000000..8287b3d3ac7
--- /dev/null
+++ b/tests/ui/lint/unused/unused-parens-for-stmt-expr-attributes-issue-129833.fixed
@@ -0,0 +1,15 @@
+//@ run-rustfix
+// Check the `unused_parens` suggestion for paren_expr with attributes.
+// The suggestion should retain attributes in the front.
+
+#![feature(stmt_expr_attributes)]
+#![deny(unused_parens)]
+
+pub fn foo() -> impl Fn() {
+    let _ = #[inline] #[allow(dead_code)] || println!("Hello!"); //~ERROR unnecessary parentheses
+    #[inline] #[allow(dead_code)] || println!("Hello!") //~ERROR unnecessary parentheses
+}
+
+fn main() {
+    let _ = foo();
+}
diff --git a/tests/ui/lint/unused/unused-parens-for-stmt-expr-attributes-issue-129833.rs b/tests/ui/lint/unused/unused-parens-for-stmt-expr-attributes-issue-129833.rs
new file mode 100644
index 00000000000..0b6edae30e7
--- /dev/null
+++ b/tests/ui/lint/unused/unused-parens-for-stmt-expr-attributes-issue-129833.rs
@@ -0,0 +1,15 @@
+//@ run-rustfix
+// Check the `unused_parens` suggestion for paren_expr with attributes.
+// The suggestion should retain attributes in the front.
+
+#![feature(stmt_expr_attributes)]
+#![deny(unused_parens)]
+
+pub fn foo() -> impl Fn() {
+    let _ = (#[inline] #[allow(dead_code)] || println!("Hello!")); //~ERROR unnecessary parentheses
+    (#[inline] #[allow(dead_code)] || println!("Hello!")) //~ERROR unnecessary parentheses
+}
+
+fn main() {
+    let _ = foo();
+}
diff --git a/tests/ui/lint/unused/unused-parens-for-stmt-expr-attributes-issue-129833.stderr b/tests/ui/lint/unused/unused-parens-for-stmt-expr-attributes-issue-129833.stderr
new file mode 100644
index 00000000000..65513553f7e
--- /dev/null
+++ b/tests/ui/lint/unused/unused-parens-for-stmt-expr-attributes-issue-129833.stderr
@@ -0,0 +1,31 @@
+error: unnecessary parentheses around assigned value
+  --> $DIR/unused-parens-for-stmt-expr-attributes-issue-129833.rs:9:13
+   |
+LL |     let _ = (#[inline] #[allow(dead_code)] || println!("Hello!"));
+   |             ^                                                   ^
+   |
+note: the lint level is defined here
+  --> $DIR/unused-parens-for-stmt-expr-attributes-issue-129833.rs:6:9
+   |
+LL | #![deny(unused_parens)]
+   |         ^^^^^^^^^^^^^
+help: remove these parentheses
+   |
+LL -     let _ = (#[inline] #[allow(dead_code)] || println!("Hello!"));
+LL +     let _ = #[inline] #[allow(dead_code)] || println!("Hello!");
+   |
+
+error: unnecessary parentheses around block return value
+  --> $DIR/unused-parens-for-stmt-expr-attributes-issue-129833.rs:10:5
+   |
+LL |     (#[inline] #[allow(dead_code)] || println!("Hello!"))
+   |     ^                                                   ^
+   |
+help: remove these parentheses
+   |
+LL -     (#[inline] #[allow(dead_code)] || println!("Hello!"))
+LL +     #[inline] #[allow(dead_code)] || println!("Hello!")
+   |
+
+error: aborting due to 2 previous errors
+