1
Fork 0

Rollup merge of #119198 - compiler-errors:desugaring, r=eholk

Split coroutine desugaring kind from source

What a coroutine is desugared from (gen/async gen/async) should be separate from where it comes (fn/block/closure).
This commit is contained in:
Michael Goulet 2023-12-22 21:41:04 -05:00 committed by GitHub
commit ae0a6e8537
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
30 changed files with 448 additions and 239 deletions

View file

@ -464,8 +464,12 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
Rvalue::Aggregate(kind, ..) => {
if let AggregateKind::Coroutine(def_id, ..) = kind.as_ref()
&& let Some(coroutine_kind @ hir::CoroutineKind::Async(..)) =
self.tcx.coroutine_kind(def_id)
&& let Some(
coroutine_kind @ hir::CoroutineKind::Desugared(
hir::CoroutineDesugaring::Async,
_,
),
) = self.tcx.coroutine_kind(def_id)
{
self.check_op(ops::Coroutine(coroutine_kind));
}

View file

@ -339,7 +339,11 @@ impl<'tcx> NonConstOp<'tcx> for FnCallUnstable {
pub struct Coroutine(pub hir::CoroutineKind);
impl<'tcx> NonConstOp<'tcx> for Coroutine {
fn status_in_item(&self, _: &ConstCx<'_, 'tcx>) -> Status {
if let hir::CoroutineKind::Async(hir::CoroutineSource::Block) = self.0 {
if let hir::CoroutineKind::Desugared(
hir::CoroutineDesugaring::Async,
hir::CoroutineSource::Block,
) = self.0
{
Status::Unstable(sym::const_async_blocks)
} else {
Status::Forbidden
@ -348,7 +352,11 @@ impl<'tcx> NonConstOp<'tcx> for Coroutine {
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
let msg = format!("{:#}s are not allowed in {}s", self.0, ccx.const_kind());
if let hir::CoroutineKind::Async(hir::CoroutineSource::Block) = self.0 {
if let hir::CoroutineKind::Desugared(
hir::CoroutineDesugaring::Async,
hir::CoroutineSource::Block,
) = self.0
{
ccx.tcx.sess.create_feature_err(
errors::UnallowedOpInConstContext { span, msg },
sym::const_async_blocks,