@@ -50,6 +50,7 @@ use errors::Applicability;
5050use rustc_data_structures:: fx:: FxHashSet ;
5151use rustc_data_structures:: indexed_vec:: IndexVec ;
5252use rustc_data_structures:: thin_vec:: ThinVec ;
53+ use rustc_data_structures:: sync:: Lrc ;
5354
5455use std:: collections:: { BTreeSet , BTreeMap } ;
5556use std:: mem;
@@ -58,17 +59,17 @@ use syntax::attr;
5859use syntax:: ast;
5960use syntax:: ast:: * ;
6061use syntax:: errors;
61- use syntax:: ext:: hygiene:: Mark ;
62+ use syntax:: ext:: hygiene:: { Mark , SyntaxContext } ;
6263use syntax:: print:: pprust;
6364use syntax:: ptr:: P ;
64- use syntax:: source_map:: { respan, CompilerDesugaringKind , Spanned } ;
65+ use syntax:: source_map:: { self , respan, CompilerDesugaringKind , Spanned } ;
6566use syntax:: source_map:: CompilerDesugaringKind :: IfTemporary ;
6667use syntax:: std_inject;
6768use syntax:: symbol:: { kw, sym, Symbol } ;
6869use syntax:: tokenstream:: { TokenStream , TokenTree } ;
6970use syntax:: parse:: token:: Token ;
7071use syntax:: visit:: { self , Visitor } ;
71- use syntax_pos:: Span ;
72+ use syntax_pos:: { edition , Span } ;
7273
7374const HIR_ID_COUNTER_LOCKED : u32 = 0xFFFFFFFF ;
7475
@@ -829,6 +830,27 @@ impl<'a> LoweringContext<'a> {
829830 self . sess . diagnostic ( )
830831 }
831832
833+ /// Reuses the span but adds information like the kind of the desugaring and features that are
834+ /// allowed inside this span.
835+ fn mark_span_with_reason (
836+ & self ,
837+ reason : CompilerDesugaringKind ,
838+ span : Span ,
839+ allow_internal_unstable : Option < Lrc < [ Symbol ] > > ,
840+ ) -> Span {
841+ let mark = Mark :: fresh ( Mark :: root ( ) ) ;
842+ mark. set_expn_info ( source_map:: ExpnInfo {
843+ call_site : span,
844+ def_site : Some ( span) ,
845+ format : source_map:: CompilerDesugaring ( reason) ,
846+ allow_internal_unstable,
847+ allow_internal_unsafe : false ,
848+ local_inner_macros : false ,
849+ edition : edition:: Edition :: from_session ( ) ,
850+ } ) ;
851+ span. with_ctxt ( SyntaxContext :: empty ( ) . apply_mark ( mark) )
852+ }
853+
832854 fn with_anonymous_lifetime_mode < R > (
833855 & mut self ,
834856 anonymous_lifetime_mode : AnonymousLifetimeMode ,
@@ -1128,7 +1150,7 @@ impl<'a> LoweringContext<'a> {
11281150 attrs : ThinVec :: new ( ) ,
11291151 } ;
11301152
1131- let unstable_span = self . sess . source_map ( ) . mark_span_with_reason (
1153+ let unstable_span = self . mark_span_with_reason (
11321154 CompilerDesugaringKind :: Async ,
11331155 span,
11341156 Some ( vec ! [ sym:: gen_future] . into ( ) ) ,
@@ -1535,7 +1557,7 @@ impl<'a> LoweringContext<'a> {
15351557 // desugaring that explicitly states that we don't want to track that.
15361558 // Not tracking it makes lints in rustc and clippy very fragile as
15371559 // frequently opened issues show.
1538- let exist_ty_span = self . sess . source_map ( ) . mark_span_with_reason (
1560+ let exist_ty_span = self . mark_span_with_reason (
15391561 CompilerDesugaringKind :: ExistentialReturnType ,
15401562 span,
15411563 None ,
@@ -2395,7 +2417,7 @@ impl<'a> LoweringContext<'a> {
23952417 ) -> hir:: FunctionRetTy {
23962418 let span = output. span ( ) ;
23972419
2398- let exist_ty_span = self . sess . source_map ( ) . mark_span_with_reason (
2420+ let exist_ty_span = self . mark_span_with_reason (
23992421 CompilerDesugaringKind :: Async ,
24002422 span,
24012423 None ,
@@ -4038,10 +4060,7 @@ impl<'a> LoweringContext<'a> {
40384060 let else_arm = self . arm ( hir_vec ! [ else_pat] , P ( else_expr) ) ;
40394061
40404062 // Lower condition:
4041- let span_block = self
4042- . sess
4043- . source_map ( )
4044- . mark_span_with_reason ( IfTemporary , cond. span , None ) ;
4063+ let span_block = self . mark_span_with_reason ( IfTemporary , cond. span , None ) ;
40454064 let cond = self . lower_expr ( cond) ;
40464065 // Wrap in a construct equivalent to `{ let _t = $cond; _t }` to preserve drop
40474066 // semantics since `if cond { ... }` don't let temporaries live outside of `cond`.
@@ -4071,7 +4090,7 @@ impl<'a> LoweringContext<'a> {
40714090 } ) ,
40724091 ExprKind :: TryBlock ( ref body) => {
40734092 self . with_catch_scope ( body. id , |this| {
4074- let unstable_span = this. sess . source_map ( ) . mark_span_with_reason (
4093+ let unstable_span = this. mark_span_with_reason (
40754094 CompilerDesugaringKind :: TryBlock ,
40764095 body. span ,
40774096 Some ( vec ! [ sym:: try_trait] . into ( ) ) ,
@@ -4503,7 +4522,7 @@ impl<'a> LoweringContext<'a> {
45034522 // expand <head>
45044523 let mut head = self . lower_expr ( head) ;
45054524 let head_sp = head. span ;
4506- let desugared_span = self . sess . source_map ( ) . mark_span_with_reason (
4525+ let desugared_span = self . mark_span_with_reason (
45074526 CompilerDesugaringKind :: ForLoop ,
45084527 head_sp,
45094528 None ,
@@ -4657,13 +4676,13 @@ impl<'a> LoweringContext<'a> {
46574676 // return Try::from_error(From::from(err)),
46584677 // }
46594678
4660- let unstable_span = self . sess . source_map ( ) . mark_span_with_reason (
4679+ let unstable_span = self . mark_span_with_reason (
46614680 CompilerDesugaringKind :: QuestionMark ,
46624681 e. span ,
46634682 Some ( vec ! [ sym:: try_trait] . into ( ) ) ,
46644683 ) ;
46654684 let try_span = self . sess . source_map ( ) . end_point ( e. span ) ;
4666- let try_span = self . sess . source_map ( ) . mark_span_with_reason (
4685+ let try_span = self . mark_span_with_reason (
46674686 CompilerDesugaringKind :: QuestionMark ,
46684687 try_span,
46694688 Some ( vec ! [ sym:: try_trait] . into ( ) ) ,
@@ -5460,12 +5479,12 @@ impl<'a> LoweringContext<'a> {
54605479 err. emit ( ) ;
54615480 return hir:: ExprKind :: Err ;
54625481 }
5463- let span = self . sess . source_map ( ) . mark_span_with_reason (
5482+ let span = self . mark_span_with_reason (
54645483 CompilerDesugaringKind :: Await ,
54655484 await_span,
54665485 None ,
54675486 ) ;
5468- let gen_future_span = self . sess . source_map ( ) . mark_span_with_reason (
5487+ let gen_future_span = self . mark_span_with_reason (
54695488 CompilerDesugaringKind :: Await ,
54705489 await_span,
54715490 Some ( vec ! [ sym:: gen_future] . into ( ) ) ,
0 commit comments