@@ -44,6 +44,7 @@ use crate::middle::cstore::CrateStore;
44
44
use rustc_data_structures:: fx:: FxHashSet ;
45
45
use rustc_data_structures:: indexed_vec:: IndexVec ;
46
46
use rustc_data_structures:: thin_vec:: ThinVec ;
47
+ use rustc_data_structures:: sync:: Lrc ;
47
48
use crate :: session:: Session ;
48
49
use crate :: session:: config:: nightly_options;
49
50
use crate :: util:: common:: FN_OUTPUT_NAME ;
@@ -681,13 +682,20 @@ impl<'a> LoweringContext<'a> {
681
682
Ident :: with_empty_ctxt ( Symbol :: gensym ( s) )
682
683
}
683
684
684
- fn allow_internal_unstable ( & self , reason : CompilerDesugaringKind , span : Span ) -> Span {
685
+ /// Reuses the span but adds information like the kind of the desugaring and features that are
686
+ /// allowed inside this span.
687
+ fn mark_span_with_reason (
688
+ & self ,
689
+ reason : CompilerDesugaringKind ,
690
+ span : Span ,
691
+ allow_internal_unstable : Option < Lrc < [ Symbol ] > > ,
692
+ ) -> Span {
685
693
let mark = Mark :: fresh ( Mark :: root ( ) ) ;
686
694
mark. set_expn_info ( source_map:: ExpnInfo {
687
695
call_site : span,
688
696
def_site : Some ( span) ,
689
697
format : source_map:: CompilerDesugaring ( reason) ,
690
- allow_internal_unstable : true ,
698
+ allow_internal_unstable,
691
699
allow_internal_unsafe : false ,
692
700
local_inner_macros : false ,
693
701
edition : source_map:: hygiene:: default_edition ( ) ,
@@ -964,7 +972,13 @@ impl<'a> LoweringContext<'a> {
964
972
attrs : ThinVec :: new ( ) ,
965
973
} ;
966
974
967
- let unstable_span = self . allow_internal_unstable ( CompilerDesugaringKind :: Async , span) ;
975
+ let unstable_span = self . mark_span_with_reason (
976
+ CompilerDesugaringKind :: Async ,
977
+ span,
978
+ Some ( vec ! [
979
+ Symbol :: intern( "gen_future" ) ,
980
+ ] . into ( ) ) ,
981
+ ) ;
968
982
let gen_future = self . expr_std_path (
969
983
unstable_span, & [ "future" , "from_generator" ] , None , ThinVec :: new ( ) ) ;
970
984
hir:: ExprKind :: Call ( P ( gen_future) , hir_vec ! [ generator] )
@@ -1360,9 +1374,10 @@ impl<'a> LoweringContext<'a> {
1360
1374
// desugaring that explicitly states that we don't want to track that.
1361
1375
// Not tracking it makes lints in rustc and clippy very fragile as
1362
1376
// frequently opened issues show.
1363
- let exist_ty_span = self . allow_internal_unstable (
1377
+ let exist_ty_span = self . mark_span_with_reason (
1364
1378
CompilerDesugaringKind :: ExistentialReturnType ,
1365
1379
span,
1380
+ None ,
1366
1381
) ;
1367
1382
1368
1383
let exist_ty_def_index = self
@@ -3927,8 +3942,13 @@ impl<'a> LoweringContext<'a> {
3927
3942
} ) ,
3928
3943
ExprKind :: TryBlock ( ref body) => {
3929
3944
self . with_catch_scope ( body. id , |this| {
3930
- let unstable_span =
3931
- this. allow_internal_unstable ( CompilerDesugaringKind :: TryBlock , body. span ) ;
3945
+ let unstable_span = this. mark_span_with_reason (
3946
+ CompilerDesugaringKind :: TryBlock ,
3947
+ body. span ,
3948
+ Some ( vec ! [
3949
+ Symbol :: intern( "try_trait" ) ,
3950
+ ] . into ( ) ) ,
3951
+ ) ;
3932
3952
let mut block = this. lower_block ( body, true ) . into_inner ( ) ;
3933
3953
let tail = block. expr . take ( ) . map_or_else (
3934
3954
|| {
@@ -4360,9 +4380,10 @@ impl<'a> LoweringContext<'a> {
4360
4380
// expand <head>
4361
4381
let head = self . lower_expr ( head) ;
4362
4382
let head_sp = head. span ;
4363
- let desugared_span = self . allow_internal_unstable (
4383
+ let desugared_span = self . mark_span_with_reason (
4364
4384
CompilerDesugaringKind :: ForLoop ,
4365
4385
head_sp,
4386
+ None ,
4366
4387
) ;
4367
4388
4368
4389
let iter = self . str_to_ident ( "iter" ) ;
@@ -4525,8 +4546,13 @@ impl<'a> LoweringContext<'a> {
4525
4546
// return Try::from_error(From::from(err)),
4526
4547
// }
4527
4548
4528
- let unstable_span =
4529
- self . allow_internal_unstable ( CompilerDesugaringKind :: QuestionMark , e. span ) ;
4549
+ let unstable_span = self . mark_span_with_reason (
4550
+ CompilerDesugaringKind :: QuestionMark ,
4551
+ e. span ,
4552
+ Some ( vec ! [
4553
+ Symbol :: intern( "try_trait" )
4554
+ ] . into ( ) ) ,
4555
+ ) ;
4530
4556
4531
4557
// `Try::into_result(<expr>)`
4532
4558
let discr = {
0 commit comments