@@ -15,7 +15,9 @@ use rustc_ast::{
15
15
NodeId , PatKind , StmtKind , TyKind , DUMMY_NODE_ID ,
16
16
} ;
17
17
use rustc_ast_pretty:: pprust;
18
+ use rustc_data_structures:: fingerprint:: Fingerprint ;
18
19
use rustc_data_structures:: flat_map_in_place:: FlatMapInPlace ;
20
+ use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher } ;
19
21
use rustc_data_structures:: sync:: Lrc ;
20
22
use rustc_errors:: PResult ;
21
23
use rustc_feature:: Features ;
@@ -396,14 +398,32 @@ pub struct MacroExpander<'a, 'b> {
396
398
monotonic : bool , // cf. `cx.monotonic_expander()`
397
399
}
398
400
401
+ #[ tracing:: instrument( level = "debug" , skip( tcx) ) ]
399
402
pub fn expand_legacy_bang < ' tcx > (
400
403
tcx : TyCtxt < ' tcx > ,
401
- key : ( LocalExpnId , LocalExpnId ) ,
404
+ key : ( LocalExpnId , LocalExpnId , Fingerprint ) ,
402
405
) -> Result < ( & ' tcx TokenStream , usize ) , ( Span , ErrorGuaranteed ) > {
403
- let ( invoc_id, current_expansion) = dbg ! ( key) ;
404
- dbg ! ( invoc_id. to_expn_id( ) . expn_hash( ) , current_expansion. to_expn_id( ) . expn_hash( ) ) ;
406
+ use tracing:: debug;
407
+
408
+ let ( invoc_id, current_expansion, arg_fingerprint) = key;
409
+
405
410
let map = tcx. macro_map . borrow ( ) ;
406
411
let ( arg, span, expander) = map. get ( & invoc_id) . as_ref ( ) . unwrap ( ) ;
412
+ debug ! ( ?arg) ;
413
+
414
+ // this (i.e., debug-printing `span`) somehow made the test pass??
415
+ // tracing::debug!(?span);
416
+
417
+ let arg_hash: Fingerprint = tcx. with_stable_hashing_context ( |mut hcx| {
418
+ let mut hasher = StableHasher :: new ( ) ;
419
+ arg. flattened ( ) . hash_stable ( & mut hcx, & mut hasher) ;
420
+ hasher. finish ( )
421
+ } ) ;
422
+
423
+ // sanity-check, to make sure we're not running for (maybe) old arguments
424
+ // that were loaded from the cache. this would certainly be a bug.
425
+ assert_eq ! ( arg_fingerprint, arg_hash) ;
426
+
407
427
expander
408
428
. expand ( & tcx. sess , * span, arg. clone ( ) , current_expansion)
409
429
. map ( |( tts, i) | ( tcx. arena . alloc ( tts) as & TokenStream , i) )
0 commit comments