AST/HIR: Introduce ExprKind::Err
for better error recovery in the front-end
This commit is contained in:
parent
d2986970ad
commit
a5c52c72ae
@ -392,7 +392,8 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
|
||||
|
||||
hir::ExprKind::Closure(..) |
|
||||
hir::ExprKind::Lit(..) |
|
||||
hir::ExprKind::Path(_) => {
|
||||
hir::ExprKind::Path(_) |
|
||||
hir::ExprKind::Err => {
|
||||
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) => {
|
||||
visitor.visit_expr(subexpression);
|
||||
}
|
||||
ExprKind::Err => {}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4117,6 +4117,8 @@ impl<'a> LoweringContext<'a> {
|
||||
hir::ExprKind::Yield(P(expr))
|
||||
}
|
||||
|
||||
ExprKind::Err => hir::ExprKind::Err,
|
||||
|
||||
// Desugar `ExprIfLet`
|
||||
// from: `if let <pat> = <sub_expr> <body> [<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::Repeat(..) => ExprPrecedence::Repeat,
|
||||
ExprKind::Yield(..) => ExprPrecedence::Yield,
|
||||
ExprKind::Err => ExprPrecedence::Err,
|
||||
}
|
||||
}
|
||||
|
||||
@ -1412,7 +1413,8 @@ impl Expr {
|
||||
ExprKind::AddrOf(..) |
|
||||
ExprKind::Binary(..) |
|
||||
ExprKind::Yield(..) |
|
||||
ExprKind::Cast(..) => {
|
||||
ExprKind::Cast(..) |
|
||||
ExprKind::Err => {
|
||||
false
|
||||
}
|
||||
}
|
||||
@ -1525,6 +1527,9 @@ pub enum ExprKind {
|
||||
|
||||
/// A suspension point for generators. This is `yield <expr>` in Rust.
|
||||
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.
|
||||
|
@ -430,7 +430,9 @@ impl<'a> State<'a> {
|
||||
self.s.word("_")?;
|
||||
}
|
||||
hir::TyKind::Err => {
|
||||
self.s.word("?")?;
|
||||
self.popen()?;
|
||||
self.s.word("/*ERROR*/")?;
|
||||
self.pclose()?;
|
||||
}
|
||||
}
|
||||
self.end()
|
||||
@ -1540,6 +1542,11 @@ impl<'a> State<'a> {
|
||||
self.word_space("yield")?;
|
||||
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.end()
|
||||
|
@ -592,7 +592,8 @@ impl_stable_hash_for!(enum hir::ExprKind {
|
||||
InlineAsm(asm, inputs, outputs),
|
||||
Struct(path, fields, base),
|
||||
Repeat(val, times),
|
||||
Yield(val)
|
||||
Yield(val),
|
||||
Err
|
||||
});
|
||||
|
||||
impl_stable_hash_for!(enum hir::LocalSource {
|
||||
|
@ -479,7 +479,8 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
|
||||
}
|
||||
|
||||
hir::ExprKind::Continue(..) |
|
||||
hir::ExprKind::Lit(..) => {}
|
||||
hir::ExprKind::Lit(..) |
|
||||
hir::ExprKind::Err => {}
|
||||
|
||||
hir::ExprKind::Loop(ref 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::Yield(..) |
|
||||
hir::ExprKind::Type(..) |
|
||||
hir::ExprKind::Err |
|
||||
hir::ExprKind::Path(hir::QPath::TypeRelative(..)) => {
|
||||
intravisit::walk_expr(ir, expr);
|
||||
}
|
||||
@ -1254,7 +1255,8 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
|
||||
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
|
||||
}
|
||||
|
||||
@ -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::Struct(..) | hir::ExprKind::Repeat(..) |
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -687,7 +687,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
|
||||
hir::ExprKind::Block(..) | hir::ExprKind::Loop(..) | hir::ExprKind::Match(..) |
|
||||
hir::ExprKind::Lit(..) | hir::ExprKind::Break(..) |
|
||||
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))
|
||||
}
|
||||
}
|
||||
|
@ -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::Yield(ref v) => ExprKind::Yield { value: v.to_ref() },
|
||||
hir::ExprKind::Err => unreachable!(),
|
||||
};
|
||||
|
||||
Expr {
|
||||
|
@ -449,7 +449,8 @@ fn check_expr_kind<'a, 'tcx>(
|
||||
struct_result
|
||||
}
|
||||
|
||||
hir::ExprKind::Lit(_) => Promotable,
|
||||
hir::ExprKind::Lit(_) |
|
||||
hir::ExprKind::Err => Promotable,
|
||||
|
||||
hir::ExprKind::AddrOf(_, ref expr) |
|
||||
hir::ExprKind::Repeat(ref expr, _) => {
|
||||
|
@ -4513,6 +4513,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||
}
|
||||
tcx.mk_unit()
|
||||
}
|
||||
hir::ExprKind::Err => {
|
||||
tcx.types.err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1001,6 +1001,7 @@ impl Expr {
|
||||
ExprKind::Paren(..) => ExprPrecedence::Paren,
|
||||
ExprKind::Try(..) => ExprPrecedence::Try,
|
||||
ExprKind::Yield(..) => ExprPrecedence::Yield,
|
||||
ExprKind::Err => ExprPrecedence::Err,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1160,6 +1161,9 @@ pub enum ExprKind {
|
||||
|
||||
/// A `yield`, with an optional value to be yielded.
|
||||
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
|
||||
|
@ -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::Try(ex) => ExprKind::Try(folder.fold_expr(ex)),
|
||||
ExprKind::TryBlock(body) => ExprKind::TryBlock(folder.fold_block(body)),
|
||||
ExprKind::Err => ExprKind::Err,
|
||||
},
|
||||
id: folder.new_id(id),
|
||||
span: folder.new_span(span),
|
||||
|
@ -1093,7 +1093,9 @@ impl<'a> State<'a> {
|
||||
self.s.word("_")?;
|
||||
}
|
||||
ast::TyKind::Err => {
|
||||
self.s.word("?")?;
|
||||
self.popen()?;
|
||||
self.s.word("/*ERROR*/")?;
|
||||
self.pclose()?;
|
||||
}
|
||||
ast::TyKind::ImplicitSelf => {
|
||||
self.s.word("Self")?;
|
||||
@ -2391,6 +2393,11 @@ impl<'a> State<'a> {
|
||||
self.s.space()?;
|
||||
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.end()
|
||||
|
@ -267,6 +267,7 @@ pub enum ExprPrecedence {
|
||||
TryBlock,
|
||||
Struct,
|
||||
Async,
|
||||
Err,
|
||||
}
|
||||
|
||||
impl ExprPrecedence {
|
||||
@ -325,7 +326,8 @@ impl ExprPrecedence {
|
||||
ExprPrecedence::Block |
|
||||
ExprPrecedence::TryBlock |
|
||||
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) => {
|
||||
visitor.visit_block(body)
|
||||
}
|
||||
ExprKind::Err => {}
|
||||
}
|
||||
|
||||
visitor.visit_expr_post(expression)
|
||||
|
Loading…
Reference in New Issue
Block a user