@@ -554,6 +554,9 @@ declare_features! (
554
554
// Allows using C-variadics.
555
555
( active, c_variadic, "1.34.0" , Some ( 44930 ) , None ) ,
556
556
557
+ // Allows `if/while p && let q = r && ...` chains.
558
+ ( active, let_chains, "1.36.0" , Some ( 53667 ) , None ) ,
559
+
557
560
// -------------------------------------------------------------------------
558
561
// feature-group-end: actual feature gates
559
562
// -------------------------------------------------------------------------
@@ -565,7 +568,8 @@ declare_features! (
565
568
const INCOMPLETE_FEATURES : & [ Symbol ] = & [
566
569
sym:: impl_trait_in_bindings,
567
570
sym:: generic_associated_types,
568
- sym:: const_generics
571
+ sym:: const_generics,
572
+ sym:: let_chains,
569
573
] ;
570
574
571
575
declare_features ! (
@@ -1884,6 +1888,27 @@ impl<'a> PostExpansionVisitor<'a> {
1884
1888
Err ( mut err) => err. emit ( ) ,
1885
1889
}
1886
1890
}
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
+ }
1887
1912
}
1888
1913
1889
1914
impl < ' a > Visitor < ' a > for PostExpansionVisitor < ' a > {
@@ -2099,6 +2124,10 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
2099
2124
2100
2125
fn visit_expr ( & mut self , e : & ' a ast:: Expr ) {
2101
2126
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
+ }
2102
2131
ast:: ExprKind :: Box ( _) => {
2103
2132
gate_feature_post ! ( & self , box_syntax, e. span, EXPLAIN_BOX_SYNTAX ) ;
2104
2133
}
0 commit comments