@@ -44,6 +44,7 @@ use crate::middle::cstore::CrateStore;
4444use rustc_data_structures:: fx:: FxHashSet ;
4545use rustc_data_structures:: indexed_vec:: IndexVec ;
4646use rustc_data_structures:: thin_vec:: ThinVec ;
47+ use rustc_data_structures:: sync:: Lrc ;
4748use crate :: session:: Session ;
4849use crate :: session:: config:: nightly_options;
4950use crate :: util:: common:: FN_OUTPUT_NAME ;
@@ -681,13 +682,20 @@ impl<'a> LoweringContext<'a> {
681682 Ident :: with_empty_ctxt ( Symbol :: gensym ( s) )
682683 }
683684
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 {
685693 let mark = Mark :: fresh ( Mark :: root ( ) ) ;
686694 mark. set_expn_info ( source_map:: ExpnInfo {
687695 call_site : span,
688696 def_site : Some ( span) ,
689697 format : source_map:: CompilerDesugaring ( reason) ,
690- allow_internal_unstable : true ,
698+ allow_internal_unstable,
691699 allow_internal_unsafe : false ,
692700 local_inner_macros : false ,
693701 edition : source_map:: hygiene:: default_edition ( ) ,
@@ -964,7 +972,13 @@ impl<'a> LoweringContext<'a> {
964972 attrs : ThinVec :: new ( ) ,
965973 } ;
966974
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+ ) ;
968982 let gen_future = self . expr_std_path (
969983 unstable_span, & [ "future" , "from_generator" ] , None , ThinVec :: new ( ) ) ;
970984 hir:: ExprKind :: Call ( P ( gen_future) , hir_vec ! [ generator] )
@@ -1360,9 +1374,10 @@ impl<'a> LoweringContext<'a> {
13601374 // desugaring that explicitly states that we don't want to track that.
13611375 // Not tracking it makes lints in rustc and clippy very fragile as
13621376 // frequently opened issues show.
1363- let exist_ty_span = self . allow_internal_unstable (
1377+ let exist_ty_span = self . mark_span_with_reason (
13641378 CompilerDesugaringKind :: ExistentialReturnType ,
13651379 span,
1380+ None ,
13661381 ) ;
13671382
13681383 let exist_ty_def_index = self
@@ -3927,8 +3942,13 @@ impl<'a> LoweringContext<'a> {
39273942 } ) ,
39283943 ExprKind :: TryBlock ( ref body) => {
39293944 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+ ) ;
39323952 let mut block = this. lower_block ( body, true ) . into_inner ( ) ;
39333953 let tail = block. expr . take ( ) . map_or_else (
39343954 || {
@@ -4360,9 +4380,10 @@ impl<'a> LoweringContext<'a> {
43604380 // expand <head>
43614381 let head = self . lower_expr ( head) ;
43624382 let head_sp = head. span ;
4363- let desugared_span = self . allow_internal_unstable (
4383+ let desugared_span = self . mark_span_with_reason (
43644384 CompilerDesugaringKind :: ForLoop ,
43654385 head_sp,
4386+ None ,
43664387 ) ;
43674388
43684389 let iter = self . str_to_ident ( "iter" ) ;
@@ -4525,8 +4546,13 @@ impl<'a> LoweringContext<'a> {
45254546 // return Try::from_error(From::from(err)),
45264547 // }
45274548
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+ ) ;
45304556
45314557 // `Try::into_result(<expr>)`
45324558 let discr = {
0 commit comments