Skip to content

Commit e958b20

Browse files
committed
Fix unused_parens false positive
1 parent 5d22242 commit e958b20

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
@@ -1062,6 +1062,7 @@ pub(crate) struct UnusedParens {
10621062
/// ```
10631063
/// type Example = Box<dyn Fn() -> &'static dyn Send>;
10641064
/// ```
1065+
#[derive(Copy, Clone)]
10651066
enum NoBoundsException {
10661067
/// The type must be parenthesized.
10671068
None,
@@ -1340,7 +1341,11 @@ impl EarlyLintPass for UnusedParens {
13401341
self.with_self_ty_parens = false;
13411342
}
13421343
ast::TyKind::Ref(_, mut_ty) | ast::TyKind::Ptr(mut_ty) => {
1343-
self.in_no_bounds_pos.insert(mut_ty.ty.id, NoBoundsException::OneBound);
1344+
// If this type itself appears in no-bounds position, we propagate its
1345+
// potentially tighter constraint or risk a false posive (issue 143653).
1346+
let own_constraint = self.in_no_bounds_pos.get(&ty.id).copied();
1347+
let constraint = own_constraint.unwrap_or(NoBoundsException::OneBound);
1348+
self.in_no_bounds_pos.insert(mut_ty.ty.id, constraint);
13441349
}
13451350
ast::TyKind::TraitObject(bounds, _) | ast::TyKind::ImplTrait(_, bounds) => {
13461351
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)