@@ -31,7 +31,7 @@ use std::collections::btree_map::{
3131} ;
3232use std:: collections:: { BTreeMap , BTreeSet } ;
3333use std:: fmt;
34- use std:: hash:: { Hash , Hasher } ;
34+ use std:: hash:: Hash ;
3535use std:: iter:: { self , FromIterator } ;
3636use std:: path:: { Path , PathBuf } ;
3737use std:: str:: { self , FromStr } ;
@@ -328,19 +328,9 @@ impl Default for TrimmedDefPaths {
328328/// *Do not* switch `BTreeMap` out for an unsorted container type! That would break
329329/// dependency tracking for command-line arguments. Also only hash keys, since tracking
330330/// should only depend on the output types, not the paths they're written to.
331- #[ derive( Clone , Debug ) ]
331+ #[ derive( Clone , Debug , Hash ) ]
332332pub struct OutputTypes ( BTreeMap < OutputType , Option < PathBuf > > ) ;
333333
334- impl Hash for OutputTypes {
335- fn hash < H : Hasher > ( & self , hasher : & mut H ) {
336- for k in self . keys ( ) {
337- k. hash ( hasher) ;
338- }
339- }
340- }
341-
342- impl_stable_hash_via_hash ! ( OutputTypes ) ;
343-
344334impl OutputTypes {
345335 pub fn new ( entries : & [ ( OutputType , Option < PathBuf > ) ] ) -> OutputTypes {
346336 OutputTypes ( BTreeMap :: from_iter ( entries. iter ( ) . map ( |& ( k, ref v) | ( k, v. clone ( ) ) ) ) )
@@ -2436,8 +2426,8 @@ crate mod dep_tracking {
24362426 use super :: LdImpl ;
24372427 use super :: {
24382428 CFGuard , CrateType , DebugInfo , ErrorOutputType , InstrumentCoverage , LinkerPluginLto ,
2439- LtoCli , OptLevel , OutputTypes , Passes , SourceFileHashAlgorithm , SwitchWithOptPath ,
2440- SymbolManglingVersion , TrimmedDefPaths ,
2429+ LtoCli , OptLevel , OutputType , OutputTypes , Passes , SourceFileHashAlgorithm ,
2430+ SwitchWithOptPath , SymbolManglingVersion , TrimmedDefPaths ,
24412431 } ;
24422432 use crate :: lint;
24432433 use crate :: options:: WasiExecModel ;
@@ -2453,25 +2443,35 @@ crate mod dep_tracking {
24532443 use std:: path:: PathBuf ;
24542444
24552445 pub trait DepTrackingHash {
2456- fn hash ( & self , hasher : & mut DefaultHasher , error_format : ErrorOutputType ) ;
2446+ fn hash (
2447+ & self ,
2448+ hasher : & mut DefaultHasher ,
2449+ error_format : ErrorOutputType ,
2450+ for_crate_hash : bool ,
2451+ ) ;
24572452 }
24582453
24592454 macro_rules! impl_dep_tracking_hash_via_hash {
24602455 ( $( $t: ty) ,+ $( , ) ?) => { $(
24612456 impl DepTrackingHash for $t {
2462- fn hash( & self , hasher: & mut DefaultHasher , _: ErrorOutputType ) {
2457+ fn hash( & self , hasher: & mut DefaultHasher , _: ErrorOutputType , _for_crate_hash : bool ) {
24632458 Hash :: hash( self , hasher) ;
24642459 }
24652460 }
24662461 ) +} ;
24672462 }
24682463
24692464 impl < T : DepTrackingHash > DepTrackingHash for Option < T > {
2470- fn hash ( & self , hasher : & mut DefaultHasher , error_format : ErrorOutputType ) {
2465+ fn hash (
2466+ & self ,
2467+ hasher : & mut DefaultHasher ,
2468+ error_format : ErrorOutputType ,
2469+ for_crate_hash : bool ,
2470+ ) {
24712471 match self {
24722472 Some ( x) => {
24732473 Hash :: hash ( & 1 , hasher) ;
2474- DepTrackingHash :: hash ( x, hasher, error_format) ;
2474+ DepTrackingHash :: hash ( x, hasher, error_format, for_crate_hash ) ;
24752475 }
24762476 None => Hash :: hash ( & 0 , hasher) ,
24772477 }
@@ -2501,7 +2501,6 @@ crate mod dep_tracking {
25012501 LtoCli ,
25022502 DebugInfo ,
25032503 UnstableFeatures ,
2504- OutputTypes ,
25052504 NativeLib ,
25062505 NativeLibKind ,
25072506 SanitizerSet ,
@@ -2515,18 +2514,24 @@ crate mod dep_tracking {
25152514 SourceFileHashAlgorithm ,
25162515 TrimmedDefPaths ,
25172516 Option <LdImpl >,
2517+ OutputType ,
25182518 ) ;
25192519
25202520 impl < T1 , T2 > DepTrackingHash for ( T1 , T2 )
25212521 where
25222522 T1 : DepTrackingHash ,
25232523 T2 : DepTrackingHash ,
25242524 {
2525- fn hash ( & self , hasher : & mut DefaultHasher , error_format : ErrorOutputType ) {
2525+ fn hash (
2526+ & self ,
2527+ hasher : & mut DefaultHasher ,
2528+ error_format : ErrorOutputType ,
2529+ for_crate_hash : bool ,
2530+ ) {
25262531 Hash :: hash ( & 0 , hasher) ;
2527- DepTrackingHash :: hash ( & self . 0 , hasher, error_format) ;
2532+ DepTrackingHash :: hash ( & self . 0 , hasher, error_format, for_crate_hash ) ;
25282533 Hash :: hash ( & 1 , hasher) ;
2529- DepTrackingHash :: hash ( & self . 1 , hasher, error_format) ;
2534+ DepTrackingHash :: hash ( & self . 1 , hasher, error_format, for_crate_hash ) ;
25302535 }
25312536 }
25322537
@@ -2536,22 +2541,49 @@ crate mod dep_tracking {
25362541 T2 : DepTrackingHash ,
25372542 T3 : DepTrackingHash ,
25382543 {
2539- fn hash ( & self , hasher : & mut DefaultHasher , error_format : ErrorOutputType ) {
2544+ fn hash (
2545+ & self ,
2546+ hasher : & mut DefaultHasher ,
2547+ error_format : ErrorOutputType ,
2548+ for_crate_hash : bool ,
2549+ ) {
25402550 Hash :: hash ( & 0 , hasher) ;
2541- DepTrackingHash :: hash ( & self . 0 , hasher, error_format) ;
2551+ DepTrackingHash :: hash ( & self . 0 , hasher, error_format, for_crate_hash ) ;
25422552 Hash :: hash ( & 1 , hasher) ;
2543- DepTrackingHash :: hash ( & self . 1 , hasher, error_format) ;
2553+ DepTrackingHash :: hash ( & self . 1 , hasher, error_format, for_crate_hash ) ;
25442554 Hash :: hash ( & 2 , hasher) ;
2545- DepTrackingHash :: hash ( & self . 2 , hasher, error_format) ;
2555+ DepTrackingHash :: hash ( & self . 2 , hasher, error_format, for_crate_hash ) ;
25462556 }
25472557 }
25482558
25492559 impl < T : DepTrackingHash > DepTrackingHash for Vec < T > {
2550- fn hash ( & self , hasher : & mut DefaultHasher , error_format : ErrorOutputType ) {
2560+ fn hash (
2561+ & self ,
2562+ hasher : & mut DefaultHasher ,
2563+ error_format : ErrorOutputType ,
2564+ for_crate_hash : bool ,
2565+ ) {
25512566 Hash :: hash ( & self . len ( ) , hasher) ;
25522567 for ( index, elem) in self . iter ( ) . enumerate ( ) {
25532568 Hash :: hash ( & index, hasher) ;
2554- DepTrackingHash :: hash ( elem, hasher, error_format) ;
2569+ DepTrackingHash :: hash ( elem, hasher, error_format, for_crate_hash) ;
2570+ }
2571+ }
2572+ }
2573+
2574+ impl DepTrackingHash for OutputTypes {
2575+ fn hash (
2576+ & self ,
2577+ hasher : & mut DefaultHasher ,
2578+ error_format : ErrorOutputType ,
2579+ for_crate_hash : bool ,
2580+ ) {
2581+ Hash :: hash ( & self . 0 . len ( ) , hasher) ;
2582+ for ( key, val) in & self . 0 {
2583+ DepTrackingHash :: hash ( key, hasher, error_format, for_crate_hash) ;
2584+ if !for_crate_hash {
2585+ DepTrackingHash :: hash ( val, hasher, error_format, for_crate_hash) ;
2586+ }
25552587 }
25562588 }
25572589 }
@@ -2561,13 +2593,14 @@ crate mod dep_tracking {
25612593 sub_hashes : BTreeMap < & ' static str , & dyn DepTrackingHash > ,
25622594 hasher : & mut DefaultHasher ,
25632595 error_format : ErrorOutputType ,
2596+ for_crate_hash : bool ,
25642597 ) {
25652598 for ( key, sub_hash) in sub_hashes {
25662599 // Using Hash::hash() instead of DepTrackingHash::hash() is fine for
25672600 // the keys, as they are just plain strings
25682601 Hash :: hash ( & key. len ( ) , hasher) ;
25692602 Hash :: hash ( key, hasher) ;
2570- sub_hash. hash ( hasher, error_format) ;
2603+ sub_hash. hash ( hasher, error_format, for_crate_hash ) ;
25712604 }
25722605 }
25732606}
0 commit comments