Skip to content

Commit e9cde17

Browse files
authored
move clippy args to [workspace.lints.clippy] (#5715)
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.
1 parent 3ebded8 commit e9cde17

File tree

92 files changed

+321
-67
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+321
-67
lines changed

Cargo.toml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,48 @@ default-members = [
162162
]
163163
resolver = "2"
164164

165+
#
166+
# Tree-wide lint configuration.
167+
# https://doc.rust-lang.org/stable/cargo/reference/manifest.html#the-lints-section
168+
#
169+
# For a list of Clippy lints, see
170+
# https://rust-lang.github.io/rust-clippy/master.
171+
#
172+
[workspace.lints.clippy]
173+
# Clippy's style nits are useful, but not worth keeping in CI.
174+
style = { level = "allow", priority = -1 }
175+
# But continue to warn on anything in the "disallowed_" namespace.
176+
disallowed_macros = "warn"
177+
disallowed_methods = "warn"
178+
disallowed_names = "warn"
179+
disallowed_script_idents = "warn"
180+
disallowed_types = "warn"
181+
# Warn on some more style lints that are relatively stable and make sense.
182+
iter_cloned_collect = "warn"
183+
iter_next_slice = "warn"
184+
iter_nth = "warn"
185+
iter_nth_zero = "warn"
186+
iter_skip_next = "warn"
187+
len_zero = "warn"
188+
redundant_field_names = "warn"
189+
# `declare_interior_mutable_const` is classified as a style lint, but it can
190+
# identify real bugs (e.g., declarying a `const Atomic` and using it like
191+
# a `static Atomic`). However, it is also subject to false positives (e.g.,
192+
# idiomatically declaring a static array of atomics uses `const Atomic`). We
193+
# warn on this to catch the former, and expect any uses of the latter to allow
194+
# this locally.
195+
#
196+
# Note: any const value with a type containing a `bytes::Bytes` hits this lint,
197+
# and you should `#![allow]` it for now. This is most likely to be seen with
198+
# `http::header::{HeaderName, HeaderValue}`. This is a Clippy bug which will be
199+
# fixed in the Rust 1.80 toolchain (rust-lang/rust-clippy#12691).
200+
declare_interior_mutable_const = "warn"
201+
# Also warn on casts, preferring explicit conversions instead.
202+
#
203+
# We'd like to warn on lossy casts in the future, but lossless casts are the
204+
# easiest ones to convert over.
205+
cast_lossless = "warn"
206+
165207
[workspace.dependencies]
166208
anyhow = "1.0"
167209
anstyle = "1.0.6"

api_identity/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ license = "MPL-2.0"
1010
[lib]
1111
proc-macro = true
1212

13+
[lints]
14+
workspace = true
15+
1316
[dependencies]
1417
proc-macro2.workspace = true
1518
quote.workspace = true

bootstore/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ license = "MPL-2.0"
88
[build-dependencies]
99
omicron-rpaths.workspace = true
1010

11+
[lints]
12+
workspace = true
13+
1114
[dependencies]
1215
bytes.workspace = true
1316
camino.workspace = true

caboose-util/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ version = "0.1.0"
44
edition = "2021"
55
license = "MPL-2.0"
66

7+
[lints]
8+
workspace = true
9+
710
[dependencies]
811
anyhow.workspace = true
912
hubtools.workspace = true

certificates/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ version = "0.1.0"
44
edition = "2021"
55
license = "MPL-2.0"
66

7+
[lints]
8+
workspace = true
9+
710
[dependencies]
811
display-error-chain.workspace = true
912
foreign-types.workspace = true

clients/bootstrap-agent-client/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ version = "0.1.0"
44
edition = "2021"
55
license = "MPL-2.0"
66

7+
[lints]
8+
workspace = true
9+
710
[dependencies]
811
omicron-common.workspace = true
912
progenitor.workspace = true

clients/ddm-admin-client/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ version = "0.1.0"
44
edition = "2021"
55
license = "MPL-2.0"
66

7+
[lints]
8+
workspace = true
9+
710
[dependencies]
811
either.workspace = true
912
progenitor-client.workspace = true

clients/dns-service-client/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ version = "0.1.0"
44
edition = "2021"
55
license = "MPL-2.0"
66

7+
[lints]
8+
workspace = true
9+
710
[dependencies]
811
anyhow.workspace = true
912
chrono.workspace = true

clients/dpd-client/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ version = "0.1.0"
44
edition = "2021"
55
license = "MPL-2.0"
66

7+
[lints]
8+
workspace = true
9+
710
[dependencies]
811
futures.workspace = true
912
progenitor-client.workspace = true

clients/gateway-client/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ version = "0.1.0"
44
edition = "2021"
55
license = "MPL-2.0"
66

7+
[lints]
8+
workspace = true
9+
710
[dependencies]
811
base64.workspace = true
912
chrono.workspace = true

clients/installinator-artifact-client/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ version = "0.1.0"
44
edition = "2021"
55
license = "MPL-2.0"
66

7+
[lints]
8+
workspace = true
9+
710
[dependencies]
811
installinator-common.workspace = true
912
progenitor.workspace = true

clients/nexus-client/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ version = "0.1.0"
44
edition = "2021"
55
license = "MPL-2.0"
66

7+
[lints]
8+
workspace = true
9+
710
[dependencies]
811
chrono.workspace = true
912
futures.workspace = true

clients/oxide-client/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ version = "0.1.0"
44
edition = "2021"
55
license = "MPL-2.0"
66

7+
[lints]
8+
workspace = true
9+
710
[dependencies]
811
anyhow.workspace = true
912
base64.workspace = true

clients/oximeter-client/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ version = "0.1.0"
44
edition = "2021"
55
license = "MPL-2.0"
66

7+
[lints]
8+
workspace = true
9+
710
[dependencies]
811
chrono.workspace = true
912
futures.workspace = true

clients/sled-agent-client/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ version = "0.1.0"
44
edition = "2021"
55
license = "MPL-2.0"
66

7+
[lints]
8+
workspace = true
9+
710
[dependencies]
811
anyhow.workspace = true
912
async-trait.workspace = true

clients/wicketd-client/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ version = "0.1.0"
44
edition = "2021"
55
license = "MPL-2.0"
66

7+
[lints]
8+
workspace = true
9+
710
[dependencies]
811
chrono.workspace = true
912
installinator-common.workspace = true

common/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ version = "0.1.0"
44
edition = "2021"
55
license = "MPL-2.0"
66

7+
[lints]
8+
workspace = true
9+
710
# NOTE:
811
#
912
# This crate is depended on by several other workspaces! Be careful of adding

dev-tools/crdb-seed/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ edition = "2021"
55
license = "MPL-2.0"
66
readme = "README.md"
77

8+
[lints]
9+
workspace = true
10+
811
[dependencies]
912
anyhow.workspace = true
1013
dropshot.workspace = true

dev-tools/omdb/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ version = "0.1.0"
44
edition = "2021"
55
license = "MPL-2.0"
66

7+
[lints]
8+
workspace = true
9+
710
[build-dependencies]
811
omicron-rpaths.workspace = true
912

dev-tools/omicron-dev/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ version = "0.1.0"
44
edition = "2021"
55
license = "MPL-2.0"
66

7+
[lints]
8+
workspace = true
9+
710
[build-dependencies]
811
omicron-rpaths.workspace = true
912

dev-tools/oxlog/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ version = "0.1.0"
44
edition = "2021"
55
license = "MPL-2.0"
66

7+
[lints]
8+
workspace = true
9+
710
[dependencies]
811
anyhow.workspace = true
912
camino.workspace = true

dev-tools/reconfigurator-cli/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ version = "0.1.0"
44
edition = "2021"
55
license = "MPL-2.0"
66

7+
[lints]
8+
workspace = true
9+
710
[build-dependencies]
811
omicron-rpaths.workspace = true
912

dev-tools/xtask/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ version = "0.1.0"
44
edition = "2021"
55
license = "MPL-2.0"
66

7+
[lints]
8+
workspace = true
9+
710
[dependencies]
811
anyhow.workspace = true
912
camino.workspace = true

dev-tools/xtask/src/check_workspace_deps.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,24 @@ pub fn run_cmd() -> Result<()> {
3131

3232
// Iterate the workspace packages and fill out the maps above.
3333
for pkg_info in workspace.workspace_packages() {
34+
let manifest_path = &pkg_info.manifest_path;
35+
let manifest = read_cargo_toml(manifest_path)?;
36+
37+
// Check that `[lints] workspace = true` is set.
38+
if !manifest.lints.map(|lints| lints.workspace).unwrap_or(false) {
39+
eprintln!(
40+
"error: package {:?} does not have `[lints] workspace = true` set",
41+
pkg_info.name
42+
);
43+
nerrors += 1;
44+
}
45+
3446
if pkg_info.name == WORKSPACE_HACK_PACKAGE_NAME {
3547
// Skip over workspace-hack because hakari doesn't yet support
3648
// workspace deps: https://github.com/guppy-rs/guppy/issues/7
3749
continue;
3850
}
3951

40-
let manifest_path = &pkg_info.manifest_path;
41-
let manifest = read_cargo_toml(manifest_path)?;
4252
for tree in [
4353
&manifest.dependencies,
4454
&manifest.dev_dependencies,

dev-tools/xtask/src/clippy.rs

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -34,54 +34,7 @@ pub fn run_cmd(args: ClippyArgs) -> Result<()> {
3434
//
3535
// We disallow warnings by default.
3636
.arg("--deny")
37-
.arg("warnings")
38-
// Clippy's style nits are useful, but not worth keeping in CI. This
39-
// override belongs in src/lib.rs, and it is there, but that doesn't
40-
// reliably work due to rust-lang/rust-clippy#6610.
41-
.arg("--allow")
42-
.arg("clippy::style")
43-
// But continue to warn on anything in the "disallowed_" namespace.
44-
// (These will be turned into errors by `--deny warnings` above.)
45-
.arg("--warn")
46-
.arg("clippy::disallowed_macros")
47-
.arg("--warn")
48-
.arg("clippy::disallowed_methods")
49-
.arg("--warn")
50-
.arg("clippy::disallowed_names")
51-
.arg("--warn")
52-
.arg("clippy::disallowed_script_idents")
53-
.arg("--warn")
54-
.arg("clippy::disallowed_types")
55-
// Warn on some more style lints that are relatively stable and make
56-
// sense.
57-
.arg("--warn")
58-
.arg("clippy::iter_cloned_collect")
59-
.arg("--warn")
60-
.arg("clippy::iter_next_slice")
61-
.arg("--warn")
62-
.arg("clippy::iter_nth")
63-
.arg("--warn")
64-
.arg("clippy::iter_nth_zero")
65-
.arg("--warn")
66-
.arg("clippy::iter_skip_next")
67-
.arg("--warn")
68-
.arg("clippy::len_zero")
69-
.arg("--warn")
70-
.arg("clippy::redundant_field_names")
71-
// `declare_interior_mutable_const` is classified as a style lint, but
72-
// it can identify real bugs (e.g., declarying a `const Atomic` and
73-
// using it like a `static Atomic`). However, it is also subject to
74-
// false positives (e.g., idiomatically declaring a static array of
75-
// atomics uses `const Atomic`). We warn on this to catch the former,
76-
// and expect any uses of the latter to allow this locally.
77-
.arg("--warn")
78-
.arg("clippy::declare_interior_mutable_const")
79-
// Also warn on casts, preferring explicit conversions instead.
80-
//
81-
// We'd like to warn on lossy casts in the future, but lossless casts
82-
// are the easiest ones to convert over.
83-
.arg("--warn")
84-
.arg("clippy::cast_lossless");
37+
.arg("warnings");
8538

8639
eprintln!(
8740
"running: {:?} {}",

dns-server/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ version = "0.1.0"
44
edition = "2021"
55
license = "MPL-2.0"
66

7+
[lints]
8+
workspace = true
9+
710
[dependencies]
811
anyhow.workspace = true
912
camino.workspace = true

end-to-end-tests/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ version = "0.1.0"
44
edition = "2021"
55
license = "MPL-2.0"
66

7+
[lints]
8+
workspace = true
9+
710
[dependencies]
811
anyhow = { workspace = true, features = ["backtrace"] }
912
async-trait.workspace = true

gateway-cli/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ version = "0.1.0"
44
edition = "2021"
55
license = "MPL-2.0"
66

7+
[lints]
8+
workspace = true
9+
710
[dependencies]
811
anyhow.workspace = true
912
clap.workspace = true

gateway-test-utils/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ version = "0.1.0"
44
edition = "2021"
55
license = "MPL-2.0"
66

7+
[lints]
8+
workspace = true
9+
710
[dependencies]
811
camino.workspace = true
912
dropshot.workspace = true

0 commit comments

Comments
 (0)