65
65
//! Target Name | ✓ | ✓
66
66
//! TargetKind (bin/lib/etc.) | ✓ | ✓
67
67
//! Enabled Features | ✓ | ✓
68
+ //! Declared Features | ✓ |
68
69
//! Immediate dependency’s hashes | ✓[^1] | ✓
69
70
//! [`CompileKind`] (host/target) | ✓ | ✓
70
71
//! __CARGO_DEFAULT_LIB_METADATA[^4] | | ✓
@@ -572,6 +573,8 @@ pub struct Fingerprint {
572
573
rustc : u64 ,
573
574
/// Sorted list of cfg features enabled.
574
575
features : String ,
576
+ /// Sorted list of all the declared cfg features.
577
+ declared_features : String ,
575
578
/// Hash of the `Target` struct, including the target name,
576
579
/// package-relative source path, edition, etc.
577
580
target : u64 ,
@@ -876,6 +879,7 @@ impl Fingerprint {
876
879
profile : 0 ,
877
880
path : 0 ,
878
881
features : String :: new ( ) ,
882
+ declared_features : String :: new ( ) ,
879
883
deps : Vec :: new ( ) ,
880
884
local : Mutex :: new ( Vec :: new ( ) ) ,
881
885
memoized_hash : Mutex :: new ( None ) ,
@@ -922,6 +926,12 @@ impl Fingerprint {
922
926
new : self . features . clone ( ) ,
923
927
} ;
924
928
}
929
+ if self . declared_features != old. declared_features {
930
+ return DirtyReason :: DeclaredFeaturesChanged {
931
+ old : old. declared_features . clone ( ) ,
932
+ new : self . declared_features . clone ( ) ,
933
+ } ;
934
+ }
925
935
if self . target != old. target {
926
936
return DirtyReason :: TargetConfigurationChanged ;
927
937
}
@@ -1200,6 +1210,7 @@ impl hash::Hash for Fingerprint {
1200
1210
let Fingerprint {
1201
1211
rustc,
1202
1212
ref features,
1213
+ ref declared_features,
1203
1214
target,
1204
1215
path,
1205
1216
profile,
@@ -1215,6 +1226,7 @@ impl hash::Hash for Fingerprint {
1215
1226
(
1216
1227
rustc,
1217
1228
features,
1229
+ declared_features,
1218
1230
target,
1219
1231
path,
1220
1232
profile,
@@ -1431,6 +1443,7 @@ fn calculate_normal(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Finger
1431
1443
allow_features. hash ( & mut config) ;
1432
1444
}
1433
1445
let compile_kind = unit. kind . fingerprint_hash ( ) ;
1446
+ let declared_features = unit. pkg . summary ( ) . features ( ) . keys ( ) . collect :: < Vec < _ > > ( ) ;
1434
1447
Ok ( Fingerprint {
1435
1448
rustc : util:: hash_u64 ( & cx. bcx . rustc ( ) . verbose_version ) ,
1436
1449
target : util:: hash_u64 ( & unit. target ) ,
@@ -1439,6 +1452,14 @@ fn calculate_normal(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Finger
1439
1452
// actually affect the output artifact so there's no need to hash it.
1440
1453
path : util:: hash_u64 ( path_args ( cx. bcx . ws , unit) . 0 ) ,
1441
1454
features : format ! ( "{:?}" , unit. features) ,
1455
+ // Note we curently only populate `declared_features` when `-Zcheck-cfg`
1456
+ // is passed since it's the only user-facing toggle that will make this
1457
+ // fingerprint relevant.
1458
+ declared_features : if cx. bcx . config . cli_unstable ( ) . check_cfg {
1459
+ format ! ( "{declared_features:?}" )
1460
+ } else {
1461
+ "" . to_string ( )
1462
+ } ,
1442
1463
deps,
1443
1464
local : Mutex :: new ( local) ,
1444
1465
memoized_hash : Mutex :: new ( None ) ,
0 commit comments