]> git.lizzy.rs Git - rust.git/commitdiff
parser::path: remove .fatal calls
authorMazdak Farrokhzad <twingoow@gmail.com>
Tue, 31 Dec 2019 00:57:42 +0000 (01:57 +0100)
committerMazdak Farrokhzad <twingoow@gmail.com>
Tue, 31 Dec 2019 03:33:34 +0000 (04:33 +0100)
src/librustc_parse/parser/expr.rs
src/librustc_parse/parser/path.rs
src/librustc_parse/parser/stmt.rs

index 49ca5abe97f6446b60046cd554b326692e55c2d2..9a4bef3776865d19185ab92bcd5b007e09da82a1 100644 (file)
@@ -1450,9 +1450,7 @@ fn error_missing_if_cond(&self, lo: Span, span: Span) -> P<ast::Block> {
         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.
index 6f24dfcd027c59dc7fb5710b41cd6010329cb03c..325ad56cd2a43ff896dddaf1459234135e7187b2 100644 (file)
@@ -406,9 +406,11 @@ fn parse_generic_args(&mut self) -> PResult<'a, (Vec<GenericArg>, Vec<AssocTyCon
                     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()?
index 1f72c66ea03d6a4b844f9354636caac1cdb29d83..bf092ed14e342e7e802fb827d39dafa80648b780 100644 (file)
@@ -398,10 +398,7 @@ pub(super) fn parse_block_tail(
                     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 @@ pub(super) fn mk_block(&self, stmts: Vec<Stmt>, rules: BlockCheckMode, span: Spa
     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)
+    }
 }