-
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
Linting classical overflow checks #741
Conversation
@martiansideofthemoon Update your nightly |
71c041e
to
348e3d2
Compare
@@ -283,6 +285,7 @@ pub fn plugin_registrar(reg: &mut Registry) { | |||
needless_update::NEEDLESS_UPDATE, | |||
no_effect::NO_EFFECT, | |||
open_options::NONSENSICAL_OPEN_OPTIONS, | |||
overflow_check_conditional::OVERFLOW_CHECK_CONDTIONAL, |
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.
You’re missing an i
here
348e3d2
to
7fed35e
Compare
|
||
/// **What it does:** This lint finds classic overflow checks. | ||
/// | ||
/// **Why is this bad?** Most classic overflow checks would cause the compiler to panic. |
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.
I would reformulate that to insist on the fact that while those are classic in C, they won’t work in Rust. Also point out that Rust does not need them because of the overflowing_*
and wrapping_*
family of functions.
f7f62a2
to
9e0bf22
Compare
@Manishearth , @mcarton I hope it's okay 😄 |
|
||
/// **What it does:** This lint finds classic overflow checks. | ||
/// | ||
/// **Why is this bad?** Most classic C overflow checks will fail in Rust. Users can use functions like overflowing_* and wrapping_* instead. |
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.
Can you put overflowing_*
and wrapping_*
between quotes? Looks better on the wiki.
`overflowing_*` and `wrapping_*`
You need to run |
9e0bf22
to
55fbf59
Compare
For bonus points, you could also lint underflow checks, e.g |
@llogiq I hope it's okay 😄 |
Bonus points for you! 😄 My only small nit is that the lint docs could tell that we lint over- and underflow checks. Also perhaps one could unify some parts into a function to avoid duplication, but I'm fine with merging as it is. |
As discussed on IRC, don’t merge the PR yet. He‘ll also handle |
Even better, although those forms are much less common IIRC. |
@Manishearth , @llogiq , @mcarton I hope it is alright |
3ab5117
to
05643f3
Compare
Unfortunately, it fails the cyclomatic_complexity check. You could factor out some common expressions of both check blocks. |
I've looked at the code, it shouldn't trigger cc, I'll investigate, just throw an |
@oli-obk alright, thanks I'll do it in a bit 😄 |
05643f3
to
9faffd2
Compare
Linting classical overflow checks
Thanks! Good work 👍 |
@Manishearth , @mcarton getting a compile error in
cyclomatic_complexity.rs
as follows :- https://pastebin.mozilla.org/8862490Fix #656.