Skip to content

Commit e7fea8c

Browse files
committed
gate const closures
1 parent 4fb10c0 commit e7fea8c

File tree

5 files changed

+28
-1
lines changed

5 files changed

+28
-1
lines changed

compiler/rustc_ast_passes/src/feature_gate.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,14 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
385385
ast::ExprKind::TryBlock(_) => {
386386
gate_feature_post!(&self, try_blocks, e.span, "`try` expression is experimental");
387387
}
388+
ast::ExprKind::Closure(box ast::Closure { constness: ast::Const::Yes(_), .. }) => {
389+
gate_feature_post!(
390+
&self,
391+
const_closures,
392+
e.span,
393+
"const closures are experimental"
394+
);
395+
}
388396
_ => {}
389397
}
390398
visit::walk_expr(self, e)

compiler/rustc_feature/src/active.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,9 @@ declare_features! (
342342
(active, collapse_debuginfo, "1.65.0", Some(100758), None),
343343
/// Allows `async {}` expressions in const contexts.
344344
(active, const_async_blocks, "1.53.0", Some(85368), None),
345-
// Allows limiting the evaluation steps of const expressions
345+
/// Allows `const || {}` closures in const contexts.
346+
(incomplete, const_closures, "CURRENT_RUSTC_VERSION", Some(106003), None),
347+
/// Allows limiting the evaluation steps of const expressions
346348
(active, const_eval_limit, "1.43.0", Some(67217), None),
347349
/// Allows the definition of `const extern fn` and `const unsafe extern fn`.
348350
(active, const_extern_fn, "1.40.0", Some(64926), None),

compiler/rustc_span/src/symbol.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,7 @@ symbols! {
498498
console,
499499
const_allocate,
500500
const_async_blocks,
501+
const_closures,
501502
const_compare_raw_pointers,
502503
const_constructor,
503504
const_deallocate,
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
fn main() {
2+
(const || {})();
3+
//~^ ERROR: const closures are experimental
4+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0658]: const closures are experimental
2+
--> $DIR/gate.rs:2:6
3+
|
4+
LL | (const || {})();
5+
| ^^^^^^^^^^^
6+
|
7+
= note: see issue #106003 <https://github.com/rust-lang/rust/issues/106003> for more information
8+
= help: add `#![feature(const_closures)]` to the crate attributes to enable
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0658`.

0 commit comments

Comments
 (0)