AST/HIR: Introduce ExprKind::Err
for better error recovery in the front-end
This commit is contained in:
parent
d2986970ad
commit
a5c52c72ae
17 changed files with 51 additions and 11 deletions
|
@ -392,7 +392,8 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
|
||||||
|
|
||||||
hir::ExprKind::Closure(..) |
|
hir::ExprKind::Closure(..) |
|
||||||
hir::ExprKind::Lit(..) |
|
hir::ExprKind::Lit(..) |
|
||||||
hir::ExprKind::Path(_) => {
|
hir::ExprKind::Path(_) |
|
||||||
|
hir::ExprKind::Err => {
|
||||||
self.straightline(expr, pred, None::<hir::Expr>.iter())
|
self.straightline(expr, pred, None::<hir::Expr>.iter())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1099,6 +1099,7 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) {
|
||||||
ExprKind::Yield(ref subexpression) => {
|
ExprKind::Yield(ref subexpression) => {
|
||||||
visitor.visit_expr(subexpression);
|
visitor.visit_expr(subexpression);
|
||||||
}
|
}
|
||||||
|
ExprKind::Err => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4117,6 +4117,8 @@ impl<'a> LoweringContext<'a> {
|
||||||
hir::ExprKind::Yield(P(expr))
|
hir::ExprKind::Yield(P(expr))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ExprKind::Err => hir::ExprKind::Err,
|
||||||
|
|
||||||
// Desugar `ExprIfLet`
|
// Desugar `ExprIfLet`
|
||||||
// from: `if let <pat> = <sub_expr> <body> [<else_opt>]`
|
// from: `if let <pat> = <sub_expr> <body> [<else_opt>]`
|
||||||
ExprKind::IfLet(ref pats, ref sub_expr, ref body, ref else_opt) => {
|
ExprKind::IfLet(ref pats, ref sub_expr, ref body, ref else_opt) => {
|
||||||
|
|
|
@ -1362,6 +1362,7 @@ impl Expr {
|
||||||
ExprKind::Struct(..) => ExprPrecedence::Struct,
|
ExprKind::Struct(..) => ExprPrecedence::Struct,
|
||||||
ExprKind::Repeat(..) => ExprPrecedence::Repeat,
|
ExprKind::Repeat(..) => ExprPrecedence::Repeat,
|
||||||
ExprKind::Yield(..) => ExprPrecedence::Yield,
|
ExprKind::Yield(..) => ExprPrecedence::Yield,
|
||||||
|
ExprKind::Err => ExprPrecedence::Err,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1412,7 +1413,8 @@ impl Expr {
|
||||||
ExprKind::AddrOf(..) |
|
ExprKind::AddrOf(..) |
|
||||||
ExprKind::Binary(..) |
|
ExprKind::Binary(..) |
|
||||||
ExprKind::Yield(..) |
|
ExprKind::Yield(..) |
|
||||||
ExprKind::Cast(..) => {
|
ExprKind::Cast(..) |
|
||||||
|
ExprKind::Err => {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1525,6 +1527,9 @@ pub enum ExprKind {
|
||||||
|
|
||||||
/// A suspension point for generators. This is `yield <expr>` in Rust.
|
/// A suspension point for generators. This is `yield <expr>` in Rust.
|
||||||
Yield(P<Expr>),
|
Yield(P<Expr>),
|
||||||
|
|
||||||
|
/// Placeholder for an expression that wasn't syntactically well formed in some way.
|
||||||
|
Err,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Optionally `Self`-qualified value/type path or associated extension.
|
/// Optionally `Self`-qualified value/type path or associated extension.
|
||||||
|
|
|
@ -430,7 +430,9 @@ impl<'a> State<'a> {
|
||||||
self.s.word("_")?;
|
self.s.word("_")?;
|
||||||
}
|
}
|
||||||
hir::TyKind::Err => {
|
hir::TyKind::Err => {
|
||||||
self.s.word("?")?;
|
self.popen()?;
|
||||||
|
self.s.word("/*ERROR*/")?;
|
||||||
|
self.pclose()?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.end()
|
self.end()
|
||||||
|
@ -1540,6 +1542,11 @@ impl<'a> State<'a> {
|
||||||
self.word_space("yield")?;
|
self.word_space("yield")?;
|
||||||
self.print_expr_maybe_paren(&expr, parser::PREC_JUMP)?;
|
self.print_expr_maybe_paren(&expr, parser::PREC_JUMP)?;
|
||||||
}
|
}
|
||||||
|
hir::ExprKind::Err => {
|
||||||
|
self.popen()?;
|
||||||
|
self.s.word("/*ERROR*/")?;
|
||||||
|
self.pclose()?;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
self.ann.post(self, AnnNode::Expr(expr))?;
|
self.ann.post(self, AnnNode::Expr(expr))?;
|
||||||
self.end()
|
self.end()
|
||||||
|
|
|
@ -592,7 +592,8 @@ impl_stable_hash_for!(enum hir::ExprKind {
|
||||||
InlineAsm(asm, inputs, outputs),
|
InlineAsm(asm, inputs, outputs),
|
||||||
Struct(path, fields, base),
|
Struct(path, fields, base),
|
||||||
Repeat(val, times),
|
Repeat(val, times),
|
||||||
Yield(val)
|
Yield(val),
|
||||||
|
Err
|
||||||
});
|
});
|
||||||
|
|
||||||
impl_stable_hash_for!(enum hir::LocalSource {
|
impl_stable_hash_for!(enum hir::LocalSource {
|
||||||
|
|
|
@ -479,7 +479,8 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
hir::ExprKind::Continue(..) |
|
hir::ExprKind::Continue(..) |
|
||||||
hir::ExprKind::Lit(..) => {}
|
hir::ExprKind::Lit(..) |
|
||||||
|
hir::ExprKind::Err => {}
|
||||||
|
|
||||||
hir::ExprKind::Loop(ref blk, _, _) => {
|
hir::ExprKind::Loop(ref blk, _, _) => {
|
||||||
self.walk_block(&blk);
|
self.walk_block(&blk);
|
||||||
|
|
|
@ -515,6 +515,7 @@ fn visit_expr<'a, 'tcx>(ir: &mut IrMaps<'a, 'tcx>, expr: &'tcx Expr) {
|
||||||
hir::ExprKind::Box(..) |
|
hir::ExprKind::Box(..) |
|
||||||
hir::ExprKind::Yield(..) |
|
hir::ExprKind::Yield(..) |
|
||||||
hir::ExprKind::Type(..) |
|
hir::ExprKind::Type(..) |
|
||||||
|
hir::ExprKind::Err |
|
||||||
hir::ExprKind::Path(hir::QPath::TypeRelative(..)) => {
|
hir::ExprKind::Path(hir::QPath::TypeRelative(..)) => {
|
||||||
intravisit::walk_expr(ir, expr);
|
intravisit::walk_expr(ir, expr);
|
||||||
}
|
}
|
||||||
|
@ -1254,7 +1255,8 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
|
||||||
self.propagate_through_exprs(inputs, succ)
|
self.propagate_through_exprs(inputs, succ)
|
||||||
}
|
}
|
||||||
|
|
||||||
hir::ExprKind::Lit(..) | hir::ExprKind::Path(hir::QPath::TypeRelative(..)) => {
|
hir::ExprKind::Lit(..) | hir::ExprKind::Err |
|
||||||
|
hir::ExprKind::Path(hir::QPath::TypeRelative(..)) => {
|
||||||
succ
|
succ
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1521,7 +1523,7 @@ fn check_expr<'a, 'tcx>(this: &mut Liveness<'a, 'tcx>, expr: &'tcx Expr) {
|
||||||
hir::ExprKind::Block(..) | hir::ExprKind::AddrOf(..) |
|
hir::ExprKind::Block(..) | hir::ExprKind::AddrOf(..) |
|
||||||
hir::ExprKind::Struct(..) | hir::ExprKind::Repeat(..) |
|
hir::ExprKind::Struct(..) | hir::ExprKind::Repeat(..) |
|
||||||
hir::ExprKind::Closure(..) | hir::ExprKind::Path(_) | hir::ExprKind::Yield(..) |
|
hir::ExprKind::Closure(..) | hir::ExprKind::Path(_) | hir::ExprKind::Yield(..) |
|
||||||
hir::ExprKind::Box(..) | hir::ExprKind::Type(..) => {
|
hir::ExprKind::Box(..) | hir::ExprKind::Type(..) | hir::ExprKind::Err => {
|
||||||
intravisit::walk_expr(this, expr);
|
intravisit::walk_expr(this, expr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -687,7 +687,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
|
||||||
hir::ExprKind::Block(..) | hir::ExprKind::Loop(..) | hir::ExprKind::Match(..) |
|
hir::ExprKind::Block(..) | hir::ExprKind::Loop(..) | hir::ExprKind::Match(..) |
|
||||||
hir::ExprKind::Lit(..) | hir::ExprKind::Break(..) |
|
hir::ExprKind::Lit(..) | hir::ExprKind::Break(..) |
|
||||||
hir::ExprKind::Continue(..) | hir::ExprKind::Struct(..) | hir::ExprKind::Repeat(..) |
|
hir::ExprKind::Continue(..) | hir::ExprKind::Struct(..) | hir::ExprKind::Repeat(..) |
|
||||||
hir::ExprKind::InlineAsm(..) | hir::ExprKind::Box(..) => {
|
hir::ExprKind::InlineAsm(..) | hir::ExprKind::Box(..) | hir::ExprKind::Err => {
|
||||||
Ok(self.cat_rvalue_node(expr.hir_id, expr.span, expr_ty))
|
Ok(self.cat_rvalue_node(expr.hir_id, expr.span, expr_ty))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -780,6 +780,7 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
|
||||||
hir::ExprKind::Tup(ref fields) => ExprKind::Tuple { fields: fields.to_ref() },
|
hir::ExprKind::Tup(ref fields) => ExprKind::Tuple { fields: fields.to_ref() },
|
||||||
|
|
||||||
hir::ExprKind::Yield(ref v) => ExprKind::Yield { value: v.to_ref() },
|
hir::ExprKind::Yield(ref v) => ExprKind::Yield { value: v.to_ref() },
|
||||||
|
hir::ExprKind::Err => unreachable!(),
|
||||||
};
|
};
|
||||||
|
|
||||||
Expr {
|
Expr {
|
||||||
|
|
|
@ -449,7 +449,8 @@ fn check_expr_kind<'a, 'tcx>(
|
||||||
struct_result
|
struct_result
|
||||||
}
|
}
|
||||||
|
|
||||||
hir::ExprKind::Lit(_) => Promotable,
|
hir::ExprKind::Lit(_) |
|
||||||
|
hir::ExprKind::Err => Promotable,
|
||||||
|
|
||||||
hir::ExprKind::AddrOf(_, ref expr) |
|
hir::ExprKind::AddrOf(_, ref expr) |
|
||||||
hir::ExprKind::Repeat(ref expr, _) => {
|
hir::ExprKind::Repeat(ref expr, _) => {
|
||||||
|
|
|
@ -4513,6 +4513,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
}
|
}
|
||||||
tcx.mk_unit()
|
tcx.mk_unit()
|
||||||
}
|
}
|
||||||
|
hir::ExprKind::Err => {
|
||||||
|
tcx.types.err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1001,6 +1001,7 @@ impl Expr {
|
||||||
ExprKind::Paren(..) => ExprPrecedence::Paren,
|
ExprKind::Paren(..) => ExprPrecedence::Paren,
|
||||||
ExprKind::Try(..) => ExprPrecedence::Try,
|
ExprKind::Try(..) => ExprPrecedence::Try,
|
||||||
ExprKind::Yield(..) => ExprPrecedence::Yield,
|
ExprKind::Yield(..) => ExprPrecedence::Yield,
|
||||||
|
ExprKind::Err => ExprPrecedence::Err,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1160,6 +1161,9 @@ pub enum ExprKind {
|
||||||
|
|
||||||
/// A `yield`, with an optional value to be yielded.
|
/// A `yield`, with an optional value to be yielded.
|
||||||
Yield(Option<P<Expr>>),
|
Yield(Option<P<Expr>>),
|
||||||
|
|
||||||
|
/// Placeholder for an expression that wasn't syntactically well formed in some way.
|
||||||
|
Err,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The explicit `Self` type in a "qualified path". The actual
|
/// The explicit `Self` type in a "qualified path". The actual
|
||||||
|
|
|
@ -1367,6 +1367,7 @@ pub fn noop_fold_expr<T: Folder>(Expr {id, node, span, attrs}: Expr, folder: &mu
|
||||||
ExprKind::Yield(ex) => ExprKind::Yield(ex.map(|x| folder.fold_expr(x))),
|
ExprKind::Yield(ex) => ExprKind::Yield(ex.map(|x| folder.fold_expr(x))),
|
||||||
ExprKind::Try(ex) => ExprKind::Try(folder.fold_expr(ex)),
|
ExprKind::Try(ex) => ExprKind::Try(folder.fold_expr(ex)),
|
||||||
ExprKind::TryBlock(body) => ExprKind::TryBlock(folder.fold_block(body)),
|
ExprKind::TryBlock(body) => ExprKind::TryBlock(folder.fold_block(body)),
|
||||||
|
ExprKind::Err => ExprKind::Err,
|
||||||
},
|
},
|
||||||
id: folder.new_id(id),
|
id: folder.new_id(id),
|
||||||
span: folder.new_span(span),
|
span: folder.new_span(span),
|
||||||
|
|
|
@ -1093,7 +1093,9 @@ impl<'a> State<'a> {
|
||||||
self.s.word("_")?;
|
self.s.word("_")?;
|
||||||
}
|
}
|
||||||
ast::TyKind::Err => {
|
ast::TyKind::Err => {
|
||||||
self.s.word("?")?;
|
self.popen()?;
|
||||||
|
self.s.word("/*ERROR*/")?;
|
||||||
|
self.pclose()?;
|
||||||
}
|
}
|
||||||
ast::TyKind::ImplicitSelf => {
|
ast::TyKind::ImplicitSelf => {
|
||||||
self.s.word("Self")?;
|
self.s.word("Self")?;
|
||||||
|
@ -2391,6 +2393,11 @@ impl<'a> State<'a> {
|
||||||
self.s.space()?;
|
self.s.space()?;
|
||||||
self.print_block_with_attrs(blk, attrs)?
|
self.print_block_with_attrs(blk, attrs)?
|
||||||
}
|
}
|
||||||
|
ast::ExprKind::Err => {
|
||||||
|
self.popen()?;
|
||||||
|
self.s.word("/*ERROR*/")?;
|
||||||
|
self.pclose()?
|
||||||
|
}
|
||||||
}
|
}
|
||||||
self.ann.post(self, AnnNode::Expr(expr))?;
|
self.ann.post(self, AnnNode::Expr(expr))?;
|
||||||
self.end()
|
self.end()
|
||||||
|
|
|
@ -267,6 +267,7 @@ pub enum ExprPrecedence {
|
||||||
TryBlock,
|
TryBlock,
|
||||||
Struct,
|
Struct,
|
||||||
Async,
|
Async,
|
||||||
|
Err,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ExprPrecedence {
|
impl ExprPrecedence {
|
||||||
|
@ -325,7 +326,8 @@ impl ExprPrecedence {
|
||||||
ExprPrecedence::Block |
|
ExprPrecedence::Block |
|
||||||
ExprPrecedence::TryBlock |
|
ExprPrecedence::TryBlock |
|
||||||
ExprPrecedence::Async |
|
ExprPrecedence::Async |
|
||||||
ExprPrecedence::Struct => PREC_PAREN,
|
ExprPrecedence::Struct |
|
||||||
|
ExprPrecedence::Err => PREC_PAREN,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -802,6 +802,7 @@ pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) {
|
||||||
ExprKind::TryBlock(ref body) => {
|
ExprKind::TryBlock(ref body) => {
|
||||||
visitor.visit_block(body)
|
visitor.visit_block(body)
|
||||||
}
|
}
|
||||||
|
ExprKind::Err => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
visitor.visit_expr_post(expression)
|
visitor.visit_expr_post(expression)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue