-
Notifications
You must be signed in to change notification settings - Fork 34
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
Massive amounts of clippy
warnings
#99
Comments
It's a fair issue and happy for discussion on it, but do understand this was written as a direct translation of the C reference code for inspection and correctness. The issue for more idiomatic rust is #68, and even that is still missing improvements like It's certainly personal preference but lints like these: r[idx + 0] = (t[0] >> 0) as u8;
^^^^^^^^^^^ help: consider reducing it to: `t[0]` For me makes it clearer about the repeated operations in code and simpler to grok for anyone looking at the code. It's also how it's written by the Kyber team. Yes you can remove the bitshift and addition to appease clippy at the tradeoff of readability in a sea of complexity.
They are lints, not errors. Using You could submit a PR on individual lint basis and we'll go from there? Unnecessary borrowing is certainly fine, other things like conversion semantics will be different and requires more attention. I won't get your hopes up here, it likely won't get down to zero but we can reduce it. |
So I'd really like to clean up what we can and get a Example: warning: the loop variable `i` is used to index `a`
--> src/reference/indcpa.rs:140:14
|
140 | for i in 0..KYBER_K {
| ^^^^^^^^^^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_range_loop
Cool, except if transposed {
xof_absorb(&mut state, seed, i as u8, j as u8); I guess they want Still keen to get this worked out, might need a few exemptions in the file while these sorts of bugs/perhaps intentional style things exist. Related: |
FWIW we often disable the #![allow(clippy::needless_range_loop)] Indeed it can be unhelpful at times where its suggestions don't improve code clarity. |
There's a few allows in modules already that should probably be removed, a repo-wide clippy.toml file seems like the best way forward. |
If you place the above attribute in lib.rs, it will apply to the whole crate. I wasn't aware clippy.toml could be used for this purpose. If so that's a semi-recent addition (last I checked, they explicitly decided against that?) |
Perhaps, yet as far as I see it using a config file is still how they present it in the docs? https://github.com/rust-lang/rust-clippy#configure-the-behavior-of-some-lints Clippy tends to attract the natural urge of bikeshedding which is fine but in the end code quality is what matters most, this always takes precedence. Personally prefer 2 space indentation but gave into doing to things the |
AFAIK, only some lints can be configured/set this way. I do still believe you need to declare the vast majority of them in your root |
Haven't actually checked but this is due to many lints needing nightly to run I think? For instance if you want 2 space indentation then you need to run Edit: sorry I'm conflating fmt with clippy |
Quite a lot of lints are experimental/nightly only/unstable. I'd use the dedicated |
I'd argue |
After running:
I get a total of 547 errors, many of which could be pretty bad (I use even harsher lints in my
lib.rs
, there's a lot of warnings). Even with justcargo clippy --features=90s-fixslice
I get 45 warnings.I do also understand that these are some pretty harsh lints, and the lints I personally use in my work are even harsher, but I can't begin to imagine the amount of subtle bugs/performance issues they've solved - and my code is a lot more idiomatic.
The majority of the issues stem from needless borrowing or redundant slicing, but
as_conversions
are probably something to keep an eye on, as well as possible truncations.I've forked the repo and started cleaning it up and making things more safe, but sadly I removed a lot of the functionality present here as it's not requried for our needs, otherwise I would've contributed my changes. I spent a few hours and got down to 140~ errors, most of which are now just
as_conversions
, which I'll still be fixing and making safe as I've had an issue with anas x
conversion before that took far too long to debug, so now I useFrom
/Into
or their fallible counterparts.This evidently isn't a major issue, so feel free to close it, I just wanted to bring attention to it as
clippy
is great at catching subtle mistakes. It could be good to add into CI too.The text was updated successfully, but these errors were encountered: