Skip to content

Commit f5bff0f

Browse files
committed
Gate const coroutines better
1 parent 3d5a21a commit f5bff0f

File tree

6 files changed

+34
-18
lines changed

6 files changed

+34
-18
lines changed

compiler/rustc_const_eval/src/check_consts/check.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -589,13 +589,23 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
589589

590590
Rvalue::Aggregate(kind, ..) => {
591591
if let AggregateKind::Coroutine(def_id, ..) = kind.as_ref()
592-
&& let Some(
593-
coroutine_kind @ hir::CoroutineKind::Desugared(
594-
hir::CoroutineDesugaring::Async | hir::CoroutineDesugaring::Gen,
595-
_,
596-
),
597-
) = self.tcx.coroutine_kind(def_id)
592+
&& let Some(coroutine_kind) = self.tcx.coroutine_kind(def_id)
598593
{
594+
// match coroutine_kind {
595+
// CoroutineKind::Desugared(
596+
// CoroutineDesugaring::Async
597+
// | CoroutineDesugaring::Gen
598+
// | CoroutineDesugaring::AsyncGen,
599+
// _,
600+
// ) => {
601+
// self.check_op(ops::Coroutine(coroutine_kind));
602+
// }
603+
// CoroutineKind::Coroutine(_) => {
604+
// // This is a generator witness, which is not a coroutine.
605+
// // We don't need to check it.
606+
// }
607+
// }
608+
599609
self.check_op(ops::Coroutine(coroutine_kind));
600610
}
601611
}

compiler/rustc_const_eval/src/check_consts/ops.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -486,19 +486,18 @@ impl<'tcx> NonConstOp<'tcx> for IntrinsicUnstable {
486486
pub(crate) struct Coroutine(pub hir::CoroutineKind);
487487
impl<'tcx> NonConstOp<'tcx> for Coroutine {
488488
fn status_in_item(&self, _: &ConstCx<'_, 'tcx>) -> Status {
489-
if let hir::CoroutineKind::Desugared(
490-
hir::CoroutineDesugaring::Async,
491-
hir::CoroutineSource::Block,
492-
) = self.0
493-
{
494-
Status::Unstable {
489+
match self.0 {
490+
hir::CoroutineKind::Desugared(
491+
hir::CoroutineDesugaring::Async,
492+
hir::CoroutineSource::Block,
493+
)
494+
| hir::CoroutineKind::Coroutine(_) => Status::Unstable {
495495
gate: sym::const_async_blocks,
496496
gate_already_checked: false,
497497
safe_to_expose_on_stable: false,
498498
is_function_call: false,
499-
}
500-
} else {
501-
Status::Forbidden
499+
},
500+
_ => Status::Forbidden,
502501
}
503502
}
504503

tests/ui/coroutine/const_gen_fn.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ const gen fn a() {}
88

99
const async gen fn b() {}
1010
//~^ ERROR functions cannot be both `const` and `async gen`
11+
//~^^ ERROR `async gen` fn bodies are not allowed in constant functions
1112

1213
fn main() {}

tests/ui/coroutine/const_gen_fn.stderr

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,11 @@ error: `gen` fn bodies are not allowed in constant functions
2222
LL | const gen fn a() {}
2323
| ^^
2424

25-
error: aborting due to 3 previous errors
25+
error: `async gen` fn bodies are not allowed in constant functions
26+
--> $DIR/const_gen_fn.rs:9:24
27+
|
28+
LL | const async gen fn b() {}
29+
| ^^
30+
31+
error: aborting due to 4 previous errors
2632

tests/ui/suggestions/unnamable-types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Test that we do not suggest to add type annotations for unnamable types.
22

33
#![crate_type="lib"]
4-
#![feature(coroutines, stmt_expr_attributes)]
4+
#![feature(coroutines, stmt_expr_attributes, const_async_blocks)]
55

66
const A = 5;
77
//~^ ERROR: missing type for `const` item

tests/ui/type-alias-impl-trait/issue-53678-coroutine-and-const-fn.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![feature(coroutines, coroutine_trait, rustc_attrs)]
1+
#![feature(coroutines, coroutine_trait, rustc_attrs, const_async_blocks)]
22
#![feature(type_alias_impl_trait)]
33

44
//@ check-pass

0 commit comments

Comments
 (0)