diff options
| author | Trevor Gross <t.gross35@gmail.com> | 2025-07-26 02:19:28 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-26 02:19:28 -0500 |
| commit | 75ed6de1eef96753da3497c0f6e2623cc86fc240 (patch) | |
| tree | 112eeae2e4786e6b8d347a02e7faf997f71147cd /compiler/rustc_lint/src | |
| parent | d8f4ceb8c07fd00df40903dbb2ba29c69efdaf00 (diff) | |
| parent | 307f66436b602697c8f1c49d8f455ec60a176166 (diff) | |
| download | rust-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 'compiler/rustc_lint/src')
| -rw-r--r-- | compiler/rustc_lint/src/unused.rs | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/compiler/rustc_lint/src/unused.rs b/compiler/rustc_lint/src/unused.rs index a9eb1739f7f..df9f3a500d9 100644 --- a/compiler/rustc_lint/src/unused.rs +++ b/compiler/rustc_lint/src/unused.rs @@ -1340,7 +1340,15 @@ impl EarlyLintPass for UnusedParens { self.with_self_ty_parens = false; } ast::TyKind::Ref(_, mut_ty) | ast::TyKind::Ptr(mut_ty) => { - self.in_no_bounds_pos.insert(mut_ty.ty.id, NoBoundsException::OneBound); + // If this type itself appears in no-bounds position, we propagate its + // potentially tighter constraint or risk a false posive (issue 143653). + let own_constraint = self.in_no_bounds_pos.get(&ty.id); + let constraint = match own_constraint { + Some(NoBoundsException::None) => NoBoundsException::None, + Some(NoBoundsException::OneBound) => NoBoundsException::OneBound, + None => NoBoundsException::OneBound, + }; + self.in_no_bounds_pos.insert(mut_ty.ty.id, constraint); } ast::TyKind::TraitObject(bounds, _) | ast::TyKind::ImplTrait(_, bounds) => { for i in 0..bounds.len() { |
