@@ -14,7 +14,6 @@ use rustc_parse::lexer::nfc_normalize;
1414use rustc_parse:: { nt_to_tokenstream, parse_stream_from_source_str} ;
1515use rustc_session:: parse:: ParseSess ;
1616use rustc_span:: def_id:: CrateNum ;
17- use rustc_span:: hygiene:: ExpnId ;
1817use rustc_span:: hygiene:: ExpnKind ;
1918use rustc_span:: symbol:: { self , kw, sym, Symbol } ;
2019use rustc_span:: { BytePos , FileName , MultiSpan , Pos , RealFileName , SourceFile , Span } ;
@@ -363,26 +362,20 @@ pub(crate) struct Rustc<'a> {
363362 mixed_site : Span ,
364363 span_debug : bool ,
365364 krate : CrateNum ,
366- expn_id : ExpnId ,
367365 rebased_spans : FxHashMap < usize , Span > ,
368366}
369367
370368impl < ' a > Rustc < ' a > {
371- pub fn new ( cx : & ' a ExtCtxt < ' _ > , krate : CrateNum ) -> Self {
369+ pub fn new ( cx : & ' a ExtCtxt < ' _ > ) -> Self {
372370 let expn_data = cx. current_expansion . id . expn_data ( ) ;
373- let def_site = cx. with_def_site_ctxt ( expn_data. def_site ) ;
374- let call_site = cx. with_call_site_ctxt ( expn_data. call_site ) ;
375- let mixed_site = cx. with_mixed_site_ctxt ( expn_data. call_site ) ;
376- let sess = cx. parse_sess ( ) ;
377371 Rustc {
378372 resolver : cx. resolver ,
379- sess,
380- def_site,
381- call_site,
382- mixed_site,
373+ sess : cx . parse_sess ( ) ,
374+ def_site : cx . with_def_site_ctxt ( expn_data . def_site ) ,
375+ call_site : cx . with_call_site_ctxt ( expn_data . call_site ) ,
376+ mixed_site : cx . with_mixed_site_ctxt ( expn_data . call_site ) ,
383377 span_debug : cx. ecfg . span_debug ,
384- krate,
385- expn_id : cx. current_expansion . id ,
378+ krate : expn_data. macro_def_id . unwrap ( ) . krate ,
386379 rebased_spans : FxHashMap :: default ( ) ,
387380 }
388381 }
@@ -782,25 +775,15 @@ impl server::Span for Rustc<'_> {
782775 /// span from the metadata of `my_proc_macro` (which we have access to,
783776 /// since we've loaded `my_proc_macro` from disk in order to execute it).
784777 /// In this way, we have obtained a span pointing into `my_proc_macro`
785- fn save_span ( & mut self , mut span : Self :: Span ) -> usize {
786- // Throw away the `SyntaxContext`, since we currently
787- // skip serializing `SyntaxContext`s for proc-macro crates
788- span = span. with_ctxt ( rustc_span:: SyntaxContext :: root ( ) ) ;
778+ fn save_span ( & mut self , span : Self :: Span ) -> usize {
789779 self . sess . save_proc_macro_span ( span)
790780 }
791781 fn recover_proc_macro_span ( & mut self , id : usize ) -> Self :: Span {
792- let resolver = self . resolver ;
793- let krate = self . krate ;
794- let expn_id = self . expn_id ;
782+ let ( resolver, krate, def_site) = ( self . resolver , self . krate , self . def_site ) ;
795783 * self . rebased_spans . entry ( id) . or_insert_with ( || {
796- let raw_span = resolver. get_proc_macro_quoted_span ( krate, id) ;
797- // Ignore the deserialized `SyntaxContext` entirely.
798- // FIXME: Preserve the macro backtrace from the serialized span
799- // For example, if a proc-macro crate has code like
800- // `macro_one!() -> macro_two!() -> quote!()`, we might
801- // want to 'concatenate' this backtrace with the backtrace from
802- // our current call site.
803- raw_span. with_def_site_ctxt ( expn_id)
784+ // FIXME: `SyntaxContext` for spans from proc macro crates is lost during encoding,
785+ // replace it with a def-site context until we are encoding it properly.
786+ resolver. get_proc_macro_quoted_span ( krate, id) . with_ctxt ( def_site. ctxt ( ) )
804787 } )
805788 }
806789}
@@ -812,7 +795,7 @@ fn ident_name_compatibility_hack(
812795 rustc : & mut Rustc < ' _ > ,
813796) -> Option < ( rustc_span:: symbol:: Ident , bool ) > {
814797 if let NtIdent ( ident, is_raw) = nt {
815- if let ExpnKind :: Macro { name : macro_name , .. } = orig_span. ctxt ( ) . outer_expn_data ( ) . kind {
798+ if let ExpnKind :: Macro ( _ , macro_name ) = orig_span. ctxt ( ) . outer_expn_data ( ) . kind {
816799 let source_map = rustc. sess . source_map ( ) ;
817800 let filename = source_map. span_to_filename ( orig_span) ;
818801 if let FileName :: Real ( RealFileName :: LocalPath ( path) ) = filename {
0 commit comments