Skip to content

Commit 960ea09

Browse files
committed
Add let_else feature gate
1 parent ae32e88 commit 960ea09

File tree

5 files changed

+33
-0
lines changed

5 files changed

+33
-0
lines changed

compiler/rustc_ast_lowering/src/block.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::{ImplTraitContext, ImplTraitPosition, LoweringContext};
22
use rustc_ast::{AttrVec, Block, BlockCheckMode, Expr, Local, LocalKind, Stmt, StmtKind};
33
use rustc_hir as hir;
4+
use rustc_session::parse::feature_err;
45
use rustc_span::symbol::Ident;
56
use rustc_span::{sym, DesugaringKind};
67

@@ -170,6 +171,15 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
170171
span,
171172
kind: hir::ExprKind::If(let_expr, then_expr, Some(else_expr)),
172173
});
174+
if !self.sess.features_untracked().let_else {
175+
feature_err(
176+
&self.sess.parse_sess,
177+
sym::let_else,
178+
local.span,
179+
"`let...else` statements are unstable",
180+
)
181+
.emit();
182+
}
173183
(stmt, if_expr)
174184
}
175185
}

compiler/rustc_feature/src/active.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,9 @@ declare_features! (
676676
/// Allows additional const parameter types, such as `&'static str` or user defined types
677677
(incomplete, adt_const_params, "1.56.0", Some(44580), None),
678678

679+
/// Allows `let...else` statements.
680+
(active, let_else, "1.56.0", Some(87335), None),
681+
679682
// -------------------------------------------------------------------------
680683
// feature-group-end: actual feature gates
681684
// -------------------------------------------------------------------------

compiler/rustc_span/src/symbol.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,7 @@ symbols! {
744744
le,
745745
len,
746746
let_chains,
747+
let_else,
747748
lhs,
748749
lib,
749750
libc,
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
fn main() {
2+
let Some(x) = Some(1) else { //~ ERROR `let...else` statements are unstable
3+
return;
4+
};
5+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0658]: `let...else` statements are unstable
2+
--> $DIR/feature-gate-let_else.rs:2:5
3+
|
4+
LL | / let Some(x) = Some(1) else {
5+
LL | | return;
6+
LL | | };
7+
| |______^
8+
|
9+
= note: see issue #87335 <https://github.com/rust-lang/rust/issues/87335> for more information
10+
= help: add `#![feature(let_else)]` to the crate attributes to enable
11+
12+
error: aborting due to previous error
13+
14+
For more information about this error, try `rustc --explain E0658`.

0 commit comments

Comments
 (0)