Skip to content

Commit c9c8387

Browse files
committed
Use RUSTC_LINT_FLAGS more.
For the `Mode::Rustc` lints as well. Because, unlike `RUSTC_FLAGS`, `RUSTC_LINT_FLAGS` is not ignored for proc macro crates. Fixes #138106.
1 parent 9fb94b3 commit c9c8387

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

Diff for: src/bootstrap/src/core/builder/cargo.rs

+23-16
Original file line numberDiff line numberDiff line change
@@ -1045,8 +1045,11 @@ impl Builder<'_> {
10451045
// so this line allows the use of custom libcs.
10461046
cargo.env("LIBC_CHECK_CFG", "1");
10471047

1048+
let mut lint_flags = Vec::new();
1049+
1050+
// Lints for all in-tree code: compiler, rustdoc, cranelift, gcc,
1051+
// clippy, rustfmt, rust-analyzer, etc.
10481052
if source_type == SourceType::InTree {
1049-
let mut lint_flags = Vec::new();
10501053
// When extending this list, add the new lints to the RUSTFLAGS of the
10511054
// build_bootstrap function of src/bootstrap/bootstrap.py as well as
10521055
// some code doesn't go through this `rustc` wrapper.
@@ -1058,27 +1061,31 @@ impl Builder<'_> {
10581061
rustdocflags.arg("-Dwarnings");
10591062
}
10601063

1061-
// This does not use RUSTFLAGS due to caching issues with Cargo.
1062-
// Clippy is treated as an "in tree" tool, but shares the same
1063-
// cache as other "submodule" tools. With these options set in
1064-
// RUSTFLAGS, that causes *every* shared dependency to be rebuilt.
1065-
// By injecting this into the rustc wrapper, this circumvents
1066-
// Cargo's fingerprint detection. This is fine because lint flags
1067-
// are always ignored in dependencies. Eventually this should be
1068-
// fixed via better support from Cargo.
1069-
cargo.env("RUSTC_LINT_FLAGS", lint_flags.join(" "));
1070-
10711064
rustdocflags.arg("-Wrustdoc::invalid_codeblock_attributes");
10721065
}
10731066

1067+
// Lints just for `compiler/` crates.
10741068
if mode == Mode::Rustc {
1075-
rustflags.arg("-Wrustc::internal");
1076-
rustflags.arg("-Drustc::symbol_intern_string_literal");
1069+
lint_flags.push("-Wrustc::internal");
1070+
lint_flags.push("-Drustc::symbol_intern_string_literal");
10771071
// FIXME(edition_2024): Change this to `-Wrust_2024_idioms` when all
10781072
// of the individual lints are satisfied.
1079-
rustflags.arg("-Wkeyword_idents_2024");
1080-
rustflags.arg("-Wunsafe_op_in_unsafe_fn");
1081-
}
1073+
lint_flags.push("-Wkeyword_idents_2024");
1074+
lint_flags.push("-Wunsafe_op_in_unsafe_fn");
1075+
}
1076+
1077+
// This does not use RUSTFLAGS for two reasons.
1078+
// - Due to caching issues with Cargo. Clippy is treated as an "in
1079+
// tree" tool, but shares the same cache as other "submodule" tools.
1080+
// With these options set in RUSTFLAGS, that causes *every* shared
1081+
// dependency to be rebuilt. By injecting this into the rustc
1082+
// wrapper, this circumvents Cargo's fingerprint detection. This is
1083+
// fine because lint flags are always ignored in dependencies.
1084+
// Eventually this should be fixed via better support from Cargo.
1085+
// - RUSTFLAGS is ignored for proc macro crates that are being built on
1086+
// the host (because `--target` is given). But we want the lint flags
1087+
// to be applied to proc macro crates.
1088+
cargo.env("RUSTC_LINT_FLAGS", lint_flags.join(" "));
10821089

10831090
if self.config.rust_frame_pointers {
10841091
rustflags.arg("-Cforce-frame-pointers=true");

0 commit comments

Comments
 (0)