From e7fea8c7e63cd60aa583e6ee761716bef9a7cc1a Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Wed, 21 Dec 2022 14:51:02 +0000 Subject: [PATCH] gate const closures --- compiler/rustc_ast_passes/src/feature_gate.rs | 8 ++++++++ compiler/rustc_feature/src/active.rs | 4 +++- compiler/rustc_span/src/symbol.rs | 1 + .../rfc-2632-const-trait-impl/const_closures/gate.rs | 4 ++++ .../const_closures/gate.stderr | 12 ++++++++++++ 5 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 src/test/ui/rfc-2632-const-trait-impl/const_closures/gate.rs create mode 100644 src/test/ui/rfc-2632-const-trait-impl/const_closures/gate.stderr diff --git a/compiler/rustc_ast_passes/src/feature_gate.rs b/compiler/rustc_ast_passes/src/feature_gate.rs index 039338f543c..89ba6f936d1 100644 --- a/compiler/rustc_ast_passes/src/feature_gate.rs +++ b/compiler/rustc_ast_passes/src/feature_gate.rs @@ -385,6 +385,14 @@ fn visit_expr(&mut self, e: &'a ast::Expr) { 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) diff --git a/compiler/rustc_feature/src/active.rs b/compiler/rustc_feature/src/active.rs index 691c0955cad..d6eda08f662 100644 --- a/compiler/rustc_feature/src/active.rs +++ b/compiler/rustc_feature/src/active.rs @@ -342,7 +342,9 @@ pub fn set(&self, features: &mut Features, span: Span) { (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), diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index fbb12701d96..706002f79b1 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -498,6 +498,7 @@ console, const_allocate, const_async_blocks, + const_closures, const_compare_raw_pointers, const_constructor, const_deallocate, diff --git a/src/test/ui/rfc-2632-const-trait-impl/const_closures/gate.rs b/src/test/ui/rfc-2632-const-trait-impl/const_closures/gate.rs new file mode 100644 index 00000000000..89551121ad2 --- /dev/null +++ b/src/test/ui/rfc-2632-const-trait-impl/const_closures/gate.rs @@ -0,0 +1,4 @@ +fn main() { + (const || {})(); + //~^ ERROR: const closures are experimental +} diff --git a/src/test/ui/rfc-2632-const-trait-impl/const_closures/gate.stderr b/src/test/ui/rfc-2632-const-trait-impl/const_closures/gate.stderr new file mode 100644 index 00000000000..94a7fe9e62c --- /dev/null +++ b/src/test/ui/rfc-2632-const-trait-impl/const_closures/gate.stderr @@ -0,0 +1,12 @@ +error[E0658]: const closures are experimental + --> $DIR/gate.rs:2:6 + | +LL | (const || {})(); + | ^^^^^^^^^^^ + | + = note: see issue #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`.