Skip to content

Commit ebea1c2

Browse files
committed
let_chains: Add feature gate.
1 parent c9fb639 commit ebea1c2

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
@@ -560,6 +560,9 @@ declare_features! (
560560
// Allows calling constructor functions in `const fn`.
561561
(active, const_constructor, "1.37.0", Some(61456), None),
562562

563+
// Allows `if/while p && let q = r && ...` chains.
564+
(active, let_chains, "1.37.0", Some(53667), None),
565+
563566
// #[repr(transparent)] on enums.
564567
(active, transparent_enums, "1.37.0", Some(60405), None),
565568

@@ -577,7 +580,8 @@ declare_features! (
577580
const INCOMPLETE_FEATURES: &[Symbol] = &[
578581
sym::impl_trait_in_bindings,
579582
sym::generic_associated_types,
580-
sym::const_generics
583+
sym::const_generics,
584+
sym::let_chains,
581585
];
582586

583587
declare_features! (
@@ -1936,6 +1940,27 @@ impl<'a> PostExpansionVisitor<'a> {
19361940
Err(mut err) => err.emit(),
19371941
}
19381942
}
1943+
1944+
/// Recurse into all places where a `let` expression would be feature gated
1945+
/// and emit gate post errors for those.
1946+
fn find_and_gate_lets(&mut self, e: &'a ast::Expr) {
1947+
match &e.node {
1948+
ast::ExprKind::Paren(e) => {
1949+
self.find_and_gate_lets(e);
1950+
}
1951+
ast::ExprKind::Binary(op, lhs, rhs) if op.node == ast::BinOpKind::And => {
1952+
self.find_and_gate_lets(lhs);
1953+
self.find_and_gate_lets(rhs);
1954+
}
1955+
ast::ExprKind::Let(..) => {
1956+
gate_feature_post!(
1957+
&self, let_chains, e.span,
1958+
"`let` expressions in this position are experimental"
1959+
);
1960+
}
1961+
_ => {}
1962+
}
1963+
}
19391964
}
19401965

19411966
impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
@@ -2133,6 +2158,10 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
21332158

21342159
fn visit_expr(&mut self, e: &'a ast::Expr) {
21352160
match e.node {
2161+
ast::ExprKind::If(ref e, ..) | ast::ExprKind::While(ref e, ..) => match e.node {
2162+
ast::ExprKind::Let(..) => {} // Stable!,
2163+
_ => self.find_and_gate_lets(e),
2164+
}
21362165
ast::ExprKind::Box(_) => {
21372166
gate_feature_post!(&self, box_syntax, e.span, EXPLAIN_BOX_SYNTAX);
21382167
}

src/libsyntax_pos/symbol.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,7 @@ symbols! {
354354
label_break_value,
355355
lang,
356356
lang_items,
357+
let_chains,
357358
lhs,
358359
lib,
359360
lifetime,

0 commit comments

Comments
 (0)