Skip to content

Commit beba32c

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. So, easier to understand, and less likely to get accidentally broken in the future. - It works for proc macro crates. It's a shame it doesn't work for rustc-specific lints, as the comments explain.
1 parent a8eeb4b commit beba32c

File tree

74 files changed

+237
-4
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

+237
-4
lines changed

Cargo.toml

+13
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,19 @@ 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. (Support for them is possibly blocked by #44690 (attributes for
71+
# tools).) Those lints are instead specified for `compiler/` crates in
72+
# `src/bootstrap/src/core/builder/cargo.rs`.
73+
[workspace.lints.rust]
74+
# FIXME(edition_2024): Change this to `-Wrust_2024_idioms` when all of the
75+
# individual lints are satisfied.
76+
keyword_idents_2024 = "warn"
77+
unsafe_op_in_unsafe_fn = "warn"
78+
6679
[profile.release.package.rustc-rayon-core]
6780
# The rustc fork of Rayon has deadlock detection code which intermittently
6881
# causes overflows in the CI (see https://github.com/rust-lang/rust/issues/90227)

compiler/rustc/Cargo.toml

+3
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

+3
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

+3
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

+3
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

+3
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

+3
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

+3
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

+3
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

+3
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

compiler/rustc_attr_parsing/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,6 @@ rustc_session = { path = "../rustc_session" }
2121
rustc_span = { path = "../rustc_span" }
2222
thin-vec = "0.2.12"
2323
# tidy-alphabetical-end
24+
25+
[lints]
26+
workspace = true

compiler/rustc_baked_icu_data/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,6 @@ icu_locid_transform = "1.3.2"
1111
icu_provider = { version = "1.2", features = ["sync"] }
1212
zerovec = "0.10.0"
1313
# tidy-alphabetical-end
14+
15+
[lints]
16+
workspace = true

compiler/rustc_borrowck/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,6 @@ rustc_traits = { path = "../rustc_traits" }
2727
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
2828
tracing = "0.1"
2929
# tidy-alphabetical-end
30+
31+
[lints]
32+
workspace = true

compiler/rustc_builtin_macros/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,6 @@ smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
3030
thin-vec = "0.2.12"
3131
tracing = "0.1"
3232
# tidy-alphabetical-end
33+
34+
[lints]
35+
workspace = true

compiler/rustc_codegen_llvm/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,6 @@ serde_json = "1"
4343
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
4444
tracing = "0.1"
4545
# tidy-alphabetical-end
46+
47+
[lints]
48+
workspace = true

compiler/rustc_codegen_ssa/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,6 @@ features = ["read_core", "elf", "macho", "pe", "xcoff", "unaligned", "archive",
6363
[target.'cfg(windows)'.dependencies.windows]
6464
version = "0.59.0"
6565
features = ["Win32_Globalization"]
66+
67+
[lints]
68+
workspace = true

compiler/rustc_const_eval/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,6 @@ rustc_trait_selection = { path = "../rustc_trait_selection" }
2626
rustc_type_ir = { path = "../rustc_type_ir" }
2727
tracing = "0.1"
2828
# tidy-alphabetical-end
29+
30+
[lints]
31+
workspace = true

compiler/rustc_data_structures/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,6 @@ memmap2 = "0.2.1"
5454

5555
[target.'cfg(not(target_has_atomic = "64"))'.dependencies]
5656
portable-atomic = "1.5.1"
57+
58+
[lints]
59+
workspace = true

compiler/rustc_driver/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,6 @@ crate-type = ["dylib"]
1010
# tidy-alphabetical-start
1111
rustc_driver_impl = { path = "../rustc_driver_impl" }
1212
# tidy-alphabetical-end
13+
14+
[lints]
15+
workspace = true

compiler/rustc_driver_impl/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,6 @@ rustc_randomized_layouts = [
7979
'rustc_middle/rustc_randomized_layouts'
8080
]
8181
# tidy-alphabetical-end
82+
83+
[lints]
84+
workspace = true

compiler/rustc_error_codes/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@ edition = "2024"
66
[dependencies]
77
# tidy-alphabetical-start
88
# tidy-alphabetical-end
9+
10+
[lints]
11+
workspace = true

compiler/rustc_error_messages/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,6 @@ rustc_span = { path = "../rustc_span" }
1919
tracing = "0.1"
2020
unic-langid = { version = "0.9.0", features = ["macros"] }
2121
# tidy-alphabetical-end
22+
23+
[lints]
24+
workspace = true

compiler/rustc_errors/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,6 @@ features = [
3939
"Win32_Security",
4040
"Win32_System_Threading",
4141
]
42+
43+
[lints]
44+
workspace = true

compiler/rustc_expand/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,6 @@ smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
2929
thin-vec = "0.2.12"
3030
tracing = "0.1"
3131
# tidy-alphabetical-end
32+
33+
[lints]
34+
workspace = true

compiler/rustc_feature/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,6 @@ rustc_span = { path = "../rustc_span" }
1010
serde = { version = "1.0.125", features = [ "derive" ] }
1111
serde_json = "1.0.59"
1212
# tidy-alphabetical-end
13+
14+
[lints]
15+
workspace = true

compiler/rustc_fluent_macro/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,6 @@ quote = "1"
1616
syn = { version = "2", features = ["full"] }
1717
unic-langid = { version = "0.9.0", features = ["macros"] }
1818
# tidy-alphabetical-end
19+
20+
[lints]
21+
workspace = true

compiler/rustc_fs_util/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@ edition = "2024"
66
[dependencies]
77
# tidy-alphabetical-start
88
# tidy-alphabetical-end
9+
10+
[lints]
11+
workspace = true

compiler/rustc_graphviz/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@ edition = "2024"
66
[dependencies]
77
# tidy-alphabetical-start
88
# tidy-alphabetical-end
9+
10+
[lints]
11+
workspace = true

compiler/rustc_hashes/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@ edition = "2024"
77
# tidy-alphabetical-start
88
rustc-stable-hash = { version = "0.1.0" }
99
# tidy-alphabetical-end
10+
11+
[lints]
12+
workspace = true

compiler/rustc_hir/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,6 @@ smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
2121
thin-vec = "0.2.12"
2222
tracing = "0.1"
2323
# tidy-alphabetical-end
24+
25+
[lints]
26+
workspace = true

compiler/rustc_hir_analysis/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,6 @@ rustc_type_ir = { path = "../rustc_type_ir" }
3232
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
3333
tracing = "0.1"
3434
# tidy-alphabetical-end
35+
36+
[lints]
37+
workspace = true

compiler/rustc_hir_pretty/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,6 @@ rustc_attr_parsing = { path = "../rustc_attr_parsing" }
1212
rustc_hir = { path = "../rustc_hir" }
1313
rustc_span = { path = "../rustc_span" }
1414
# tidy-alphabetical-end
15+
16+
[lints]
17+
workspace = true

compiler/rustc_hir_typeck/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,6 @@ rustc_type_ir = { path = "../rustc_type_ir" }
2727
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
2828
tracing = "0.1"
2929
# tidy-alphabetical-end
30+
31+
[lints]
32+
workspace = true

compiler/rustc_incremental/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,6 @@ rustc_span = { path = "../rustc_span" }
2222
thin-vec = "0.2.12"
2323
tracing = "0.1"
2424
# tidy-alphabetical-end
25+
26+
[lints]
27+
workspace = true

compiler/rustc_index/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,6 @@ nightly = [
2121
]
2222
rustc_randomized_layouts = []
2323
# tidy-alphabetical-end
24+
25+
[lints]
26+
workspace = true

compiler/rustc_index_macros/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@ quote = "1"
1313

1414
[features]
1515
nightly = []
16+
17+
[lints]
18+
workspace = true

compiler/rustc_infer/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,6 @@ smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
2121
thin-vec = "0.2.12"
2222
tracing = "0.1"
2323
# tidy-alphabetical-end
24+
25+
[lints]
26+
workspace = true

compiler/rustc_interface/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,6 @@ tracing = "0.1"
5656
# tidy-alphabetical-start
5757
llvm = ['dep:rustc_codegen_llvm']
5858
# tidy-alphabetical-end
59+
60+
[lints]
61+
workspace = true

compiler/rustc_lexer/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,6 @@ features = ["emoji"]
2424

2525
[dev-dependencies]
2626
expect-test = "1.4.0"
27+
28+
[lints]
29+
workspace = true

compiler/rustc_lint/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,6 @@ smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
2828
tracing = "0.1"
2929
unicode-security = "0.1.0"
3030
# tidy-alphabetical-end
31+
32+
[lints]
33+
workspace = true

compiler/rustc_lint_defs/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,6 @@ rustc_serialize = { path = "../rustc_serialize" }
1515
rustc_span = { path = "../rustc_span" }
1616
serde = { version = "1.0.125", features = ["derive"] }
1717
# tidy-alphabetical-end
18+
19+
[lints]
20+
workspace = true

compiler/rustc_llvm/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,6 @@ libc = "0.2.73"
1414
# pinned `cc` in `rustc_codegen_ssa` if you update `cc` here.
1515
cc = "=1.2.16"
1616
# tidy-alphabetical-end
17+
18+
[lints]
19+
workspace = true

compiler/rustc_log/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,6 @@ rustc_span = { path = "../rustc_span" }
2020
# tidy-alphabetical-start
2121
max_level_info = ['tracing/max_level_info']
2222
# tidy-alphabetical-end
23+
24+
[lints]
25+
workspace = true

compiler/rustc_macros/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@ quote = "1"
1313
syn = { version = "2.0.9", features = ["full"] }
1414
synstructure = "0.13.0"
1515
# tidy-alphabetical-end
16+
17+
[lints]
18+
workspace = true

compiler/rustc_metadata/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,6 @@ rustc_type_ir = { path = "../rustc_type_ir" }
3131
tempfile = "3.2"
3232
tracing = "0.1"
3333
# tidy-alphabetical-end
34+
35+
[lints]
36+
workspace = true

compiler/rustc_middle/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,6 @@ tracing = "0.1"
4242
# tidy-alphabetical-start
4343
rustc_randomized_layouts = []
4444
# tidy-alphabetical-end
45+
46+
[lints]
47+
workspace = true

compiler/rustc_mir_build/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,6 @@ rustc_span = { path = "../rustc_span" }
2828
rustc_trait_selection = { path = "../rustc_trait_selection" }
2929
tracing = "0.1"
3030
# tidy-alphabetical-end
31+
32+
[lints]
33+
workspace = true

compiler/rustc_mir_dataflow/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,6 @@ rustc_span = { path = "../rustc_span" }
2121
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
2222
tracing = "0.1"
2323
# tidy-alphabetical-end
24+
25+
[lints]
26+
workspace = true

compiler/rustc_mir_transform/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,6 @@ rustc_type_ir = { path = "../rustc_type_ir" }
3030
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
3131
tracing = "0.1"
3232
# tidy-alphabetical-end
33+
34+
[lints]
35+
workspace = true

compiler/rustc_monomorphize/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,6 @@ serde = "1"
2222
serde_json = "1"
2323
tracing = "0.1"
2424
# tidy-alphabetical-end
25+
26+
[lints]
27+
workspace = true

compiler/rustc_next_trait_solver/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,6 @@ nightly = [
2424
"rustc_index/nightly",
2525
"rustc_type_ir/nightly",
2626
]
27+
28+
[lints]
29+
workspace = true

compiler/rustc_parse/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,5 @@ unicode-width = "0.2.0"
2626
[dev-dependencies]
2727
termcolor = "1.2"
2828

29+
[lints]
30+
workspace = true

compiler/rustc_parse_format/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@ edition = "2024"
88
rustc_index = { path = "../rustc_index", default-features = false }
99
rustc_lexer = { path = "../rustc_lexer" }
1010
# tidy-alphabetical-end
11+
12+
[lints]
13+
workspace = true

compiler/rustc_passes/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,6 @@ rustc_target = { path = "../rustc_target" }
2626
rustc_trait_selection = { path = "../rustc_trait_selection" }
2727
tracing = "0.1"
2828
# tidy-alphabetical-end
29+
30+
[lints]
31+
workspace = true

compiler/rustc_pattern_analysis/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,6 @@ rustc = [
4343
"smallvec/may_dangle",
4444
"rustc_index/nightly",
4545
]
46+
47+
[lints]
48+
workspace = true

0 commit comments

Comments
 (0)