@@ -13,19 +13,24 @@ use rustc_errors::DiagnosticBuilder;
13
13
use rustc_errors:: { pluralize, PResult } ;
14
14
use rustc_span:: hygiene:: { LocalExpnId , Transparency } ;
15
15
use rustc_span:: symbol:: { sym, Ident , MacroRulesNormalizedIdent } ;
16
- use rustc_span:: Span ;
16
+ use rustc_span:: { Span , SyntaxContext } ;
17
17
18
18
use smallvec:: { smallvec, SmallVec } ;
19
19
use std:: mem;
20
20
21
21
// A Marker adds the given mark to the syntax context.
22
- struct Marker ( LocalExpnId , Transparency ) ;
22
+ struct Marker ( LocalExpnId , Transparency , FxHashMap < SyntaxContext , SyntaxContext > ) ;
23
23
24
24
impl MutVisitor for Marker {
25
25
const VISIT_TOKENS : bool = true ;
26
26
27
27
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) ;
29
34
}
30
35
}
31
36
@@ -123,7 +128,7 @@ pub(super) fn transcribe<'a>(
123
128
// again, and we are done transcribing.
124
129
let mut result: Vec < TokenTree > = Vec :: new ( ) ;
125
130
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 ( ) ) ;
127
132
128
133
loop {
129
134
// Look at the last frame on the stack.
0 commit comments