diff options
| author | Cameron Steffen <cam.steffen94@gmail.com> | 2021-06-23 16:40:06 -0500 |
|---|---|---|
| committer | Cameron Steffen <cam.steffen94@gmail.com> | 2021-08-30 20:18:39 -0500 |
| commit | 960ea093ab3b3b34afd4bf6b755d93184452d6af (patch) | |
| tree | b7704720dca8faf1326b3f8265c2cc40364eec65 | |
| parent | ae32e88909350c631a26b3a37a9f07dd9656dba8 (diff) | |
| download | rust-960ea093ab3b3b34afd4bf6b755d93184452d6af.tar.gz rust-960ea093ab3b3b34afd4bf6b755d93184452d6af.zip | |
Add let_else feature gate
| -rw-r--r-- | compiler/rustc_ast_lowering/src/block.rs | 10 | ||||
| -rw-r--r-- | compiler/rustc_feature/src/active.rs | 3 | ||||
| -rw-r--r-- | compiler/rustc_span/src/symbol.rs | 1 | ||||
| -rw-r--r-- | src/test/ui/feature-gates/feature-gate-let_else.rs | 5 | ||||
| -rw-r--r-- | src/test/ui/feature-gates/feature-gate-let_else.stderr | 14 |
5 files changed, 33 insertions, 0 deletions
diff --git a/compiler/rustc_ast_lowering/src/block.rs b/compiler/rustc_ast_lowering/src/block.rs index f4584e8bbdf..ca804ec6758 100644 --- a/compiler/rustc_ast_lowering/src/block.rs +++ b/compiler/rustc_ast_lowering/src/block.rs @@ -1,6 +1,7 @@ use crate::{ImplTraitContext, ImplTraitPosition, LoweringContext}; use rustc_ast::{AttrVec, Block, BlockCheckMode, Expr, Local, LocalKind, Stmt, StmtKind}; use rustc_hir as hir; +use rustc_session::parse::feature_err; use rustc_span::symbol::Ident; use rustc_span::{sym, DesugaringKind}; @@ -170,6 +171,15 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { span, kind: hir::ExprKind::If(let_expr, then_expr, Some(else_expr)), }); + if !self.sess.features_untracked().let_else { + feature_err( + &self.sess.parse_sess, + sym::let_else, + local.span, + "`let...else` statements are unstable", + ) + .emit(); + } (stmt, if_expr) } } diff --git a/compiler/rustc_feature/src/active.rs b/compiler/rustc_feature/src/active.rs index 1ff2c75966a..a3807a2bb9f 100644 --- a/compiler/rustc_feature/src/active.rs +++ b/compiler/rustc_feature/src/active.rs @@ -676,6 +676,9 @@ declare_features! ( /// Allows additional const parameter types, such as `&'static str` or user defined types (incomplete, adt_const_params, "1.56.0", Some(44580), None), + /// Allows `let...else` statements. + (active, let_else, "1.56.0", Some(87335), None), + // ------------------------------------------------------------------------- // feature-group-end: actual feature gates // ------------------------------------------------------------------------- diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 19c02ba45c4..899c51e12ff 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -744,6 +744,7 @@ symbols! { le, len, let_chains, + let_else, lhs, lib, libc, diff --git a/src/test/ui/feature-gates/feature-gate-let_else.rs b/src/test/ui/feature-gates/feature-gate-let_else.rs new file mode 100644 index 00000000000..3f04a9dabfd --- /dev/null +++ b/src/test/ui/feature-gates/feature-gate-let_else.rs @@ -0,0 +1,5 @@ +fn main() { + let Some(x) = Some(1) else { //~ ERROR `let...else` statements are unstable + return; + }; +} diff --git a/src/test/ui/feature-gates/feature-gate-let_else.stderr b/src/test/ui/feature-gates/feature-gate-let_else.stderr new file mode 100644 index 00000000000..86252604154 --- /dev/null +++ b/src/test/ui/feature-gates/feature-gate-let_else.stderr @@ -0,0 +1,14 @@ +error[E0658]: `let...else` statements are unstable + --> $DIR/feature-gate-let_else.rs:2:5 + | +LL | / let Some(x) = Some(1) else { +LL | | return; +LL | | }; + | |______^ + | + = note: see issue #87335 <https://github.com/rust-lang/rust/issues/87335> for more information + = help: add `#![feature(let_else)]` to the crate attributes to enable + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0658`. |
