Skip to content

Commit 635021b

Browse files
committed
let_chains: Add feature gate.
1 parent 96f09fe commit 635021b

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

src/libsyntax/feature_gate.rs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,9 @@ declare_features! (
554554
// Allows using C-variadics.
555555
(active, c_variadic, "1.34.0", Some(44930), None),
556556

557+
// Allows `if/while p && let q = r && ...` chains.
558+
(active, let_chains, "1.36.0", Some(53667), None),
559+
557560
// -------------------------------------------------------------------------
558561
// feature-group-end: actual feature gates
559562
// -------------------------------------------------------------------------
@@ -565,7 +568,8 @@ declare_features! (
565568
const INCOMPLETE_FEATURES: &[Symbol] = &[
566569
sym::impl_trait_in_bindings,
567570
sym::generic_associated_types,
568-
sym::const_generics
571+
sym::const_generics,
572+
sym::let_chains,
569573
];
570574

571575
declare_features! (
@@ -1884,6 +1888,27 @@ impl<'a> PostExpansionVisitor<'a> {
18841888
Err(mut err) => err.emit(),
18851889
}
18861890
}
1891+
1892+
/// Recurse into all places where a `let` expression would be feature gated
1893+
/// and emit gate post errors for those.
1894+
fn find_and_gate_lets(&mut self, e: &'a ast::Expr) {
1895+
match &e.node {
1896+
ast::ExprKind::Paren(e) => {
1897+
self.find_and_gate_lets(e);
1898+
}
1899+
ast::ExprKind::Binary(op, lhs, rhs) if op.node == ast::BinOpKind::And => {
1900+
self.find_and_gate_lets(lhs);
1901+
self.find_and_gate_lets(rhs);
1902+
}
1903+
ast::ExprKind::Let(..) => {
1904+
gate_feature_post!(
1905+
&self, let_chains, e.span,
1906+
"`let` expressions in this position are experimental"
1907+
);
1908+
}
1909+
_ => {}
1910+
}
1911+
}
18871912
}
18881913

18891914
impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
@@ -2099,6 +2124,10 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
20992124

21002125
fn visit_expr(&mut self, e: &'a ast::Expr) {
21012126
match e.node {
2127+
ast::ExprKind::If(ref e, ..) | ast::ExprKind::While(ref e, ..) => match e.node {
2128+
ast::ExprKind::Let(..) => {} // Stable!,
2129+
_ => self.find_and_gate_lets(e),
2130+
}
21022131
ast::ExprKind::Box(_) => {
21032132
gate_feature_post!(&self, box_syntax, e.span, EXPLAIN_BOX_SYNTAX);
21042133
}

src/libsyntax_pos/symbol.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ symbols! {
305305
label_break_value,
306306
lang,
307307
lang_items,
308+
let_chains,
308309
lib,
309310
link,
310311
linkage,

0 commit comments

Comments
 (0)