Skip to content

Commit 431db31

Browse files
committed
Auto merge of #13958 - Urgau:check-cfg-config-fingerprint, r=epage
Include `lints.rust.unexpected_cfgs.check-cfg` in the fingerprint ### What does this PR try to resolve? When changing the `--check-cfg` args in the `lints.rust.unexpected_cfgs.check-cfg` lint config, the build should be restarted as the arguments we pass to the compiler change, and they can change the diagnostics output by generating new or removing some `unexpected_cfgs` warning(s). ### How should we test and review this PR? Look at the before and after test (separate commit). ### Additional information Similar to #13012 which did that for the declared features. Contrary to that PR, I didn't add a new `DirtyReason` variant, since even the `[lints]` table didn't get one. r? `@epage`
2 parents 2415192 + dfb69e6 commit 431db31

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

src/cargo/core/compiler/fingerprint/mod.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
//! config settings[^5] | ✓ |
8181
//! is_std | | ✓
8282
//! `[lints]` table[^6] | ✓ |
83+
//! `[lints.rust.unexpected_cfgs.check-cfg]` | ✓ |
8384
//!
8485
//! [^1]: Build script and bin dependencies are not included.
8586
//!
@@ -1420,12 +1421,34 @@ fn calculate_normal(
14201421
}
14211422
.to_vec();
14221423

1424+
// Include all the args from `[lints.rust.unexpected_cfgs.check-cfg]`
1425+
//
1426+
// HACK(#13975): duplicating the lookup logic here until `--check-cfg` is supported
1427+
// on Cargo's MSRV and we can centralize the logic in `lints_to_rustflags`
1428+
let mut lint_check_cfg = Vec::new();
1429+
if let Ok(Some(lints)) = unit.pkg.manifest().resolved_toml().resolved_lints() {
1430+
if let Some(rust_lints) = lints.get("rust") {
1431+
if let Some(unexpected_cfgs) = rust_lints.get("unexpected_cfgs") {
1432+
if let Some(config) = unexpected_cfgs.config() {
1433+
if let Some(check_cfg) = config.get("check-cfg") {
1434+
if let Ok(check_cfgs) =
1435+
toml::Value::try_into::<Vec<String>>(check_cfg.clone())
1436+
{
1437+
lint_check_cfg = check_cfgs;
1438+
}
1439+
}
1440+
}
1441+
}
1442+
}
1443+
}
1444+
14231445
let profile_hash = util::hash_u64((
14241446
&unit.profile,
14251447
unit.mode,
14261448
build_runner.bcx.extra_args_for(unit),
14271449
build_runner.lto[unit],
14281450
unit.pkg.manifest().lint_rustflags(),
1451+
lint_check_cfg,
14291452
));
14301453
// Include metadata since it is exposed as environment variables.
14311454
let m = unit.pkg.manifest().metadata();

tests/testsuite/check_cfg.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -824,3 +824,52 @@ fn config_features_and_build_script() {
824824
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs")) // Cargo well known
825825
.run();
826826
}
827+
828+
#[cargo_test(>=1.79, reason = "--check-cfg was stabilized in Rust 1.79")]
829+
fn config_fingerprint() {
830+
let p = project()
831+
.file(
832+
"Cargo.toml",
833+
r#"
834+
[package]
835+
name = "foo"
836+
version = "0.1.0"
837+
edition = "2015"
838+
839+
[lints.rust]
840+
unexpected_cfgs = { level = "warn", check-cfg = ["cfg(bar)"] }
841+
"#,
842+
)
843+
.file("src/lib.rs", "fn entry() {}")
844+
.build();
845+
846+
p.cargo("check -v")
847+
.with_stderr_contains(x!("rustc" => "cfg" of "bar"))
848+
.run();
849+
850+
p.cargo("check -v")
851+
.with_stderr_does_not_contain("[..]rustc[..]")
852+
.run();
853+
854+
// checking that changing the `check-cfg` config does invalid the fingerprint
855+
p.change_file(
856+
"Cargo.toml",
857+
r#"
858+
[package]
859+
name = "foo"
860+
version = "0.1.0"
861+
edition = "2015"
862+
863+
[lints.rust]
864+
unexpected_cfgs = { level = "warn", check-cfg = ["cfg(bar)", "cfg(foo)"] }
865+
"#,
866+
);
867+
868+
p.cargo("check -v")
869+
// we check that the fingerprint is indeed dirty
870+
.with_stderr_contains("[..]Dirty[..]the profile configuration changed")
871+
// that cause rustc to be called again with the new check-cfg args
872+
.with_stderr_contains(x!("rustc" => "cfg" of "bar"))
873+
.with_stderr_contains(x!("rustc" => "cfg" of "foo"))
874+
.run();
875+
}

0 commit comments

Comments
 (0)