@@ -668,11 +668,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
668
668
} ;
669
669
let params = arena_vec ! [ self ; param] ;
670
670
671
+ let coroutine_kind =
672
+ hir:: CoroutineKind :: Desugared ( hir:: CoroutineDesugaring :: Async , async_coroutine_source) ;
671
673
let body = self . lower_body ( move |this| {
672
- this. coroutine_kind = Some ( hir:: CoroutineKind :: Desugared (
673
- hir:: CoroutineDesugaring :: Async ,
674
- async_coroutine_source,
675
- ) ) ;
674
+ this. coroutine_kind = Some ( coroutine_kind) ;
676
675
677
676
let old_ctx = this. task_context ;
678
677
this. task_context = Some ( task_context_hid) ;
@@ -691,7 +690,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
691
690
body,
692
691
fn_decl_span : self . lower_span ( span) ,
693
692
fn_arg_span : None ,
694
- movability : Some ( hir:: Movability :: Static ) ,
693
+ kind : hir:: ClosureKind :: Coroutine ( coroutine_kind ) ,
695
694
constness : hir:: Constness :: NotConst ,
696
695
} ) )
697
696
}
@@ -725,11 +724,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
725
724
lifetime_elision_allowed : false ,
726
725
} ) ;
727
726
727
+ let coroutine_kind =
728
+ hir:: CoroutineKind :: Desugared ( hir:: CoroutineDesugaring :: Gen , coroutine_source) ;
728
729
let body = self . lower_body ( move |this| {
729
- this. coroutine_kind = Some ( hir:: CoroutineKind :: Desugared (
730
- hir:: CoroutineDesugaring :: Gen ,
731
- coroutine_source,
732
- ) ) ;
730
+ this. coroutine_kind = Some ( coroutine_kind) ;
733
731
734
732
let res = body ( this) ;
735
733
( & [ ] , res)
@@ -745,7 +743,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
745
743
body,
746
744
fn_decl_span : self . lower_span ( span) ,
747
745
fn_arg_span : None ,
748
- movability : Some ( Movability :: Movable ) ,
746
+ kind : hir :: ClosureKind :: Coroutine ( coroutine_kind ) ,
749
747
constness : hir:: Constness :: NotConst ,
750
748
} ) )
751
749
}
@@ -806,11 +804,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
806
804
} ;
807
805
let params = arena_vec ! [ self ; param] ;
808
806
807
+ let coroutine_kind = hir:: CoroutineKind :: Desugared (
808
+ hir:: CoroutineDesugaring :: AsyncGen ,
809
+ async_coroutine_source,
810
+ ) ;
809
811
let body = self . lower_body ( move |this| {
810
- this. coroutine_kind = Some ( hir:: CoroutineKind :: Desugared (
811
- hir:: CoroutineDesugaring :: AsyncGen ,
812
- async_coroutine_source,
813
- ) ) ;
812
+ this. coroutine_kind = Some ( coroutine_kind) ;
814
813
815
814
let old_ctx = this. task_context ;
816
815
this. task_context = Some ( task_context_hid) ;
@@ -829,7 +828,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
829
828
body,
830
829
fn_decl_span : self . lower_span ( span) ,
831
830
fn_arg_span : None ,
832
- movability : Some ( hir:: Movability :: Static ) ,
831
+ kind : hir:: ClosureKind :: Coroutine ( coroutine_kind ) ,
833
832
constness : hir:: Constness :: NotConst ,
834
833
} ) )
835
834
}
@@ -898,7 +897,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
898
897
let is_async_gen = match self . coroutine_kind {
899
898
Some ( hir:: CoroutineKind :: Desugared ( hir:: CoroutineDesugaring :: Async , _) ) => false ,
900
899
Some ( hir:: CoroutineKind :: Desugared ( hir:: CoroutineDesugaring :: AsyncGen , _) ) => true ,
901
- Some ( hir:: CoroutineKind :: Coroutine )
900
+ Some ( hir:: CoroutineKind :: Coroutine ( _ ) )
902
901
| Some ( hir:: CoroutineKind :: Desugared ( hir:: CoroutineDesugaring :: Gen , _) )
903
902
| None => {
904
903
return hir:: ExprKind :: Err ( self . dcx ( ) . emit_err ( AwaitOnlyInAsyncFnAndBlocks {
@@ -1086,15 +1085,15 @@ impl<'hir> LoweringContext<'_, 'hir> {
1086
1085
) -> hir:: ExprKind < ' hir > {
1087
1086
let ( binder_clause, generic_params) = self . lower_closure_binder ( binder) ;
1088
1087
1089
- let ( body_id, coroutine_option ) = self . with_new_scopes ( fn_decl_span, move |this| {
1088
+ let ( body_id, closure_kind ) = self . with_new_scopes ( fn_decl_span, move |this| {
1090
1089
let mut coroutine_kind = None ;
1091
1090
let body_id = this. lower_fn_body ( decl, |this| {
1092
1091
let e = this. lower_expr_mut ( body) ;
1093
1092
coroutine_kind = this. coroutine_kind ;
1094
1093
e
1095
1094
} ) ;
1096
1095
let coroutine_option =
1097
- this. coroutine_movability_for_fn ( decl, fn_decl_span, coroutine_kind, movability) ;
1096
+ this. closure_movability_for_fn ( decl, fn_decl_span, coroutine_kind, movability) ;
1098
1097
( body_id, coroutine_option)
1099
1098
} ) ;
1100
1099
@@ -1111,26 +1110,26 @@ impl<'hir> LoweringContext<'_, 'hir> {
1111
1110
body : body_id,
1112
1111
fn_decl_span : self . lower_span ( fn_decl_span) ,
1113
1112
fn_arg_span : Some ( self . lower_span ( fn_arg_span) ) ,
1114
- movability : coroutine_option ,
1113
+ kind : closure_kind ,
1115
1114
constness : self . lower_constness ( constness) ,
1116
1115
} ) ;
1117
1116
1118
1117
hir:: ExprKind :: Closure ( c)
1119
1118
}
1120
1119
1121
- fn coroutine_movability_for_fn (
1120
+ fn closure_movability_for_fn (
1122
1121
& mut self ,
1123
1122
decl : & FnDecl ,
1124
1123
fn_decl_span : Span ,
1125
1124
coroutine_kind : Option < hir:: CoroutineKind > ,
1126
1125
movability : Movability ,
1127
- ) -> Option < hir:: Movability > {
1126
+ ) -> hir:: ClosureKind {
1128
1127
match coroutine_kind {
1129
- Some ( hir:: CoroutineKind :: Coroutine ) => {
1128
+ Some ( hir:: CoroutineKind :: Coroutine ( _ ) ) => {
1130
1129
if decl. inputs . len ( ) > 1 {
1131
1130
self . dcx ( ) . emit_err ( CoroutineTooManyParameters { fn_decl_span } ) ;
1132
1131
}
1133
- Some ( movability)
1132
+ hir :: ClosureKind :: Coroutine ( hir :: CoroutineKind :: Coroutine ( movability) )
1134
1133
}
1135
1134
Some (
1136
1135
hir:: CoroutineKind :: Desugared ( hir:: CoroutineDesugaring :: Gen , _)
@@ -1143,7 +1142,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
1143
1142
if movability == Movability :: Static {
1144
1143
self . dcx ( ) . emit_err ( ClosureCannotBeStatic { fn_decl_span } ) ;
1145
1144
}
1146
- None
1145
+ hir :: ClosureKind :: Closure
1147
1146
}
1148
1147
}
1149
1148
}
@@ -1235,7 +1234,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
1235
1234
body,
1236
1235
fn_decl_span : self . lower_span ( fn_decl_span) ,
1237
1236
fn_arg_span : Some ( self . lower_span ( fn_arg_span) ) ,
1238
- movability : None ,
1237
+ kind : hir :: ClosureKind :: Closure ,
1239
1238
constness : hir:: Constness :: NotConst ,
1240
1239
} ) ;
1241
1240
hir:: ExprKind :: Closure ( c)
@@ -1655,7 +1654,19 @@ impl<'hir> LoweringContext<'_, 'hir> {
1655
1654
self . dcx ( ) . emit_err ( AsyncCoroutinesNotSupported { span } ) ,
1656
1655
) ;
1657
1656
}
1658
- Some ( hir:: CoroutineKind :: Coroutine ) | None => {
1657
+ Some ( hir:: CoroutineKind :: Coroutine ( _) ) => {
1658
+ if !self . tcx . features ( ) . coroutines {
1659
+ rustc_session:: parse:: feature_err (
1660
+ & self . tcx . sess . parse_sess ,
1661
+ sym:: coroutines,
1662
+ span,
1663
+ "yield syntax is experimental" ,
1664
+ )
1665
+ . emit ( ) ;
1666
+ }
1667
+ false
1668
+ }
1669
+ None => {
1659
1670
if !self . tcx . features ( ) . coroutines {
1660
1671
rustc_session:: parse:: feature_err (
1661
1672
& self . tcx . sess . parse_sess ,
@@ -1665,7 +1676,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
1665
1676
)
1666
1677
. emit ( ) ;
1667
1678
}
1668
- self . coroutine_kind = Some ( hir:: CoroutineKind :: Coroutine ) ;
1679
+ self . coroutine_kind = Some ( hir:: CoroutineKind :: Coroutine ( Movability :: Movable ) ) ;
1669
1680
false
1670
1681
}
1671
1682
} ;
0 commit comments