@@ -13,19 +13,24 @@ use rustc_errors::DiagnosticBuilder;
1313use rustc_errors:: { pluralize, PResult } ;
1414use rustc_span:: hygiene:: { LocalExpnId , Transparency } ;
1515use rustc_span:: symbol:: { sym, Ident , MacroRulesNormalizedIdent } ;
16- use rustc_span:: Span ;
16+ use rustc_span:: { Span , SyntaxContext } ;
1717
1818use smallvec:: { smallvec, SmallVec } ;
1919use std:: mem;
2020
2121// A Marker adds the given mark to the syntax context.
22- struct Marker ( LocalExpnId , Transparency ) ;
22+ struct Marker ( LocalExpnId , Transparency , FxHashMap < SyntaxContext , SyntaxContext > ) ;
2323
2424impl MutVisitor for Marker {
2525 const VISIT_TOKENS : bool = true ;
2626
2727 fn visit_span ( & mut self , span : & mut Span ) {
28- * span = span. apply_mark ( self . 0 . to_expn_id ( ) , self . 1 )
28+ let Marker ( expn_id, transparency, ref mut cache) = * self ;
29+ let data = span. data ( ) ;
30+ let marked_ctxt = * cache
31+ . entry ( data. ctxt )
32+ . or_insert_with ( || data. ctxt . apply_mark ( expn_id. to_expn_id ( ) , transparency) ) ;
33+ * span = data. with_ctxt ( marked_ctxt) ;
2934 }
3035}
3136
@@ -123,7 +128,7 @@ pub(super) fn transcribe<'a>(
123128 // again, and we are done transcribing.
124129 let mut result: Vec < TokenTree > = Vec :: new ( ) ;
125130 let mut result_stack = Vec :: new ( ) ;
126- let mut marker = Marker ( cx. current_expansion . id , transparency) ;
131+ let mut marker = Marker ( cx. current_expansion . id , transparency, Default :: default ( ) ) ;
127132
128133 loop {
129134 // Look at the last frame on the stack.
0 commit comments