Allow async {}
expressions in const contexts
This commit is contained in:
parent
8cf990c9b5
commit
bd16825767
10 changed files with 70 additions and 19 deletions
|
@ -650,6 +650,9 @@ declare_features! (
|
||||||
/// Allows unsizing coercions in `const fn`.
|
/// Allows unsizing coercions in `const fn`.
|
||||||
(active, const_fn_unsize, "1.53.0", Some(64992), None),
|
(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
|
/// Allows using imported `main` function
|
||||||
(active, imported_main, "1.53.0", Some(28937), None),
|
(active, imported_main, "1.53.0", Some(28937), None),
|
||||||
|
|
||||||
|
|
|
@ -141,13 +141,21 @@ impl NonConstOp for FnPtrCast {
|
||||||
pub struct Generator(pub hir::GeneratorKind);
|
pub struct Generator(pub hir::GeneratorKind);
|
||||||
impl NonConstOp for Generator {
|
impl NonConstOp for Generator {
|
||||||
fn status_in_item(&self, _: &ConstCx<'_, '_>) -> Status {
|
fn status_in_item(&self, _: &ConstCx<'_, '_>) -> Status {
|
||||||
|
if let hir::GeneratorKind::Async(hir::AsyncGeneratorKind::Block) = self.0 {
|
||||||
|
Status::Unstable(sym::const_async_blocks)
|
||||||
|
} else {
|
||||||
Status::Forbidden
|
Status::Forbidden
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
|
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());
|
let msg = format!("{}s are not allowed in {}s", self.0, ccx.const_kind());
|
||||||
|
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)
|
ccx.tcx.sess.struct_span_err(span, &msg)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|
|
@ -374,6 +374,7 @@ symbols! {
|
||||||
conservative_impl_trait,
|
conservative_impl_trait,
|
||||||
console,
|
console,
|
||||||
const_allocate,
|
const_allocate,
|
||||||
|
const_async_blocks,
|
||||||
const_compare_raw_pointers,
|
const_compare_raw_pointers,
|
||||||
const_constructor,
|
const_constructor,
|
||||||
const_eval_limit,
|
const_eval_limit,
|
||||||
|
|
|
@ -1,8 +1,19 @@
|
||||||
// From <https://github.com/rust-lang/rust/issues/77361>
|
// gate-test-const_async_blocks
|
||||||
|
|
||||||
// edition:2018
|
// edition:2018
|
||||||
|
// revisions: with_feature without_feature
|
||||||
|
|
||||||
|
#![feature(rustc_attrs)]
|
||||||
|
#![cfg_attr(with_feature, feature(const_async_blocks))]
|
||||||
|
|
||||||
|
use std::future::Future;
|
||||||
|
|
||||||
|
// From <https://github.com/rust-lang/rust/issues/77361>
|
||||||
const _: i32 = { core::mem::ManuallyDrop::new(async { 0 }); 4 };
|
const _: i32 = { core::mem::ManuallyDrop::new(async { 0 }); 4 };
|
||||||
//~^ `async` block
|
//[without_feature]~^ `async` block
|
||||||
|
|
||||||
fn main() {}
|
static _FUT: &(dyn Future<Output = ()> + Sync) = &async {};
|
||||||
|
//[without_feature]~^ `async` block
|
||||||
|
|
||||||
|
#[rustc_error]
|
||||||
|
fn main() {} //[with_feature]~ fatal error triggered by #[rustc_error]
|
||||||
|
|
|
@ -1,8 +0,0 @@
|
||||||
error: `async` blocks are not allowed in constants
|
|
||||||
--> $DIR/async-block.rs:5:47
|
|
||||||
|
|
|
||||||
LL | const _: i32 = { core::mem::ManuallyDrop::new(async { 0 }); 4 };
|
|
||||||
| ^^^^^^^^^^^
|
|
||||||
|
|
||||||
error: aborting due to previous error
|
|
||||||
|
|
8
src/test/ui/consts/async-block.with_feature.stderr
Normal file
8
src/test/ui/consts/async-block.with_feature.stderr
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
error: fatal error triggered by #[rustc_error]
|
||||||
|
--> $DIR/async-block.rs:19:1
|
||||||
|
|
|
||||||
|
LL | fn main() {}
|
||||||
|
| ^^^^^^^^^
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
19
src/test/ui/consts/async-block.without_feature.stderr
Normal file
19
src/test/ui/consts/async-block.without_feature.stderr
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
error[E0658]: `async` blocks are not allowed in constants
|
||||||
|
--> $DIR/async-block.rs:12:47
|
||||||
|
|
|
||||||
|
LL | const _: i32 = { core::mem::ManuallyDrop::new(async { 0 }); 4 };
|
||||||
|
| ^^^^^^^^^^^
|
||||||
|
|
|
||||||
|
= help: add `#![feature(const_async_blocks)]` to the crate attributes to enable
|
||||||
|
|
||||||
|
error[E0658]: `async` blocks are not allowed in statics
|
||||||
|
--> $DIR/async-block.rs:15:51
|
||||||
|
|
|
||||||
|
LL | static _FUT: &(dyn Future<Output = ()> + Sync) = &async {};
|
||||||
|
| ^^^^^^^^
|
||||||
|
|
|
||||||
|
= help: add `#![feature(const_async_blocks)]` to the crate attributes to enable
|
||||||
|
|
||||||
|
error: aborting due to 2 previous errors
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0658`.
|
|
@ -7,11 +7,13 @@ LL | #![feature(impl_trait_in_bindings)]
|
||||||
= note: `#[warn(incomplete_features)]` on by default
|
= note: `#[warn(incomplete_features)]` on by default
|
||||||
= note: see issue #63065 <https://github.com/rust-lang/rust/issues/63065> for more information
|
= note: see issue #63065 <https://github.com/rust-lang/rust/issues/63065> for more information
|
||||||
|
|
||||||
error: `async` blocks are not allowed in constants
|
error[E0658]: `async` blocks are not allowed in constants
|
||||||
--> $DIR/issue-78721.rs:8:57
|
--> $DIR/issue-78721.rs:8:57
|
||||||
|
|
|
|
||||||
LL | let f: impl core::future::Future<Output = u8> = async { 1 };
|
LL | let f: impl core::future::Future<Output = u8> = async { 1 };
|
||||||
| ^^^^^^^^^^^
|
| ^^^^^^^^^^^
|
||||||
|
|
|
||||||
|
= help: add `#![feature(const_async_blocks)]` to the crate attributes to enable
|
||||||
|
|
||||||
error[E0493]: destructors cannot be evaluated at compile-time
|
error[E0493]: destructors cannot be evaluated at compile-time
|
||||||
--> $DIR/issue-78721.rs:8:13
|
--> $DIR/issue-78721.rs:8:13
|
||||||
|
@ -24,4 +26,5 @@ LL | }],
|
||||||
|
|
||||||
error: aborting due to 2 previous errors; 1 warning emitted
|
error: aborting due to 2 previous errors; 1 warning emitted
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0493`.
|
Some errors have detailed explanations: E0493, E0658.
|
||||||
|
For more information about an error, try `rustc --explain E0493`.
|
||||||
|
|
|
@ -15,11 +15,13 @@ LL | #![feature(impl_trait_in_bindings)]
|
||||||
|
|
|
|
||||||
= note: see issue #63065 <https://github.com/rust-lang/rust/issues/63065> for more information
|
= note: see issue #63065 <https://github.com/rust-lang/rust/issues/63065> for more information
|
||||||
|
|
||||||
error: `async` blocks are not allowed in constants
|
error[E0658]: `async` blocks are not allowed in constants
|
||||||
--> $DIR/issue-78722.rs:17:20
|
--> $DIR/issue-78722.rs:17:20
|
||||||
|
|
|
|
||||||
LL | let f: F = async { 1 };
|
LL | let f: F = async { 1 };
|
||||||
| ^^^^^^^^^^^
|
| ^^^^^^^^^^^
|
||||||
|
|
|
||||||
|
= help: add `#![feature(const_async_blocks)]` to the crate attributes to enable
|
||||||
|
|
||||||
error[E0493]: destructors cannot be evaluated at compile-time
|
error[E0493]: destructors cannot be evaluated at compile-time
|
||||||
--> $DIR/issue-78722.rs:17:13
|
--> $DIR/issue-78722.rs:17:13
|
||||||
|
@ -32,4 +34,5 @@ LL | }],
|
||||||
|
|
||||||
error: aborting due to 2 previous errors; 2 warnings emitted
|
error: aborting due to 2 previous errors; 2 warnings emitted
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0493`.
|
Some errors have detailed explanations: E0493, E0658.
|
||||||
|
For more information about an error, try `rustc --explain E0493`.
|
||||||
|
|
|
@ -7,11 +7,13 @@ LL | #![feature(impl_trait_in_bindings)]
|
||||||
= note: `#[warn(incomplete_features)]` on by default
|
= note: `#[warn(incomplete_features)]` on by default
|
||||||
= note: see issue #63065 <https://github.com/rust-lang/rust/issues/63065> for more information
|
= note: see issue #63065 <https://github.com/rust-lang/rust/issues/63065> for more information
|
||||||
|
|
||||||
error: `async` blocks are not allowed in constants
|
error[E0658]: `async` blocks are not allowed in constants
|
||||||
--> $DIR/issue-78722.rs:17:20
|
--> $DIR/issue-78722.rs:17:20
|
||||||
|
|
|
|
||||||
LL | let f: F = async { 1 };
|
LL | let f: F = async { 1 };
|
||||||
| ^^^^^^^^^^^
|
| ^^^^^^^^^^^
|
||||||
|
|
|
||||||
|
= help: add `#![feature(const_async_blocks)]` to the crate attributes to enable
|
||||||
|
|
||||||
error[E0493]: destructors cannot be evaluated at compile-time
|
error[E0493]: destructors cannot be evaluated at compile-time
|
||||||
--> $DIR/issue-78722.rs:17:13
|
--> $DIR/issue-78722.rs:17:13
|
||||||
|
@ -24,4 +26,5 @@ LL | }],
|
||||||
|
|
||||||
error: aborting due to 2 previous errors; 1 warning emitted
|
error: aborting due to 2 previous errors; 1 warning emitted
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0493`.
|
Some errors have detailed explanations: E0493, E0658.
|
||||||
|
For more information about an error, try `rustc --explain E0493`.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue