Skip to content

Commit de54757

Browse files
committed
Auto merge of #12884 - Urgau:outdated-option-warn-check-cfg, r=epage
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?
2 parents fcc3786 + e396904 commit de54757

File tree

3 files changed

+94
-2
lines changed

3 files changed

+94
-2
lines changed

src/cargo/core/compiler/custom_build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,7 @@ impl BuildOutput {
803803
if extra_check_cfg {
804804
check_cfgs.push(value.to_string());
805805
} else {
806-
warnings.push(format!("cargo:{} requires -Zcheck-cfg=output flag", key));
806+
warnings.push(format!("cargo:{} requires -Zcheck-cfg flag", key));
807807
}
808808
}
809809
"rustc-env" => {

src/cargo/util/config/target.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ fn parse_links_overrides(
208208
output.check_cfgs.extend(list.iter().map(|v| v.0.clone()));
209209
} else {
210210
config.shell().warn(format!(
211-
"target config `{}.{}` requires -Zcheck-cfg=output flag",
211+
"target config `{}.{}` requires -Zcheck-cfg flag",
212212
target_key, key
213213
))?;
214214
}

tests/testsuite/check_cfg.rs

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,41 @@ fn build_script_override() {
354354
.run();
355355
}
356356

357+
#[cargo_test]
358+
fn build_script_override_feature_gate() {
359+
let target = cargo_test_support::rustc_host();
360+
361+
let p = project()
362+
.file(
363+
"Cargo.toml",
364+
r#"
365+
[package]
366+
name = "foo"
367+
version = "0.1.0"
368+
links = "a"
369+
"#,
370+
)
371+
.file("src/main.rs", "fn main() {}")
372+
.file("build.rs", "fn main() {}")
373+
.file(
374+
".cargo/config",
375+
&format!(
376+
r#"
377+
[target.{}.a]
378+
rustc-check-cfg = ["cfg(foo)"]
379+
"#,
380+
target
381+
),
382+
)
383+
.build();
384+
385+
p.cargo("check")
386+
.with_stderr_contains(
387+
"warning: target config[..]rustc-check-cfg[..] requires -Zcheck-cfg flag",
388+
)
389+
.run();
390+
}
391+
357392
#[cargo_test(nightly, reason = "--check-cfg is unstable")]
358393
fn build_script_test() {
359394
let p = project()
@@ -409,6 +444,34 @@ fn build_script_test() {
409444
.run();
410445
}
411446

447+
#[cargo_test]
448+
fn build_script_feature_gate() {
449+
let p = project()
450+
.file(
451+
"Cargo.toml",
452+
r#"
453+
[package]
454+
name = "foo"
455+
version = "0.0.1"
456+
build = "build.rs"
457+
"#,
458+
)
459+
.file(
460+
"build.rs",
461+
r#"fn main() {
462+
println!("cargo:rustc-check-cfg=cfg(foo)");
463+
println!("cargo:rustc-cfg=foo");
464+
}"#,
465+
)
466+
.file("src/main.rs", "fn main() {}")
467+
.build();
468+
469+
p.cargo("check")
470+
.with_stderr_contains("warning[..]cargo:rustc-check-cfg requires -Zcheck-cfg flag")
471+
.with_status(0)
472+
.run();
473+
}
474+
412475
#[cargo_test(nightly, reason = "--check-cfg is unstable")]
413476
fn config_valid() {
414477
let p = project()
@@ -467,3 +530,32 @@ fn config_invalid() {
467530
.with_status(101)
468531
.run();
469532
}
533+
534+
#[cargo_test]
535+
fn config_feature_gate() {
536+
let p = project()
537+
.file(
538+
"Cargo.toml",
539+
r#"
540+
[package]
541+
name = "foo"
542+
version = "0.1.0"
543+
544+
[features]
545+
f_a = []
546+
"#,
547+
)
548+
.file("src/main.rs", "fn main() {}")
549+
.file(
550+
".cargo/config.toml",
551+
r#"
552+
[unstable]
553+
check-cfg = true
554+
"#,
555+
)
556+
.build();
557+
558+
p.cargo("check -v")
559+
.with_stderr_does_not_contain("--check-cfg")
560+
.run();
561+
}

0 commit comments

Comments
 (0)