Skip to content
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

move clippy args to [workspace.lints.clippy] #5715

Merged
merged 6 commits into from
May 8, 2024

Conversation

iliana
Copy link
Contributor

@iliana iliana commented May 7, 2024

This moves our Clippy configuration out of xtask and into Cargo's relatively-new lint configuration functionality. https://blog.rust-lang.org/2023/11/16/Rust-1.74.0.html#lint-configuration-through-cargo

This seeks to solve a similar root issue as #5714, which is "please, rust-analyzer, do not tell me about clippy lints we don't care about in CI".

Unfortunately this requires littering [lints] workspace = true in every Cargo.toml, at least until implicit workspace inheritance is figured out, which is most of the noise of this PR. We may want a CI check to ensure that this is set in all packages.

As part of this I removed the #![allow(clippy::style)] attributes from nexus and sled-agent, which revealed that this was overriding any style lints we re-enabled in the xtask code.

One issue is that workspace crates can't override these lints yet (rust-lang/cargo#13157), but they can continue to override them with #![allow(clippy::whatever)] attributes.

@iliana iliana requested review from jgallagher and hawkw May 7, 2024 19:40
Comment on lines +191 to +194
# a `static Atomic`). However, it is also subject to false positives (e.g.,
# idiomatically declaring a static array of atomics uses `const Atomic`). We
# warn on this to catch the former, and expect any uses of the latter to allow
# this locally.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

take it or leave it: maybe worth also mentioning http::HeaderName explicitly, since that's probably one of the most common false positives we'll hit in omicron? it would be nice if someone who adds a const HeaderName in the future to immediately see "no, just allow that lint" written down here.

#
[workspace.lints.clippy]
# Clippy's style nits are useful, but not worth keeping in CI.
style = { level = "allow", priority = -1 }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does priority = -1 do? i assume it allows this to be overridden, but why do we only need to set it here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Until [lints], all methods for modifying lint levels had inherent ordering; either command line flags, or attributes in code. TOML tables are explicitly unordered, so Rust had to do something different here. Per the RFC any sorting beyond user-defined priorities is undefined (more detail); style has to come first because otherwise it would re-allow the style lints that happen to come before it once sorted.

The default priority for any key in this table is 0, so setting this to -1 means it is ordered before the rest of the keys.

Copy link
Contributor

@jgallagher jgallagher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto Eliza's question about priority = -1, but other than that LGTM!

@sunshowers
Copy link
Contributor

sunshowers commented May 8, 2024

Ooh just saw this one — really concerned that we're going to miss workspace = true in new crates. How hard would it be to address this before landing? We already have the lint which checks that dependencies are specified with workspace = true, can that be expanded?

@iliana
Copy link
Contributor Author

iliana commented May 8, 2024

Probably!

@iliana iliana requested a review from sunshowers May 8, 2024 02:36
Copy link
Contributor

@sunshowers sunshowers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thanks!

@iliana iliana merged commit e9cde17 into main May 8, 2024
22 checks passed
@iliana iliana deleted the iliana/workspace-lints-clippy branch May 8, 2024 22:59
hawkw pushed a commit that referenced this pull request May 9, 2024
This moves our Clippy configuration out of xtask and into Cargo's
relatively-new lint configuration functionality.
https://blog.rust-lang.org/2023/11/16/Rust-1.74.0.html#lint-configuration-through-cargo

Unfortunately this requires littering `[lints] workspace = true` in
every Cargo.toml, at least until implicit workspace inheritance is
figured out. This adds a check to `cargo xtask check-workspace-deps` to
ensure this is the case in CI.

As part of this I removed the `#![allow(clippy::style)]` attributes from
nexus and sled-agent, which revealed that this was overriding any style
lints we re-enabled in the xtask code.

One issue is that workspace crates can't override these lints yet
(rust-lang/cargo#13157), but they can continue
to override them with `#![allow(clippy::whatever)]` attributes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants