about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2019-12-06 23:33:13 +0100
committerMazdak Farrokhzad <twingoow@gmail.com>2019-12-23 13:42:49 +0100
commit7bcc325034e4b428636cb459ccc2c49d08793fec (patch)
tree1a9c9e0abe950964b97c2ed225dbc0376a27179b
parent44ff4df49dfbff2d21999ec9360ed8df655a6d9b (diff)
downloadrust-7bcc325034e4b428636cb459ccc2c49d08793fec.tar.gz
rust-7bcc325034e4b428636cb459ccc2c49d08793fec.zip
refactor parse_if_expr
-rw-r--r--src/librustc_parse/parser/expr.rs10
-rw-r--r--src/test/ui/if/if-let.stderr4
2 files changed, 4 insertions, 10 deletions
diff --git a/src/librustc_parse/parser/expr.rs b/src/librustc_parse/parser/expr.rs
index e67d3f6991a..87c18d53840 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<ast::Block> {
diff --git a/src/test/ui/if/if-let.stderr b/src/test/ui/if/if-let.stderr
index 83ab234cf04..570a64e999c 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");