diff --git a/src/cargo/core/compiler/mod.rs b/src/cargo/core/compiler/mod.rs index f30368e0f..a908c71a9 100644 --- a/src/cargo/core/compiler/mod.rs +++ b/src/cargo/core/compiler/mod.rs @@ -1353,12 +1353,37 @@ fn check_cfg_args(build_runner: &BuildRunner<'_, '_>, unit: &Unit) -> Vec>(check_cfg.clone()) + { + for check_cfg in check_cfgs { + args.push(OsString::from("--check-cfg")); + args.push(OsString::from(check_cfg)); + } + // warn (if wise) about `check-cfg` not being a list-of-string + } else if unit.show_warnings(&build_runner.bcx.gctx) { + let _ = build_runner.bcx.gctx.shell().warn("`lints.rust.unexpected_cfgs.check-cfg` must be a list of string"); + } + } + } + } + } + } + + args } else { Vec::new() } diff --git a/src/cargo/util/toml/mod.rs b/src/cargo/util/toml/mod.rs index 16dd2b4eb..088dd0196 100644 --- a/src/cargo/util/toml/mod.rs +++ b/src/cargo/util/toml/mod.rs @@ -2282,9 +2282,14 @@ supported tools: {}", for config_name in config.keys() { // manually report unused manifest key warning since we collect all the "extra" // keys and values inside the config table - let message = - format!("unused manifest key: `lints.{tool}.{name}.{config_name}`"); - warnings.push(message); + // + // except for `rust.unexpected_cfgs.check-cfg` which is used by rustc/rustdoc + if !(tool == "rust" && name == "unexpected_cfgs" && config_name == "check-cfg") + { + let message = + format!("unused manifest key: `lints.{tool}.{name}.{config_name}`"); + warnings.push(message); + } } } } diff --git a/tests/testsuite/check_cfg.rs b/tests/testsuite/check_cfg.rs index dff0d538a..278670411 100644 --- a/tests/testsuite/check_cfg.rs +++ b/tests/testsuite/check_cfg.rs @@ -496,3 +496,28 @@ fn build_script_test() { .with_stdout_contains_n("test [..] ... ok", 3) .run(); } + +#[cargo_test(>=1.79, reason = "--check-cfg was stabilized in Rust 1.79")] +fn config_simple() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.1.0" + edition = "2015" + + [lints.rust] + unexpected_cfgs = { level = "warn", check-cfg = ["cfg(has_foo)", "cfg(has_bar, values(\"yes\", \"no\"))"] } + "#, + ) + .file("src/main.rs", "fn main() {}") + .build(); + + p.cargo("check -v") + .with_stderr_contains(x!("rustc" => "cfg" of "has_foo")) + .with_stderr_contains(x!("rustc" => "cfg" of "has_bar" with "yes" "no")) + .with_stderr_does_not_contain("[..]unused manifest key[..]") + .run(); +}