-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Fix false positive for unused_unit #14962
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@@ -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() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps this should have been covered by !hir_ty.span.from_expansion()
. Certainly, there are no explicit -> ()
tokens in the source. If this is the case, I'm happy to close this PR and file an issue upstream.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those expansion checks are quite finicky; sometimes you have an expression without expansion but a subexpression expanded, etc. So as long as this appears to fix the issue, it's better than nothing.
|
||
mod pr14962 { | ||
#[allow(unused_parens)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is a targeted lint, could you please use #[expect(unused_parens)]
instead? That doubles as an extra free test for unused_parens
that would force us to think about it if its behavior changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not actually emit a warning by rustc yet. I'm currently looking into why that is exactly. I can remove the attribute and change the name of the type alias if you want.
Thank you. |
Given a type alias as follows, clippy would detect a false positive for
unused_unit
.changelog: [
unused_unit
]: fix false positive forFn
bounds