@@ -2130,7 +2130,7 @@ impl<'a> Parser<'a> {
2130
2130
return self . parse_lambda_expr ( lo, CaptureBy :: Value , attrs) ;
2131
2131
}
2132
2132
if self . eat_keyword ( keywords:: If ) {
2133
- return self . parse_if_expr ( attrs, false ) ;
2133
+ return self . parse_if_expr ( attrs) ;
2134
2134
}
2135
2135
if self . eat_keyword ( keywords:: For ) {
2136
2136
let lo = self . prev_span ;
@@ -2962,25 +2962,20 @@ impl<'a> Parser<'a> {
2962
2962
}
2963
2963
2964
2964
/// Parse an 'if' or 'if let' expression ('if' token already eaten)
2965
- pub fn parse_if_expr ( & mut self , attrs : ThinVec < Attribute > ,
2966
- in_else : bool ) -> PResult < ' a , P < Expr > > {
2965
+ pub fn parse_if_expr ( & mut self , attrs : ThinVec < Attribute > ) -> PResult < ' a , P < Expr > > {
2967
2966
if self . check_keyword ( keywords:: Let ) {
2968
2967
return self . parse_if_let_expr ( attrs) ;
2969
2968
}
2970
2969
let lo = self . prev_span ;
2971
2970
let cond = self . parse_expr_res ( RESTRICTION_NO_STRUCT_LITERAL , None ) ?;
2972
- let thn = self . parse_block ( ) . map_err ( |mut err| {
2973
- if in_else {
2974
- err. cancel ( ) ;
2975
- let sp = lo. next_point ( ) ;
2976
- let mut err = self . diagnostic ( )
2977
- . struct_span_err ( sp, "missing condition for `if` statemement" ) ;
2978
- err. span_label ( sp, "expected if condition here" ) ;
2979
- err
2980
- } else {
2981
- err
2982
- }
2983
- } ) ?;
2971
+ if self . eat_keyword ( keywords:: Else ) {
2972
+ let sp = lo. next_point ( ) ;
2973
+ let mut err = self . diagnostic ( )
2974
+ . struct_span_err ( sp, "missing condition for `if` statemement" ) ;
2975
+ err. span_label ( sp, "expected if condition here" ) ;
2976
+ return Err ( err)
2977
+ }
2978
+ let thn = self . parse_block ( ) ?;
2984
2979
let mut els: Option < P < Expr > > = None ;
2985
2980
let mut hi = thn. span ;
2986
2981
if self . eat_keyword ( keywords:: Else ) {
@@ -3037,7 +3032,7 @@ impl<'a> Parser<'a> {
3037
3032
// `else` token already eaten
3038
3033
pub fn parse_else_expr ( & mut self ) -> PResult < ' a , P < Expr > > {
3039
3034
if self . eat_keyword ( keywords:: If ) {
3040
- return self . parse_if_expr ( ThinVec :: new ( ) , true ) ;
3035
+ return self . parse_if_expr ( ThinVec :: new ( ) ) ;
3041
3036
} else {
3042
3037
let blk = self . parse_block ( ) ?;
3043
3038
return Ok ( self . mk_expr ( blk. span , ExprKind :: Block ( blk) , ThinVec :: new ( ) ) ) ;
0 commit comments