Skip to content

Commit 6bb0c97

Browse files
authored
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
2 parents da93448 + 1e96456 commit 6bb0c97

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

clippy_lints/src/unused_unit.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedUnit {
109109
&& let AssocItemConstraintKind::Equality { term: Term::Ty(hir_ty) } = constraints[0].kind
110110
&& args.span_ext.hi() != poly.span.hi()
111111
&& !hir_ty.span.from_expansion()
112+
&& args.span_ext.hi() != hir_ty.span.hi()
112113
&& is_unit_ty(hir_ty)
113114
{
114115
lint_unneeded_unit_return(cx, hir_ty.span, poly.span);

tests/ui/unused_unit.edition2021.fixed

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,4 +143,10 @@ mod issue14577 {
143143
todo!()
144144
}
145145
}
146-
}
146+
}
147+
148+
mod pr14962 {
149+
#[allow(unused_parens)]
150+
type UnusedParensButNoUnit = Box<dyn (Fn())>;
151+
}
152+

tests/ui/unused_unit.edition2024.fixed

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,4 +143,10 @@ mod issue14577 {
143143
todo!()
144144
}
145145
}
146-
}
146+
}
147+
148+
mod pr14962 {
149+
#[allow(unused_parens)]
150+
type UnusedParensButNoUnit = Box<dyn (Fn())>;
151+
}
152+

tests/ui/unused_unit.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,4 +143,10 @@ mod issue14577 {
143143
todo!()
144144
}
145145
}
146-
}
146+
}
147+
148+
mod pr14962 {
149+
#[allow(unused_parens)]
150+
type UnusedParensButNoUnit = Box<dyn (Fn())>;
151+
}
152+

0 commit comments

Comments
 (0)