diff --git a/src/librustc_parse/parser/expr.rs b/src/librustc_parse/parser/expr.rs index e67d3f6991af..87c18d538401 100644 --- a/src/librustc_parse/parser/expr.rs +++ b/src/librustc_parse/parser/expr.rs @@ -1423,14 +1423,8 @@ impl<'a> Parser<'a> { err })? }; - let mut els = None; - let mut hi = thn.span; - if self.eat_keyword(kw::Else) { - let elexpr = self.parse_else_expr()?; - hi = elexpr.span; - els = Some(elexpr); - } - Ok(self.mk_expr(lo.to(hi), ExprKind::If(cond, thn, els), attrs)) + let els = if self.eat_keyword(kw::Else) { Some(self.parse_else_expr()?) } else { None }; + Ok(self.mk_expr(lo.to(self.prev_span), ExprKind::If(cond, thn, els), attrs)) } fn error_missing_if_cond(&self, lo: Span, span: Span) -> P { diff --git a/src/test/ui/if/if-let.stderr b/src/test/ui/if/if-let.stderr index 83ab234cf04e..570a64e999cd 100644 --- a/src/test/ui/if/if-let.stderr +++ b/src/test/ui/if/if-let.stderr @@ -2,7 +2,7 @@ warning: irrefutable if-let pattern --> $DIR/if-let.rs:6:13 | LL | if let $p = $e $b - | ^^ + | ^^^^^^^^^^^^^^^^^ ... LL | / foo!(a, 1, { LL | | println!("irrefutable pattern"); @@ -15,7 +15,7 @@ warning: irrefutable if-let pattern --> $DIR/if-let.rs:6:13 | LL | if let $p = $e $b - | ^^ + | ^^^^^^^^^^^^^^^^^ ... LL | / bar!(a, 1, { LL | | println!("irrefutable pattern");