ITADN

linker_messages force-warn lint level is not respected

#17142OpenMark-Simulacrum 创建于 2026-06-27
I-nominated-to-discuss
M
Mark-Simulacrumcommented
Not entirely sure if this is a bug in Cargo or in rustc or I'm misunderstanding the stabilization report, but my expectation based on https://doc.rust-lang.org/nightly/cargo/reference/config.html#buildwarnings ("Only warnings that are lints (i.e. level is adjustable) are affected") and the [stabilization report](https://github.com/rust-lang/cargo/pull/16796) ("this matches RUSTFLAGS=-Dwarnings") is that CARGO_BUILD_WARNINGS and RUSTFLAGS=-Dwarnings should have the same behavior. However, for linker messages that doesn't appear to be the case; `-Dwarnings` is ignored while `CARGO_BUILD_WARNINGS` denies the lint and breaks compilation. It was intentional that linker messages *don't* get affected by deny warnings so this behavior is inconsistent with intent on the rustc side. Both of these are stabilized in 1.97, which will become stable in ~1.5 weeks and are intended to both feature in the blog post, so it probably makes sense to figure out whether we're happy with this (to me unexpected) interaction. ``` $ cargo build --config "target.aarch64-apple-darwin.linker=\"$(pwd)/linker.rs\"" Compiling test-linker-message v0.1.0 (/Volumes/Edit/Edit/test-linker-message) warning: linker stderr: Linker emits a message | = note: `#[warn(linker_messages)]` on by default warning: `test-linker-message` (bin "test-linker-message") generated 1 warning ``` ``` $ RUSTFLAGS=-Dwarnings cargo build --config "target.aarch64-apple-darwin.linker=\"$(pwd)/linker.rs\"" Compiling test-linker-message v0.1.0 (/Volumes/Edit/Edit/test-linker-message) warning: linker stderr: Linker emits a message | = note: `#[warn(linker_messages)]` on by default = note: the `linker_messages` lint ignores `-D warnings` ``` ``` $ CARGO_BUILD_WARNINGS=deny cargo build --config "target.aarch64-apple-darwin.linker=\"$(pwd)/linker.rs\"" warning: linker stderr: Linker emits a message | = note: `#[warn(linker_messages)]` on by default error: `test-linker-message` (bin "test-linker-message") generated 1 warning error: warnings are denied by `build.warnings` configuration ``` Linker warning-emitter: <details> ``` $ cat linker.rs #!/usr/bin/env cargo -Zscript --- [package] edition = "2024" --- fn main() -> Result<(), std::process::ExitCode> { eprintln!("Linker emits a message"); let status = std::process::Command::new("cc") .args(std::env::args_os().skip(1)) .status() .unwrap(); if status.success() { Ok(()) } else { Err(std::process::ExitCode::FAILURE) } } ``` </details>
10 条评论