@@ -2666,13 +2666,18 @@ impl<'a> Parser<'a> {
2666
2666
} else {
2667
2667
try!( self . parse_prefix_expr ( ) )
2668
2668
} ;
2669
- if self . expr_is_complete ( & * lhs) && min_prec == 0 {
2669
+ if self . expr_is_complete ( & * lhs) {
2670
2670
// Semi-statement forms are odd. See https://github.com/rust-lang/rust/issues/29071
2671
2671
return Ok ( lhs) ;
2672
2672
}
2673
2673
let cur_op_span = self . span ;
2674
2674
self . expected_tokens . push ( TokenType :: Operator ) ;
2675
2675
while let Some ( op) = AssocOp :: from_token ( & self . token ) {
2676
+ let restrictions = if op. is_assign_like ( ) {
2677
+ self . restrictions & Restrictions :: RESTRICTION_NO_STRUCT_LITERAL
2678
+ } else {
2679
+ self . restrictions
2680
+ } ;
2676
2681
if op. precedence ( ) < min_prec {
2677
2682
break ;
2678
2683
}
@@ -2706,12 +2711,19 @@ impl<'a> Parser<'a> {
2706
2711
break
2707
2712
}
2708
2713
2714
+
2709
2715
let rhs = try!( match op. fixity ( ) {
2710
- Fixity :: Right => self . parse_assoc_expr_with ( op. precedence ( ) , None ) ,
2711
- Fixity :: Left => self . parse_assoc_expr_with ( op. precedence ( ) + 1 , None ) ,
2716
+ Fixity :: Right => self . with_res ( restrictions, |this|{
2717
+ this. parse_assoc_expr_with ( op. precedence ( ) , None )
2718
+ } ) ,
2719
+ Fixity :: Left => self . with_res ( restrictions, |this|{
2720
+ this. parse_assoc_expr_with ( op. precedence ( ) + 1 , None )
2721
+ } ) ,
2712
2722
// We currently have no non-associative operators that are not handled above by
2713
2723
// the special cases. The code is here only for future convenience.
2714
- Fixity :: None => self . parse_assoc_expr_with ( op. precedence ( ) + 1 , None ) ,
2724
+ Fixity :: None => self . with_res ( restrictions, |this|{
2725
+ this. parse_assoc_expr_with ( op. precedence ( ) + 1 , None )
2726
+ } ) ,
2715
2727
} ) ;
2716
2728
2717
2729
lhs = match op {
@@ -2974,13 +2986,22 @@ impl<'a> Parser<'a> {
2974
2986
self . parse_expr_res ( Restrictions :: empty ( ) )
2975
2987
}
2976
2988
2977
- /// Parse an expression, subject to the given restrictions
2978
- pub fn parse_expr_res ( & mut self , r : Restrictions ) -> PResult < P < Expr > > {
2989
+ /// Evaluate the closure with restrictions in place.
2990
+ ///
2991
+ /// After the closure is evaluated, restrictions are reset.
2992
+ pub fn with_res < F > ( & mut self , r : Restrictions , f : F ) -> PResult < P < Expr > >
2993
+ where F : FnOnce ( & mut Self ) -> PResult < P < Expr > > {
2979
2994
let old = self . restrictions ;
2980
2995
self . restrictions = r;
2981
- let e = try! ( self . parse_assoc_expr ( ) ) ;
2996
+ let r = f ( self ) ;
2982
2997
self . restrictions = old;
2983
- return Ok ( e) ;
2998
+ return r;
2999
+
3000
+ }
3001
+
3002
+ /// Parse an expression, subject to the given restrictions
3003
+ pub fn parse_expr_res ( & mut self , r : Restrictions ) -> PResult < P < Expr > > {
3004
+ self . with_res ( r, |this| this. parse_assoc_expr ( ) )
2984
3005
}
2985
3006
2986
3007
/// Parse the RHS of a local variable declaration (e.g. '= 14;')
0 commit comments