@@ -50,6 +50,7 @@ use errors::Applicability;
50
50
use rustc_data_structures:: fx:: FxHashSet ;
51
51
use rustc_data_structures:: indexed_vec:: IndexVec ;
52
52
use rustc_data_structures:: thin_vec:: ThinVec ;
53
+ use rustc_data_structures:: sync:: Lrc ;
53
54
54
55
use std:: collections:: { BTreeSet , BTreeMap } ;
55
56
use std:: mem;
@@ -58,17 +59,17 @@ use syntax::attr;
58
59
use syntax:: ast;
59
60
use syntax:: ast:: * ;
60
61
use syntax:: errors;
61
- use syntax:: ext:: hygiene:: Mark ;
62
+ use syntax:: ext:: hygiene:: { Mark , SyntaxContext } ;
62
63
use syntax:: print:: pprust;
63
64
use syntax:: ptr:: P ;
64
- use syntax:: source_map:: { respan, CompilerDesugaringKind , Spanned } ;
65
+ use syntax:: source_map:: { self , respan, CompilerDesugaringKind , Spanned } ;
65
66
use syntax:: source_map:: CompilerDesugaringKind :: IfTemporary ;
66
67
use syntax:: std_inject;
67
68
use syntax:: symbol:: { kw, sym, Symbol } ;
68
69
use syntax:: tokenstream:: { TokenStream , TokenTree } ;
69
70
use syntax:: parse:: token:: Token ;
70
71
use syntax:: visit:: { self , Visitor } ;
71
- use syntax_pos:: Span ;
72
+ use syntax_pos:: { edition , Span } ;
72
73
73
74
const HIR_ID_COUNTER_LOCKED : u32 = 0xFFFFFFFF ;
74
75
@@ -829,6 +830,27 @@ impl<'a> LoweringContext<'a> {
829
830
self . sess . diagnostic ( )
830
831
}
831
832
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
+
832
854
fn with_anonymous_lifetime_mode < R > (
833
855
& mut self ,
834
856
anonymous_lifetime_mode : AnonymousLifetimeMode ,
@@ -1128,7 +1150,7 @@ impl<'a> LoweringContext<'a> {
1128
1150
attrs : ThinVec :: new ( ) ,
1129
1151
} ;
1130
1152
1131
- let unstable_span = self . sess . source_map ( ) . mark_span_with_reason (
1153
+ let unstable_span = self . mark_span_with_reason (
1132
1154
CompilerDesugaringKind :: Async ,
1133
1155
span,
1134
1156
Some ( vec ! [ sym:: gen_future] . into ( ) ) ,
@@ -1535,7 +1557,7 @@ impl<'a> LoweringContext<'a> {
1535
1557
// desugaring that explicitly states that we don't want to track that.
1536
1558
// Not tracking it makes lints in rustc and clippy very fragile as
1537
1559
// 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 (
1539
1561
CompilerDesugaringKind :: ExistentialReturnType ,
1540
1562
span,
1541
1563
None ,
@@ -2395,7 +2417,7 @@ impl<'a> LoweringContext<'a> {
2395
2417
) -> hir:: FunctionRetTy {
2396
2418
let span = output. span ( ) ;
2397
2419
2398
- let exist_ty_span = self . sess . source_map ( ) . mark_span_with_reason (
2420
+ let exist_ty_span = self . mark_span_with_reason (
2399
2421
CompilerDesugaringKind :: Async ,
2400
2422
span,
2401
2423
None ,
@@ -4038,10 +4060,7 @@ impl<'a> LoweringContext<'a> {
4038
4060
let else_arm = self . arm ( hir_vec ! [ else_pat] , P ( else_expr) ) ;
4039
4061
4040
4062
// 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 ) ;
4045
4064
let cond = self . lower_expr ( cond) ;
4046
4065
// Wrap in a construct equivalent to `{ let _t = $cond; _t }` to preserve drop
4047
4066
// semantics since `if cond { ... }` don't let temporaries live outside of `cond`.
@@ -4071,7 +4090,7 @@ impl<'a> LoweringContext<'a> {
4071
4090
} ) ,
4072
4091
ExprKind :: TryBlock ( ref body) => {
4073
4092
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 (
4075
4094
CompilerDesugaringKind :: TryBlock ,
4076
4095
body. span ,
4077
4096
Some ( vec ! [ sym:: try_trait] . into ( ) ) ,
@@ -4503,7 +4522,7 @@ impl<'a> LoweringContext<'a> {
4503
4522
// expand <head>
4504
4523
let mut head = self . lower_expr ( head) ;
4505
4524
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 (
4507
4526
CompilerDesugaringKind :: ForLoop ,
4508
4527
head_sp,
4509
4528
None ,
@@ -4657,13 +4676,13 @@ impl<'a> LoweringContext<'a> {
4657
4676
// return Try::from_error(From::from(err)),
4658
4677
// }
4659
4678
4660
- let unstable_span = self . sess . source_map ( ) . mark_span_with_reason (
4679
+ let unstable_span = self . mark_span_with_reason (
4661
4680
CompilerDesugaringKind :: QuestionMark ,
4662
4681
e. span ,
4663
4682
Some ( vec ! [ sym:: try_trait] . into ( ) ) ,
4664
4683
) ;
4665
4684
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 (
4667
4686
CompilerDesugaringKind :: QuestionMark ,
4668
4687
try_span,
4669
4688
Some ( vec ! [ sym:: try_trait] . into ( ) ) ,
@@ -5460,12 +5479,12 @@ impl<'a> LoweringContext<'a> {
5460
5479
err. emit ( ) ;
5461
5480
return hir:: ExprKind :: Err ;
5462
5481
}
5463
- let span = self . sess . source_map ( ) . mark_span_with_reason (
5482
+ let span = self . mark_span_with_reason (
5464
5483
CompilerDesugaringKind :: Await ,
5465
5484
await_span,
5466
5485
None ,
5467
5486
) ;
5468
- let gen_future_span = self . sess . source_map ( ) . mark_span_with_reason (
5487
+ let gen_future_span = self . mark_span_with_reason (
5469
5488
CompilerDesugaringKind :: Await ,
5470
5489
await_span,
5471
5490
Some ( vec ! [ sym:: gen_future] . into ( ) ) ,
0 commit comments