Skip to content

Commit 6fba125

Browse files
committed
parser::path: remove .fatal calls
1 parent 51fb599 commit 6fba125

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

src/librustc_parse/parser/expr.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1450,9 +1450,7 @@ impl<'a> Parser<'a> {
14501450
self.struct_span_err(sp, "missing condition for `if` expression")
14511451
.span_label(sp, "expected if condition here")
14521452
.emit();
1453-
let expr = self.mk_expr_err(span);
1454-
let stmt = self.mk_stmt(span, ast::StmtKind::Expr(expr));
1455-
self.mk_block(vec![stmt], BlockCheckMode::Default, span)
1453+
self.mk_block_err(span)
14561454
}
14571455

14581456
/// Parses the condition of a `if` or `while` expression.

src/librustc_parse/parser/path.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -406,9 +406,11 @@ impl<'a> Parser<'a> {
406406
if self.token.is_bool_lit() {
407407
self.parse_literal_maybe_minus()?
408408
} else {
409-
return Err(
410-
self.fatal("identifiers may currently not be used for const generics")
411-
);
409+
let span = self.token.span;
410+
let msg = "identifiers may currently not be used for const generics";
411+
self.struct_span_err(span, msg).emit();
412+
let block = self.mk_block_err(span);
413+
self.mk_expr(span, ast::ExprKind::Block(block, None), ast::AttrVec::new())
412414
}
413415
} else {
414416
self.parse_literal_maybe_minus()?

src/librustc_parse/parser/stmt.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -398,10 +398,7 @@ impl<'a> Parser<'a> {
398398
self.maybe_annotate_with_ascription(&mut err, false);
399399
err.emit();
400400
self.recover_stmt_(SemiColonMode::Ignore, BlockMode::Ignore);
401-
Some(self.mk_stmt(
402-
self.token.span,
403-
StmtKind::Expr(self.mk_expr_err(self.token.span)),
404-
))
401+
Some(self.mk_stmt_err(self.token.span))
405402
}
406403
Ok(stmt) => stmt,
407404
};
@@ -479,4 +476,12 @@ impl<'a> Parser<'a> {
479476
pub(super) fn mk_stmt(&self, span: Span, kind: StmtKind) -> Stmt {
480477
Stmt { id: DUMMY_NODE_ID, kind, span }
481478
}
479+
480+
fn mk_stmt_err(&self, span: Span) -> Stmt {
481+
self.mk_stmt(span, StmtKind::Expr(self.mk_expr_err(span)))
482+
}
483+
484+
pub(super) fn mk_block_err(&self, span: Span) -> P<Block> {
485+
self.mk_block(vec![self.mk_stmt_err(span)], BlockCheckMode::Default, span)
486+
}
482487
}

0 commit comments

Comments
 (0)