1
Fork 0

Feature gate coroutine yield usage

This commit is contained in:
Oli Scherer 2023-10-23 14:29:00 +00:00
parent 2e5b36741b
commit cece90c65f
7 changed files with 86 additions and 15 deletions

View file

@ -1504,12 +1504,22 @@ impl<'hir> LoweringContext<'_, 'hir> {
fn lower_expr_yield(&mut self, span: Span, opt_expr: Option<&Expr>) -> hir::ExprKind<'hir> {
match self.coroutine_kind {
Some(hir::CoroutineKind::Coroutine) => {}
Some(hir::CoroutineKind::Gen(_)) => {}
Some(hir::CoroutineKind::Async(_)) => {
self.tcx.sess.emit_err(AsyncCoroutinesNotSupported { span });
}
None => self.coroutine_kind = Some(hir::CoroutineKind::Coroutine),
Some(hir::CoroutineKind::Coroutine) | None => {
if !self.tcx.features().coroutines {
rustc_session::parse::feature_err(
&self.tcx.sess.parse_sess,
sym::coroutines,
span,
"yield syntax is experimental",
)
.emit();
}
self.coroutine_kind = Some(hir::CoroutineKind::Coroutine)
}
}
let expr =