diff options
| author | llogiq <bogusandre@gmail.com> | 2025-06-05 19:44:04 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-06-05 19:44:04 +0000 |
| commit | 6bb0c97409cbfac7ec6f49f9aec3d35a5ae35122 (patch) | |
| tree | 968aeae36c3ea8cc497f10a54c65cede49bd0afe | |
| parent | da93448c9875e40b252c794d4b08a28fe3cbeb65 (diff) | |
| parent | 1e96456b84bd22dd5140dd4feb9108fc87e17da9 (diff) | |
| download | rust-6bb0c97409cbfac7ec6f49f9aec3d35a5ae35122.tar.gz rust-6bb0c97409cbfac7ec6f49f9aec3d35a5ae35122.zip | |
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
| -rw-r--r-- | clippy_lints/src/unused_unit.rs | 1 | ||||
| -rw-r--r-- | tests/ui/unused_unit.edition2021.fixed | 8 | ||||
| -rw-r--r-- | tests/ui/unused_unit.edition2024.fixed | 8 | ||||
| -rw-r--r-- | tests/ui/unused_unit.rs | 8 |
4 files changed, 22 insertions, 3 deletions
diff --git a/clippy_lints/src/unused_unit.rs b/clippy_lints/src/unused_unit.rs index 2abcdf5d0d4..3811f0fe6b5 100644 --- a/clippy_lints/src/unused_unit.rs +++ b/clippy_lints/src/unused_unit.rs @@ -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); diff --git a/tests/ui/unused_unit.edition2021.fixed b/tests/ui/unused_unit.edition2021.fixed index 93dd58b8e9d..def8ef86e3c 100644 --- a/tests/ui/unused_unit.edition2021.fixed +++ b/tests/ui/unused_unit.edition2021.fixed @@ -143,4 +143,10 @@ mod issue14577 { todo!() } } -} \ No newline at end of file +} + +mod pr14962 { + #[allow(unused_parens)] + type UnusedParensButNoUnit = Box<dyn (Fn())>; +} + diff --git a/tests/ui/unused_unit.edition2024.fixed b/tests/ui/unused_unit.edition2024.fixed index 987d901b97d..f908b958b19 100644 --- a/tests/ui/unused_unit.edition2024.fixed +++ b/tests/ui/unused_unit.edition2024.fixed @@ -143,4 +143,10 @@ mod issue14577 { todo!() } } -} \ No newline at end of file +} + +mod pr14962 { + #[allow(unused_parens)] + type UnusedParensButNoUnit = Box<dyn (Fn())>; +} + diff --git a/tests/ui/unused_unit.rs b/tests/ui/unused_unit.rs index b7645f7b6a2..7298ec40cc2 100644 --- a/tests/ui/unused_unit.rs +++ b/tests/ui/unused_unit.rs @@ -143,4 +143,10 @@ mod issue14577 { todo!() } } -} \ No newline at end of file +} + +mod pr14962 { + #[allow(unused_parens)] + type UnusedParensButNoUnit = Box<dyn (Fn())>; +} + |
