Skip to content

Commit

Permalink
Auto merge of #12884 - Urgau:outdated-option-warn-check-cfg, r=epage
Browse files Browse the repository at this point in the history
Remove outdated option to `-Zcheck-cfg` warnings

Forgot to remove those in #12845.

Note: Would it make sense to have feature-gate tests for those? and if so what would be the recommended way?
  • Loading branch information
bors committed Oct 27, 2023
2 parents fcc3786 + e396904 commit de54757
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/cargo/core/compiler/custom_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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" => {
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/util/config/target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
))?;
}
Expand Down
92 changes: 92 additions & 0 deletions tests/testsuite/check_cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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();
}

0 comments on commit de54757

Please sign in to comment.