From fd7b6744e83c76e543cc2fd985ef655dd9183874 Mon Sep 17 00:00:00 2001 From: Urgau Date: Fri, 27 Oct 2023 16:27:37 +0200 Subject: [PATCH 1/2] Remove outdated option to -Zcheck-cfg warnings --- src/cargo/core/compiler/custom_build.rs | 2 +- src/cargo/util/config/target.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cargo/core/compiler/custom_build.rs b/src/cargo/core/compiler/custom_build.rs index b3412e1d073..022ad87613a 100644 --- a/src/cargo/core/compiler/custom_build.rs +++ b/src/cargo/core/compiler/custom_build.rs @@ -803,7 +803,7 @@ impl BuildOutput { if extra_check_cfg { check_cfgs.push(value.to_string()); } else { - warnings.push(format!("cargo:{} requires -Zcheck-cfg=output flag", key)); + warnings.push(format!("cargo:{} requires -Zcheck-cfg flag", key)); } } "rustc-env" => { diff --git a/src/cargo/util/config/target.rs b/src/cargo/util/config/target.rs index de00b5b115a..0e2029ffc56 100644 --- a/src/cargo/util/config/target.rs +++ b/src/cargo/util/config/target.rs @@ -208,7 +208,7 @@ fn parse_links_overrides( output.check_cfgs.extend(list.iter().map(|v| v.0.clone())); } else { config.shell().warn(format!( - "target config `{}.{}` requires -Zcheck-cfg=output flag", + "target config `{}.{}` requires -Zcheck-cfg flag", target_key, key ))?; } From e396904b25713f80e40f47e022f18ef4c50efde1 Mon Sep 17 00:00:00 2001 From: Urgau Date: Fri, 27 Oct 2023 17:10:49 +0200 Subject: [PATCH 2/2] Add feature gate test for check-cfg config, build script and override --- tests/testsuite/check_cfg.rs | 92 ++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) diff --git a/tests/testsuite/check_cfg.rs b/tests/testsuite/check_cfg.rs index dbc67582524..30c3d0459c2 100644 --- a/tests/testsuite/check_cfg.rs +++ b/tests/testsuite/check_cfg.rs @@ -354,6 +354,41 @@ fn build_script_override() { .run(); } +#[cargo_test] +fn build_script_override_feature_gate() { + let target = cargo_test_support::rustc_host(); + + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.1.0" + links = "a" + "#, + ) + .file("src/main.rs", "fn main() {}") + .file("build.rs", "fn main() {}") + .file( + ".cargo/config", + &format!( + r#" + [target.{}.a] + rustc-check-cfg = ["cfg(foo)"] + "#, + target + ), + ) + .build(); + + p.cargo("check") + .with_stderr_contains( + "warning: target config[..]rustc-check-cfg[..] requires -Zcheck-cfg flag", + ) + .run(); +} + #[cargo_test(nightly, reason = "--check-cfg is unstable")] fn build_script_test() { let p = project() @@ -409,6 +444,34 @@ fn build_script_test() { .run(); } +#[cargo_test] +fn build_script_feature_gate() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.1" + build = "build.rs" + "#, + ) + .file( + "build.rs", + r#"fn main() { + println!("cargo:rustc-check-cfg=cfg(foo)"); + println!("cargo:rustc-cfg=foo"); + }"#, + ) + .file("src/main.rs", "fn main() {}") + .build(); + + p.cargo("check") + .with_stderr_contains("warning[..]cargo:rustc-check-cfg requires -Zcheck-cfg flag") + .with_status(0) + .run(); +} + #[cargo_test(nightly, reason = "--check-cfg is unstable")] fn config_valid() { let p = project() @@ -467,3 +530,32 @@ fn config_invalid() { .with_status(101) .run(); } + +#[cargo_test] +fn config_feature_gate() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.1.0" + + [features] + f_a = [] + "#, + ) + .file("src/main.rs", "fn main() {}") + .file( + ".cargo/config.toml", + r#" + [unstable] + check-cfg = true + "#, + ) + .build(); + + p.cargo("check -v") + .with_stderr_does_not_contain("--check-cfg") + .run(); +}