-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Remove negative integer literal checks. #3677
Conversation
clippy_lints/src/arithmetic.rs
Outdated
@@ -92,11 +92,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Arithmetic { | |||
} | |||
}, | |||
hir::ExprKind::Unary(hir::UnOp::UnNeg, arg) => { | |||
let ty = cx.tables.expr_ty(arg); | |||
if ty.is_integral() { |
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.
Instead of removing the lint entirely, I think we should only skip reporting it if arg
is a constant. You can use clippy's const folder to check if it's a constant. If it is, don't report the lint. That should cause -1
and -(-1)
to stop linting, but -i
and -(-i)
not.
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.
if constant_simple(cx, cx.tables, expr).is_none() { |
Not sure if that is what you meant, but it seems to work.
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.
jup, exactly what I had in mind
@bors r+ |
📌 Commit 87d24e1 has been approved by |
Remove negative integer literal checks. Fixes #3678.
☀️ Test successful - checks-travis, status-appveyor |
Fixes #3678.