Fix false positive for unused_unit (#14962)

Given a type alias as follows, clippy would detect a false positive for
`unused_unit`.

```rust
type UnusedParensButNoUnit = Box<dyn (Fn())>;
```

changelog: [`unused_unit`]: fix false positive for `Fn` bounds
This commit is contained in:
llogiq 2025-06-05 19:44:04 +00:00 committed by GitHub
commit 6bb0c97409
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 22 additions and 3 deletions

View file

@ -109,6 +109,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedUnit {
&& let AssocItemConstraintKind::Equality { term: Term::Ty(hir_ty) } = constraints[0].kind
&& args.span_ext.hi() != poly.span.hi()
&& !hir_ty.span.from_expansion()
&& args.span_ext.hi() != hir_ty.span.hi()
&& is_unit_ty(hir_ty)
{
lint_unneeded_unit_return(cx, hir_ty.span, poly.span);

View file

@ -143,4 +143,10 @@ mod issue14577 {
todo!()
}
}
}
}
mod pr14962 {
#[allow(unused_parens)]
type UnusedParensButNoUnit = Box<dyn (Fn())>;
}

View file

@ -143,4 +143,10 @@ mod issue14577 {
todo!()
}
}
}
}
mod pr14962 {
#[allow(unused_parens)]
type UnusedParensButNoUnit = Box<dyn (Fn())>;
}

View file

@ -143,4 +143,10 @@ mod issue14577 {
todo!()
}
}
}
}
mod pr14962 {
#[allow(unused_parens)]
type UnusedParensButNoUnit = Box<dyn (Fn())>;
}