gate const closures

This commit is contained in:
Deadbeef 2022-12-21 14:51:02 +00:00
parent 4fb10c0ce4
commit e7fea8c7e6
5 changed files with 28 additions and 1 deletions

View File

@ -385,6 +385,14 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
ast::ExprKind::TryBlock(_) => {
gate_feature_post!(&self, try_blocks, e.span, "`try` expression is experimental");
}
ast::ExprKind::Closure(box ast::Closure { constness: ast::Const::Yes(_), .. }) => {
gate_feature_post!(
&self,
const_closures,
e.span,
"const closures are experimental"
);
}
_ => {}
}
visit::walk_expr(self, e)

View File

@ -342,7 +342,9 @@ declare_features! (
(active, collapse_debuginfo, "1.65.0", Some(100758), None),
/// Allows `async {}` expressions in const contexts.
(active, const_async_blocks, "1.53.0", Some(85368), None),
// Allows limiting the evaluation steps of const expressions
/// Allows `const || {}` closures in const contexts.
(incomplete, const_closures, "CURRENT_RUSTC_VERSION", Some(106003), None),
/// Allows limiting the evaluation steps of const expressions
(active, const_eval_limit, "1.43.0", Some(67217), None),
/// Allows the definition of `const extern fn` and `const unsafe extern fn`.
(active, const_extern_fn, "1.40.0", Some(64926), None),

View File

@ -498,6 +498,7 @@ symbols! {
console,
const_allocate,
const_async_blocks,
const_closures,
const_compare_raw_pointers,
const_constructor,
const_deallocate,

View File

@ -0,0 +1,4 @@
fn main() {
(const || {})();
//~^ ERROR: const closures are experimental
}

View File

@ -0,0 +1,12 @@
error[E0658]: const closures are experimental
--> $DIR/gate.rs:2:6
|
LL | (const || {})();
| ^^^^^^^^^^^
|
= note: see issue #106003 <https://github.com/rust-lang/rust/issues/106003> for more information
= help: add `#![feature(const_closures)]` to the crate attributes to enable
error: aborting due to previous error
For more information about this error, try `rustc --explain E0658`.