Skip to content

Commit bf0c5d6

Browse files
committed
Fix unused_parens false positive
1 parent 6b3ae3f commit bf0c5d6

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

compiler/rustc_lint/src/unused.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1055,6 +1055,7 @@ pub(crate) struct UnusedParens {
10551055
/// ```
10561056
/// type Example = Box<dyn Fn() -> &'static dyn Send>;
10571057
/// ```
1058+
#[derive(Copy, Clone)]
10581059
enum NoBoundsException {
10591060
/// The type must be parenthesized.
10601061
None,
@@ -1333,7 +1334,11 @@ impl EarlyLintPass for UnusedParens {
13331334
self.with_self_ty_parens = false;
13341335
}
13351336
ast::TyKind::Ref(_, mut_ty) | ast::TyKind::Ptr(mut_ty) => {
1336-
self.in_no_bounds_pos.insert(mut_ty.ty.id, NoBoundsException::OneBound);
1337+
// If this type itself appears in no-bounds position, we propagate its
1338+
// potentially tighter constraint or risk a false posive (issue 143653).
1339+
let own_constraint = self.in_no_bounds_pos.get(&ty.id).copied();
1340+
let constraint = own_constraint.unwrap_or(NoBoundsException::OneBound);
1341+
self.in_no_bounds_pos.insert(mut_ty.ty.id, constraint);
13371342
}
13381343
ast::TyKind::TraitObject(bounds, _) | ast::TyKind::ImplTrait(_, bounds) => {
13391344
for i in 0..bounds.len() {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//@ check-pass
2+
3+
#![deny(unused_parens)]
4+
#![allow(warnings)]
5+
trait MyTrait {}
6+
7+
fn foo(_: Box<dyn FnMut(&mut u32) -> &mut (dyn MyTrait) + Send + Sync>) {}
8+
9+
fn main() {}

0 commit comments

Comments
 (0)