mirror of
https://github.com/rust-lang/rust.git
synced 2024-10-31 22:41:50 +00:00
Allow async {}
expressions in const contexts
This commit is contained in:
parent
8cf990c9b5
commit
bd16825767
@ -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,
|
||||
|
@ -1,8 +1,19 @@
|
||||
// From <https://github.com/rust-lang/rust/issues/77361>
|
||||
// gate-test-const_async_blocks
|
||||
|
||||
// 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 };
|
||||
//~^ `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: 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
|
||||
|
|
||||
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
|
||||
--> $DIR/issue-78721.rs:8:13
|
||||
@ -24,4 +26,5 @@ LL | }],
|
||||
|
||||
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
|
||||
|
||||
error: `async` blocks are not allowed in constants
|
||||
error[E0658]: `async` blocks are not allowed in constants
|
||||
--> $DIR/issue-78722.rs:17:20
|
||||
|
|
||||
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
|
||||
--> $DIR/issue-78722.rs:17:13
|
||||
@ -32,4 +34,5 @@ LL | }],
|
||||
|
||||
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: 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
|
||||
|
|
||||
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
|
||||
--> $DIR/issue-78722.rs:17:13
|
||||
@ -24,4 +26,5 @@ LL | }],
|
||||
|
||||
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…
Reference in New Issue
Block a user