about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2019-12-31 01:57:42 +0100
committerMazdak Farrokhzad <twingoow@gmail.com>2019-12-31 04:33:34 +0100
commit6fba12591217cd4f1980e0d6fc5b2dee897799d1 (patch)
treeb374757c1311c1cae8fd4815ccee9705d06f2c2a
parent51fb5998493366a7f0257855d1d9be7836aad30f (diff)
downloadrust-6fba12591217cd4f1980e0d6fc5b2dee897799d1.tar.gz
rust-6fba12591217cd4f1980e0d6fc5b2dee897799d1.zip
parser::path: remove .fatal calls
-rw-r--r--src/librustc_parse/parser/expr.rs4
-rw-r--r--src/librustc_parse/parser/path.rs8
-rw-r--r--src/librustc_parse/parser/stmt.rs13
3 files changed, 15 insertions, 10 deletions
diff --git a/src/librustc_parse/parser/expr.rs b/src/librustc_parse/parser/expr.rs
index 49ca5abe97f..9a4bef37768 100644
--- a/src/librustc_parse/parser/expr.rs
+++ b/src/librustc_parse/parser/expr.rs
@@ -1450,9 +1450,7 @@ impl<'a> Parser<'a> {
         self.struct_span_err(sp, "missing condition for `if` expression")
             .span_label(sp, "expected if condition here")
             .emit();
-        let expr = self.mk_expr_err(span);
-        let stmt = self.mk_stmt(span, ast::StmtKind::Expr(expr));
-        self.mk_block(vec![stmt], BlockCheckMode::Default, span)
+        self.mk_block_err(span)
     }
 
     /// Parses the condition of a `if` or `while` expression.
diff --git a/src/librustc_parse/parser/path.rs b/src/librustc_parse/parser/path.rs
index 6f24dfcd027..325ad56cd2a 100644
--- a/src/librustc_parse/parser/path.rs
+++ b/src/librustc_parse/parser/path.rs
@@ -406,9 +406,11 @@ impl<'a> Parser<'a> {
                     if self.token.is_bool_lit() {
                         self.parse_literal_maybe_minus()?
                     } else {
-                        return Err(
-                            self.fatal("identifiers may currently not be used for const generics")
-                        );
+                        let span = self.token.span;
+                        let msg = "identifiers may currently not be used for const generics";
+                        self.struct_span_err(span, msg).emit();
+                        let block = self.mk_block_err(span);
+                        self.mk_expr(span, ast::ExprKind::Block(block, None), ast::AttrVec::new())
                     }
                 } else {
                     self.parse_literal_maybe_minus()?
diff --git a/src/librustc_parse/parser/stmt.rs b/src/librustc_parse/parser/stmt.rs
index 1f72c66ea03..bf092ed14e3 100644
--- a/src/librustc_parse/parser/stmt.rs
+++ b/src/librustc_parse/parser/stmt.rs
@@ -398,10 +398,7 @@ impl<'a> Parser<'a> {
                     self.maybe_annotate_with_ascription(&mut err, false);
                     err.emit();
                     self.recover_stmt_(SemiColonMode::Ignore, BlockMode::Ignore);
-                    Some(self.mk_stmt(
-                        self.token.span,
-                        StmtKind::Expr(self.mk_expr_err(self.token.span)),
-                    ))
+                    Some(self.mk_stmt_err(self.token.span))
                 }
                 Ok(stmt) => stmt,
             };
@@ -479,4 +476,12 @@ impl<'a> Parser<'a> {
     pub(super) fn mk_stmt(&self, span: Span, kind: StmtKind) -> Stmt {
         Stmt { id: DUMMY_NODE_ID, kind, span }
     }
+
+    fn mk_stmt_err(&self, span: Span) -> Stmt {
+        self.mk_stmt(span, StmtKind::Expr(self.mk_expr_err(span)))
+    }
+
+    pub(super) fn mk_block_err(&self, span: Span) -> P<Block> {
+        self.mk_block(vec![self.mk_stmt_err(span)], BlockCheckMode::Default, span)
+    }
 }