Skip to content

Commit be0fbc6

Browse files
committed
Specify rust lints for compiler/ crates via Cargo.
By naming them in `[workspace.lints.rust]` in the top-level `Cargo.toml`, and then making all `compiler/` crates inherit them with `[lints] workspace = true`. (I omitted `rustc_codegen_{cranelift,gcc}`, because they're a bit different.) The advantages of this over the current approach: - It uses a standard Cargo feature, rather than special handling in bootstrap. - It works for proc macro crates. It's a shame it doesn't work for rustc-specific lints, as the comments explain. Two interesting cases that already had a `[lints.rust]` section, which is incompatible with inheriting lints from the workspace. - `rustc_type_ir` had an `unexpected_cfgs` entry for `cfg(bootstrap)`, but that's no longer necessary, because all mentions of `bootstrap` in `rustc_type_ir` have been removed. - `rustc_builtin_macros` had an `unexpected_cfgs` entry for `cfg(llvm_enayme)`, ... XXX what to do here? is it necessary?
1 parent 41e5bf2 commit be0fbc6

File tree

74 files changed

+239
-7
lines changed

Some content is hidden

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

74 files changed

+239
-7
lines changed

Cargo.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,18 @@ exclude = [
6363
"src/tools/x",
6464
]
6565

66+
# These lints are applied to many crates in the workspace. In practice, this is
67+
# all crates under `compiler/`.
68+
#
69+
# NOTE: rustc-specific lints (e.g. `rustc::internal`) aren't supported by
70+
# Cargo. They are specified for `compiler/` crates in
71+
# `src/bootstrap/src/core/builder/cargo.rs`.
72+
[workspace.lints.rust]
73+
# FIXME(edition_2024): Change this to `-Wrust_2024_idioms` when all of the
74+
# individual lints are satisfied.
75+
keyword_idents_2024 = "warn"
76+
unsafe_op_in_unsafe_fn = "warn"
77+
6678
[profile.release.package.rustc-rayon-core]
6779
# The rustc fork of Rayon has deadlock detection code which intermittently
6880
# causes overflows in the CI (see https://github.com/rust-lang/rust/issues/90227)

compiler/rustc/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,6 @@ llvm = ['rustc_driver_impl/llvm']
3232
max_level_info = ['rustc_driver_impl/max_level_info']
3333
rustc_randomized_layouts = ['rustc_driver_impl/rustc_randomized_layouts']
3434
# tidy-alphabetical-end
35+
36+
[lints]
37+
workspace = true

compiler/rustc_abi/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,6 @@ nightly = [
3131
]
3232
randomize = ["dep:rand", "dep:rand_xoshiro", "nightly"]
3333
# tidy-alphabetical-end
34+
35+
[lints]
36+
workspace = true

compiler/rustc_arena/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@ edition = "2024"
77
# tidy-alphabetical-start
88
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
99
# tidy-alphabetical-end
10+
11+
[lints]
12+
workspace = true

compiler/rustc_ast/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,6 @@ smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
1818
thin-vec = "0.2.12"
1919
tracing = "0.1"
2020
# tidy-alphabetical-end
21+
22+
[lints]
23+
workspace = true

compiler/rustc_ast_ir/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,6 @@ nightly = [
1919
"dep:rustc_macros",
2020
"dep:rustc_span",
2121
]
22+
23+
[lints]
24+
workspace = true

compiler/rustc_ast_lowering/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,6 @@ smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
2828
thin-vec = "0.2.12"
2929
tracing = "0.1"
3030
# tidy-alphabetical-end
31+
32+
[lints]
33+
workspace = true

compiler/rustc_ast_passes/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,6 @@ rustc_session = { path = "../rustc_session" }
2020
rustc_span = { path = "../rustc_span" }
2121
thin-vec = "0.2.12"
2222
# tidy-alphabetical-end
23+
24+
[lints]
25+
workspace = true

compiler/rustc_ast_pretty/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,6 @@ rustc_lexer = { path = "../rustc_lexer" }
1212
rustc_span = { path = "../rustc_span" }
1313
thin-vec = "0.2.12"
1414
# tidy-alphabetical-end
15+
16+
[lints]
17+
workspace = true

compiler/rustc_attr_data_structures/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,6 @@ rustc_serialize = {path = "../rustc_serialize"}
1414
rustc_span = {path = "../rustc_span"}
1515
thin-vec = "0.2.12"
1616
# tidy-alphabetical-end
17+
18+
[lints]
19+
workspace = true

0 commit comments

Comments
 (0)