@@ -3,7 +3,7 @@ use crate::attr::{HasAttrs, Stability, Deprecation};
33use crate :: source_map:: SourceMap ;
44use crate :: edition:: Edition ;
55use crate :: ext:: expand:: { self , AstFragment , Invocation } ;
6- use crate :: ext:: hygiene:: { ExpnId , SyntaxContext , Transparency } ;
6+ use crate :: ext:: hygiene:: { ExpnId , Transparency } ;
77use crate :: mut_visit:: { self , MutVisitor } ;
88use crate :: parse:: { self , parser, DirectoryOwnership } ;
99use crate :: parse:: token;
@@ -760,23 +760,39 @@ impl<'a> ExtCtxt<'a> {
760760 pub fn call_site ( & self ) -> Span {
761761 self . current_expansion . id . expn_data ( ) . call_site
762762 }
763- pub fn backtrace ( & self ) -> SyntaxContext {
764- SyntaxContext :: root ( ) . apply_mark ( self . current_expansion . id )
763+
764+ /// Equivalent of `Span::def_site` from the proc macro API,
765+ /// except that the location is taken from the span passed as an argument.
766+ pub fn with_def_site_ctxt ( & self , span : Span ) -> Span {
767+ span. with_ctxt_from_mark ( self . current_expansion . id , Transparency :: Opaque )
768+ }
769+
770+ /// Equivalent of `Span::call_site` from the proc macro API,
771+ /// except that the location is taken from the span passed as an argument.
772+ pub fn with_call_site_ctxt ( & self , span : Span ) -> Span {
773+ span. with_ctxt_from_mark ( self . current_expansion . id , Transparency :: Transparent )
774+ }
775+
776+ /// Span with a context reproducing `macro_rules` hygiene (hygienic locals, unhygienic items).
777+ /// FIXME: This should be eventually replaced either with `with_def_site_ctxt` (preferably),
778+ /// or with `with_call_site_ctxt` (where necessary).
779+ pub fn with_legacy_ctxt ( & self , span : Span ) -> Span {
780+ span. with_ctxt_from_mark ( self . current_expansion . id , Transparency :: SemiTransparent )
765781 }
766782
767783 /// Returns span for the macro which originally caused the current expansion to happen.
768784 ///
769785 /// Stops backtracing at include! boundary.
770786 pub fn expansion_cause ( & self ) -> Option < Span > {
771- let mut ctxt = self . backtrace ( ) ;
787+ let mut expn_id = self . current_expansion . id ;
772788 let mut last_macro = None ;
773789 loop {
774- let expn_data = ctxt . outer_expn_data ( ) ;
790+ let expn_data = expn_id . expn_data ( ) ;
775791 // Stop going up the backtrace once include! is encountered
776792 if expn_data. is_root ( ) || expn_data. kind . descr ( ) == sym:: include {
777793 break ;
778794 }
779- ctxt = expn_data. call_site . ctxt ( ) ;
795+ expn_id = expn_data. call_site . ctxt ( ) . outer_expn ( ) ;
780796 last_macro = Some ( expn_data. call_site ) ;
781797 }
782798 last_macro
@@ -865,7 +881,7 @@ impl<'a> ExtCtxt<'a> {
865881 ast:: Ident :: from_str ( st)
866882 }
867883 pub fn std_path ( & self , components : & [ Symbol ] ) -> Vec < ast:: Ident > {
868- let def_site = DUMMY_SP . apply_mark ( self . current_expansion . id ) ;
884+ let def_site = self . with_def_site_ctxt ( DUMMY_SP ) ;
869885 iter:: once ( Ident :: new ( kw:: DollarCrate , def_site) )
870886 . chain ( components. iter ( ) . map ( |& s| Ident :: with_dummy_span ( s) ) )
871887 . collect ( )
0 commit comments