Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove outdated option to -Zcheck-cfg warnings #12884

Merged
merged 2 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
Loading