Allow async {} expressions in const contexts
This commit is contained in:
@@ -650,6 +650,9 @@ declare_features! (
|
||||
/// Allows unsizing coercions in `const fn`.
|
||||
(active, const_fn_unsize, "1.53.0", Some(64992), None),
|
||||
|
||||
/// Allows `async {}` expressions in const contexts.
|
||||
(active, const_async_blocks, "1.53.0", None, None),
|
||||
|
||||
/// Allows using imported `main` function
|
||||
(active, imported_main, "1.53.0", Some(28937), None),
|
||||
|
||||
|
||||
@@ -141,12 +141,20 @@ impl NonConstOp for FnPtrCast {
|
||||
pub struct Generator(pub hir::GeneratorKind);
|
||||
impl NonConstOp for Generator {
|
||||
fn status_in_item(&self, _: &ConstCx<'_, '_>) -> Status {
|
||||
Status::Forbidden
|
||||
if let hir::GeneratorKind::Async(hir::AsyncGeneratorKind::Block) = self.0 {
|
||||
Status::Unstable(sym::const_async_blocks)
|
||||
} else {
|
||||
Status::Forbidden
|
||||
}
|
||||
}
|
||||
|
||||
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());
|
||||
ccx.tcx.sess.struct_span_err(span, &msg)
|
||||
if let hir::GeneratorKind::Async(hir::AsyncGeneratorKind::Block) = self.0 {
|
||||
feature_err(&ccx.tcx.sess.parse_sess, sym::const_async_blocks, span, &msg)
|
||||
} else {
|
||||
ccx.tcx.sess.struct_span_err(span, &msg)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -374,6 +374,7 @@ symbols! {
|
||||
conservative_impl_trait,
|
||||
console,
|
||||
const_allocate,
|
||||
const_async_blocks,
|
||||
const_compare_raw_pointers,
|
||||
const_constructor,
|
||||
const_eval_limit,
|
||||
|
||||
Reference in New Issue
Block a user