Skip to content

Commit f32f43d

Browse files
committed
Avoid fingerprint invalidation when reordering the declared features
1 parent 7d1fc45 commit f32f43d

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1443,7 +1443,9 @@ fn calculate_normal(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Finger
14431443
allow_features.hash(&mut config);
14441444
}
14451445
let compile_kind = unit.kind.fingerprint_hash();
1446-
let declared_features = unit.pkg.summary().features().keys().collect::<Vec<_>>();
1446+
let mut declared_features = unit.pkg.summary().features().keys().collect::<Vec<_>>();
1447+
declared_features.sort(); // to avoid useless rebuild if the user orders it's features
1448+
// differently
14471449
Ok(Fingerprint {
14481450
rustc: util::hash_u64(&cx.bcx.rustc().verbose_version),
14491451
target: util::hash_u64(&unit.target),

tests/testsuite/check_cfg.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,25 @@ fn features_fingerprint() {
165165
.with_stderr_does_not_contain("[..]unexpected_cfgs[..]")
166166
.run();
167167

168+
p.cargo("check -v -Zcheck-cfg")
169+
.masquerade_as_nightly_cargo(&["check-cfg"])
170+
.with_stderr_does_not_contain("[..]rustc[..]")
171+
.run();
172+
173+
// checking that re-ordering the features does not invalid the fingerprint
174+
p.change_file(
175+
"Cargo.toml",
176+
r#"
177+
[package]
178+
name = "foo"
179+
version = "0.1.0"
180+
181+
[features]
182+
f_b = []
183+
f_a = []
184+
"#,
185+
);
186+
168187
p.cargo("check -v -Zcheck-cfg")
169188
.masquerade_as_nightly_cargo(&["check-cfg"])
170189
.with_stderr_does_not_contain("[..]rustc[..]")

0 commit comments

Comments
 (0)