@@ -265,6 +265,40 @@ impl HygieneData {
265265 scope
266266 }
267267
268+ fn apply_mark_with_transparency ( & mut self , ctxt : SyntaxContext , mark : Mark ,
269+ transparency : Transparency ) -> SyntaxContext {
270+ assert_ne ! ( mark, Mark :: root( ) ) ;
271+ if transparency == Transparency :: Opaque {
272+ return self . apply_mark_internal ( ctxt, mark, transparency) ;
273+ }
274+
275+ let call_site_ctxt =
276+ self . expn_info ( mark) . map_or ( SyntaxContext :: empty ( ) , |info| info. call_site . ctxt ( ) ) ;
277+ let mut call_site_ctxt = if transparency == Transparency :: SemiTransparent {
278+ self . modern ( call_site_ctxt)
279+ } else {
280+ self . modern_and_legacy ( call_site_ctxt)
281+ } ;
282+
283+ if call_site_ctxt == SyntaxContext :: empty ( ) {
284+ return self . apply_mark_internal ( ctxt, mark, transparency) ;
285+ }
286+
287+ // Otherwise, `mark` is a macros 1.0 definition and the call site is in a
288+ // macros 2.0 expansion, i.e., a macros 1.0 invocation is in a macros 2.0 definition.
289+ //
290+ // In this case, the tokens from the macros 1.0 definition inherit the hygiene
291+ // at their invocation. That is, we pretend that the macros 1.0 definition
292+ // was defined at its invocation (i.e., inside the macros 2.0 definition)
293+ // so that the macros 2.0 definition remains hygienic.
294+ //
295+ // See the example at `test/run-pass/hygiene/legacy_interaction.rs`.
296+ for ( mark, transparency) in self . marks ( ctxt) {
297+ call_site_ctxt = self . apply_mark_internal ( call_site_ctxt, mark, transparency) ;
298+ }
299+ self . apply_mark_internal ( call_site_ctxt, mark, transparency)
300+ }
301+
268302 fn apply_mark_internal ( & mut self , ctxt : SyntaxContext , mark : Mark , transparency : Transparency )
269303 -> SyntaxContext {
270304 let syntax_contexts = & mut self . syntax_contexts ;
@@ -382,41 +416,7 @@ impl SyntaxContext {
382416 /// Extend a syntax context with a given mark and transparency
383417 pub fn apply_mark_with_transparency ( self , mark : Mark , transparency : Transparency )
384418 -> SyntaxContext {
385- assert_ne ! ( mark, Mark :: root( ) ) ;
386- if transparency == Transparency :: Opaque {
387- return self . apply_mark_internal ( mark, transparency) ;
388- }
389-
390- let call_site_ctxt =
391- mark. expn_info ( ) . map_or ( SyntaxContext :: empty ( ) , |info| info. call_site . ctxt ( ) ) ;
392- let call_site_ctxt = if transparency == Transparency :: SemiTransparent {
393- call_site_ctxt. modern ( )
394- } else {
395- call_site_ctxt. modern_and_legacy ( )
396- } ;
397-
398- if call_site_ctxt == SyntaxContext :: empty ( ) {
399- return self . apply_mark_internal ( mark, transparency) ;
400- }
401-
402- // Otherwise, `mark` is a macros 1.0 definition and the call site is in a
403- // macros 2.0 expansion, i.e., a macros 1.0 invocation is in a macros 2.0 definition.
404- //
405- // In this case, the tokens from the macros 1.0 definition inherit the hygiene
406- // at their invocation. That is, we pretend that the macros 1.0 definition
407- // was defined at its invocation (i.e., inside the macros 2.0 definition)
408- // so that the macros 2.0 definition remains hygienic.
409- //
410- // See the example at `test/run-pass/hygiene/legacy_interaction.rs`.
411- let mut ctxt = call_site_ctxt;
412- for ( mark, transparency) in self . marks ( ) {
413- ctxt = ctxt. apply_mark_internal ( mark, transparency) ;
414- }
415- ctxt. apply_mark_internal ( mark, transparency)
416- }
417-
418- fn apply_mark_internal ( self , mark : Mark , transparency : Transparency ) -> SyntaxContext {
419- HygieneData :: with ( |data| data. apply_mark_internal ( self , mark, transparency) )
419+ HygieneData :: with ( |data| data. apply_mark_with_transparency ( self , mark, transparency) )
420420 }
421421
422422 /// Pulls a single mark off of the syntax context. This effectively moves the
0 commit comments