-
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
new restriction lint: integer_division_remainder_used
#12451
Conversation
r? @Manishearth rustbot has assigned @Manishearth. Use r? to explicitly pick a reviewer |
@tarcieri The example I included is extremely basic and not necessarily relevant to the lint itself; however, I'm no cryptography expert and found the example you provided in the original issue to be a bit long and specific (and also uses someone else's code). If you can think of a better (ideally short) example than |
☔ The latest upstream changes (presumably #12440) made this pull request unmergeable. Please resolve the merge conflicts. |
declare_clippy_lint! { | ||
/// ### What it does | ||
/// Checks for the usage of division (/) and remainder (%) operations | ||
/// when performed on any integer types using the default Div and Rem trait implementaions. |
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.
/// when performed on any integer types using the default Div and Rem trait implementaions. | |
/// when performed on any integer types using the default Div and Rem trait implementations. |
r? rust-lang/clippy still a bit busy, redirecting reviews |
/// let my_div = 10 >> 1; | ||
/// ``` | ||
#[clippy::version = "1.78.0"] | ||
pub DIVISION_REMAINDER_USED, |
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.
nit: INTEGER_DIVISION_REMAINDER_USED
@Jacherr the specific example doesn't really matter as long as it covers usages of division / remainder. I just picked a real-world one to illustrate what the problem looked like in the wild and how it was fixed. |
division_remainder_used
integer_division_remainder_used
Thank you! @bors r+ |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
A bit late, but we noticed there should potentially be an exception to this for operations which are exclusively on constants and/or which are statically known to always be in a It's fine as-is, but operations which are only on constants would be considered a false positive for cryptographic purposes. I can open a separate issue for that if it's helpful. |
Fixes #12391
Introduces a restriction lint which disallows the use of
/
and%
operators on anyInt
orUint
types (i.e., any that use the defaultDiv
orRem
trait implementations). Custom implementations of these traits are ignored.changelog: Add new restriction lint [
integer_division_remainder_used
]