-
Notifications
You must be signed in to change notification settings - Fork 151
Cargo.toml: add workspace-level clippy config #1399
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
base: master
Are you sure you want to change the base?
Conversation
e8b32f8 to
41aa651
Compare
|
Oh fun, this seems to be incompatible with the |
|
Not sure what's happening here... what? error: missing documentation for the crate
--> blobby/tests/mod.rs:1:1
|
1 | / #![cfg(feature = "alloc")]
2 | | #![allow(missing_docs, clippy::panic_in_result_fn)]
3 | |
4 | | const ITEMS_LEN: usize = 10;
... |
31 | | Ok(())
32 | | }
| |_^
|
= note: `-D missing-docs` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(missing_docs)]`...it's literally right there! Edit: though this lint seems fixed easily enough by adding a toplevel rustdoc comment |
41aa651 to
26fc609
Compare
|
Well, it's green, though I had to shut off the Maybe we can figure out some way to implement that which doesn't involve blowing away the workspace-level |
|
Something else we could use these configs for is setting some |
Adds a set of workspace-level lints including common ones we've used in
the past and others collected via running `clippy::pedantic` on several
of our crates and looking for interesting ones.
Workspace-level lints require explict opt-in from each crate's
Cargo.toml, so there's nothing forcing any crate to use them:
[lints]
workspace = true
That said, I have opted every crate in the workspace into these lints
and gotten them all to pass except for `wycheproof2blb` which is an
internal utility tool and I didn't feel like it was worth the hassle.
Even then, the lints are all set to `"warn"`, so they can be easily
overridden by `#[allow(...)]` attributes, including `#![allow(...)]`
to shut them off at the granularity of an entire crate.
I managed to fix most of the issues that `cargo clippy --fix` didn't fix
automatically including some missing documentation and documentation
formatting issues.
The main thing I didn't fix was adding missing `SAFETY` comments,
which is a problem with a few of the crates in this repo. I disabled a
lint at the crate level and added a TODO where we're missing them and it
wasn't easily corrected.
26fc609 to
fd1cf9d
Compare
newpavlov
left a comment
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 think you overuse #[must_use] a fair bit and it should be used in cases where a genuine mistake is likely and can cause silent bugs. See: https://std-dev-guide.rust-lang.org/policy/must-use.html As an example, Vec::len is not annotated with it, but you added it to InOutBuf::len.
Since it's not relevant to fixing the new lints, it's probably better to do in a separate PR.
|
|
||
| impl std::fmt::Display for CaseResult { | ||
| fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
| impl core::fmt::Display for CaseResult { |
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.
Add use core::fmt; to make it a bit less cluttered?
| #![allow( | ||
| clippy::missing_safety_doc, | ||
| clippy::std_instead_of_alloc, | ||
| clippy::std_instead_of_core, |
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.
std_instead_of_core and std_instead_of_alloc could be easily fixed.
| clippy::std_instead_of_alloc, | ||
| clippy::std_instead_of_core, | ||
| clippy::undocumented_unsafe_blocks, | ||
| clippy::unwrap_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.
Clippy has option allow-unwrap-in-tests which may be better than allowing this lint in every test.
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.
Aha, interesting
| /// Transform buffer into [`PaddedInOutBuf`] using padding algorithm `P`. | ||
| /// | ||
| /// # Errors | ||
| /// - if the padding is invalid |
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 think it's better to not have one entry lists and write simply:
/// # Errors
/// If the padding is invalid.
Same for other one-entry error and panic docs.
|
|
||
| impl Padding for Pkcs7 { | ||
| #[inline] | ||
| #[allow(clippy::cast_possible_truncation)] |
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.
Replace the cast with u8::try_from(..).expect("...")? I think the compiler should be able to remove the panic, but it's worth to check.
| must_use_candidate = "warn" | ||
| needless_range_loop = "allow" | ||
| implicit_saturating_sub = "warn" | ||
| panic_in_result_fn = "warn" |
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 am not sure about usefulness of the panic_in_result_fn lint in our context.
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 marked a couple of my crates as clippy::panic in this PR. panic_in_result_fn is a bit more manageable. It also won't trip on const asserts.
I'm fine with removing it from the workspace-level, but it does seem good to me. At one point I was trying my best to write panic-free code but the lack of tooling to ensure that's actually the case is somewhat demotivating.
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.
IIUC the lint did not result in any fixes in our code and I can not recall a single case where it could've been legitimate, so I think it's better to remove it and associated allows.
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 can remove it, but the general idea that something which returns Result probably shouldn't panic if possible seems like a good one to me
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.
Ideally, sure. But in practice we use Result for cases when user is responsible for the error and panics to guard against potential bugs in our code. Most of such panics get eliminated by optimization passes, but Clippy is unable to see it.
|
The minimal versions problem can be probably fixed by tweaking the action to cut |
The changes were applied with FWIW, I was sent down this whole road after encountering a bug in |
I think it would probably be better if it emitted a dummy workspace-level [workspace]
members = ["crate-under-test"]That way we don't need to update anything if we add any other workspace-level configs. |
Sure, but it would be a bit harder to implement than just cutting the lines. I think it's fine to start with the simple workaround and improve it later.
Ah, ok. Personally, I think that most of the added |
|
Really? One's just emitting a file from a template where the other you're trying to munge an existing file. Former sure seems easier and more maintainable to me, especially since it will work in perpetuity with other workspace-level configs |
|
For emitting the file you need to retrieve the crate name, while cutting the lines is one simple command. We also probably want to keep any other settings in the root Cargo.toml (i.e. ideally we should only modify the |
Adds a set of workspace-level lints including common ones we've used in the past and others collected via running
clippy::pedanticon several of our crates and looking for interesting ones.Workspace-level lints require explict opt-in from each crate's Cargo.toml, so there's nothing forcing any crate to use them:
That said, I have opted every crate in the workspace into these lints and gotten them all to pass except for
wycheproof2blbwhich is an internal utility tool and I didn't feel like it was worth the hassle.Even then, the lints are all set to
"warn", so they can be easily overridden by#[allow(...)]attributes, including#![allow(...)]to shut them off at the granularity of an entire crate.I managed to fix most of the issues that
cargo clippy --fixdidn't fix automatically including some missing documentation and documentation formatting issues.The main thing I didn't fix was adding missing
SAFETYcomments, which is a problem with a few of the crates in this repo. I disabled a lint at the crate level and added a TODO where we're missing them and it wasn't easily corrected.