6565//! Target Name | ✓ | ✓
6666//! TargetKind (bin/lib/etc.) | ✓ | ✓
6767//! Enabled Features | ✓ | ✓
68+ //! Declared Features | ✓ |
6869//! Immediate dependency’s hashes | ✓[^1] | ✓
6970//! [`CompileKind`] (host/target) | ✓ | ✓
7071//! __CARGO_DEFAULT_LIB_METADATA[^4] | | ✓
@@ -572,6 +573,8 @@ pub struct Fingerprint {
572573 rustc : u64 ,
573574 /// Sorted list of cfg features enabled.
574575 features : String ,
576+ /// Sorted list of all the declared cfg features.
577+ declared_features : String ,
575578 /// Hash of the `Target` struct, including the target name,
576579 /// package-relative source path, edition, etc.
577580 target : u64 ,
@@ -876,6 +879,7 @@ impl Fingerprint {
876879 profile : 0 ,
877880 path : 0 ,
878881 features : String :: new ( ) ,
882+ declared_features : String :: new ( ) ,
879883 deps : Vec :: new ( ) ,
880884 local : Mutex :: new ( Vec :: new ( ) ) ,
881885 memoized_hash : Mutex :: new ( None ) ,
@@ -922,6 +926,12 @@ impl Fingerprint {
922926 new : self . features . clone ( ) ,
923927 } ;
924928 }
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+ }
925935 if self . target != old. target {
926936 return DirtyReason :: TargetConfigurationChanged ;
927937 }
@@ -1200,6 +1210,7 @@ impl hash::Hash for Fingerprint {
12001210 let Fingerprint {
12011211 rustc,
12021212 ref features,
1213+ ref declared_features,
12031214 target,
12041215 path,
12051216 profile,
@@ -1215,6 +1226,7 @@ impl hash::Hash for Fingerprint {
12151226 (
12161227 rustc,
12171228 features,
1229+ declared_features,
12181230 target,
12191231 path,
12201232 profile,
@@ -1431,6 +1443,7 @@ fn calculate_normal(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Finger
14311443 allow_features. hash ( & mut config) ;
14321444 }
14331445 let compile_kind = unit. kind . fingerprint_hash ( ) ;
1446+ let declared_features = unit. pkg . summary ( ) . features ( ) . keys ( ) . collect :: < Vec < _ > > ( ) ;
14341447 Ok ( Fingerprint {
14351448 rustc : util:: hash_u64 ( & cx. bcx . rustc ( ) . verbose_version ) ,
14361449 target : util:: hash_u64 ( & unit. target ) ,
@@ -1439,6 +1452,14 @@ fn calculate_normal(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Finger
14391452 // actually affect the output artifact so there's no need to hash it.
14401453 path : util:: hash_u64 ( path_args ( cx. bcx . ws , unit) . 0 ) ,
14411454 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+ } ,
14421463 deps,
14431464 local : Mutex :: new ( local) ,
14441465 memoized_hash : Mutex :: new ( None ) ,
0 commit comments