about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorTrevor Gross <t.gross35@gmail.com>2025-07-26 02:19:28 -0500
committerGitHub <noreply@github.com>2025-07-26 02:19:28 -0500
commit75ed6de1eef96753da3497c0f6e2623cc86fc240 (patch)
tree112eeae2e4786e6b8d347a02e7faf997f71147cd /tests
parentd8f4ceb8c07fd00df40903dbb2ba29c69efdaf00 (diff)
parent307f66436b602697c8f1c49d8f455ec60a176166 (diff)
downloadrust-75ed6de1eef96753da3497c0f6e2623cc86fc240.tar.gz
rust-75ed6de1eef96753da3497c0f6e2623cc86fc240.zip
Rollup merge of #143698 - benschulz:unused-parens-2, r=lcnr,compiler-errors
Fix unused_parens false positive

Resolves rust-lang/rust#143653.

The "no bounds exception" was indiscriminately set to `OneBound` for referents and pointees. However, if the reference or pointer type itself appears in no-bounds position, any constraints it has must be propagated.

```rust
// unused parens: not in no-bounds position
fn foo(_: Box<(dyn Send)>) {}

// unused parens: in no-bounds position, but one-bound exception applies
fn bar(_: Box<dyn Fn(&u32) -> &(dyn Send)>) {}

// *NOT* unused parens: in no-bounds position, but no exceptions to be made
fn baz(_: Box<dyn Fn(&u32) -> &(dyn Send) + Send>) {}
```
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/lint/unused/unused-parens-false-positive-issue-143653.fixed12
-rw-r--r--tests/ui/lint/unused/unused-parens-false-positive-issue-143653.rs12
-rw-r--r--tests/ui/lint/unused/unused-parens-false-positive-issue-143653.stderr19
3 files changed, 43 insertions, 0 deletions
diff --git a/tests/ui/lint/unused/unused-parens-false-positive-issue-143653.fixed b/tests/ui/lint/unused/unused-parens-false-positive-issue-143653.fixed
new file mode 100644
index 00000000000..4b0bca3d44a
--- /dev/null
+++ b/tests/ui/lint/unused/unused-parens-false-positive-issue-143653.fixed
@@ -0,0 +1,12 @@
+//@ run-rustfix
+
+#![deny(unused_parens)]
+#![allow(warnings)]
+trait MyTrait {}
+
+fn foo(_: Box<dyn FnMut(&mut u32) -> &mut (dyn MyTrait) + Send + Sync>) {}
+
+//~v ERROR unnecessary parentheses around type
+fn bar(_: Box<dyn FnMut(&mut u32) -> &mut dyn MyTrait>) {}
+
+fn main() {}
diff --git a/tests/ui/lint/unused/unused-parens-false-positive-issue-143653.rs b/tests/ui/lint/unused/unused-parens-false-positive-issue-143653.rs
new file mode 100644
index 00000000000..4eefd3dc81a
--- /dev/null
+++ b/tests/ui/lint/unused/unused-parens-false-positive-issue-143653.rs
@@ -0,0 +1,12 @@
+//@ run-rustfix
+
+#![deny(unused_parens)]
+#![allow(warnings)]
+trait MyTrait {}
+
+fn foo(_: Box<dyn FnMut(&mut u32) -> &mut (dyn MyTrait) + Send + Sync>) {}
+
+//~v ERROR unnecessary parentheses around type
+fn bar(_: Box<dyn FnMut(&mut u32) -> &mut (dyn MyTrait)>) {}
+
+fn main() {}
diff --git a/tests/ui/lint/unused/unused-parens-false-positive-issue-143653.stderr b/tests/ui/lint/unused/unused-parens-false-positive-issue-143653.stderr
new file mode 100644
index 00000000000..89455e3db73
--- /dev/null
+++ b/tests/ui/lint/unused/unused-parens-false-positive-issue-143653.stderr
@@ -0,0 +1,19 @@
+error: unnecessary parentheses around type
+  --> $DIR/unused-parens-false-positive-issue-143653.rs:10:43
+   |
+LL | fn bar(_: Box<dyn FnMut(&mut u32) -> &mut (dyn MyTrait)>) {}
+   |                                           ^           ^
+   |
+note: the lint level is defined here
+  --> $DIR/unused-parens-false-positive-issue-143653.rs:3:9
+   |
+LL | #![deny(unused_parens)]
+   |         ^^^^^^^^^^^^^
+help: remove these parentheses
+   |
+LL - fn bar(_: Box<dyn FnMut(&mut u32) -> &mut (dyn MyTrait)>) {}
+LL + fn bar(_: Box<dyn FnMut(&mut u32) -> &mut dyn MyTrait>) {}
+   |
+
+error: aborting due to 1 previous error
+