@@ -15,7 +15,9 @@ use rustc_ast::{
1515 NodeId , PatKind , StmtKind , TyKind , DUMMY_NODE_ID ,
1616} ;
1717use rustc_ast_pretty:: pprust;
18+ use rustc_data_structures:: fingerprint:: Fingerprint ;
1819use rustc_data_structures:: flat_map_in_place:: FlatMapInPlace ;
20+ use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher } ;
1921use rustc_data_structures:: sync:: Lrc ;
2022use rustc_errors:: PResult ;
2123use rustc_feature:: Features ;
@@ -396,14 +398,32 @@ pub struct MacroExpander<'a, 'b> {
396398 monotonic : bool , // cf. `cx.monotonic_expander()`
397399}
398400
401+ #[ tracing:: instrument( level = "debug" , skip( tcx) ) ]
399402pub fn expand_legacy_bang < ' tcx > (
400403 tcx : TyCtxt < ' tcx > ,
401- key : ( LocalExpnId , LocalExpnId ) ,
404+ key : ( LocalExpnId , LocalExpnId , Fingerprint ) ,
402405) -> 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+
405410 let map = tcx. macro_map . borrow ( ) ;
406411 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+
407427 expander
408428 . expand ( & tcx. sess , * span, arg. clone ( ) , current_expansion)
409429 . map ( |( tts, i) | ( tcx. arena . alloc ( tts) as & TokenStream , i) )
0 commit comments