Skip to content

Commit

Permalink
Avoid fingerprint invalidation when reordering the declared features
Browse files Browse the repository at this point in the history
  • Loading branch information
Urgau committed Dec 1, 2023
1 parent 7d1fc45 commit f32f43d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/cargo/core/compiler/fingerprint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1443,7 +1443,9 @@ fn calculate_normal(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Finger
allow_features.hash(&mut config);
}
let compile_kind = unit.kind.fingerprint_hash();
let declared_features = unit.pkg.summary().features().keys().collect::<Vec<_>>();
let mut declared_features = unit.pkg.summary().features().keys().collect::<Vec<_>>();
declared_features.sort(); // to avoid useless rebuild if the user orders it's features
// differently
Ok(Fingerprint {
rustc: util::hash_u64(&cx.bcx.rustc().verbose_version),
target: util::hash_u64(&unit.target),
Expand Down
19 changes: 19 additions & 0 deletions tests/testsuite/check_cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,25 @@ fn features_fingerprint() {
.with_stderr_does_not_contain("[..]unexpected_cfgs[..]")
.run();

p.cargo("check -v -Zcheck-cfg")
.masquerade_as_nightly_cargo(&["check-cfg"])
.with_stderr_does_not_contain("[..]rustc[..]")
.run();

// checking that re-ordering the features does not invalid the fingerprint
p.change_file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.1.0"
[features]
f_b = []
f_a = []
"#,
);

p.cargo("check -v -Zcheck-cfg")
.masquerade_as_nightly_cargo(&["check-cfg"])
.with_stderr_does_not_contain("[..]rustc[..]")
Expand Down

0 comments on commit f32f43d

Please sign in to comment.