Add ast::ExprKind::Dummy
This commit is contained in:
parent
8c0b1fcd29
commit
a3fce72a27
18 changed files with 37 additions and 24 deletions
|
@ -1296,23 +1296,10 @@ impl Expr {
|
||||||
ExprKind::Yeet(..) => ExprPrecedence::Yeet,
|
ExprKind::Yeet(..) => ExprPrecedence::Yeet,
|
||||||
ExprKind::FormatArgs(..) => ExprPrecedence::FormatArgs,
|
ExprKind::FormatArgs(..) => ExprPrecedence::FormatArgs,
|
||||||
ExprKind::Become(..) => ExprPrecedence::Become,
|
ExprKind::Become(..) => ExprPrecedence::Become,
|
||||||
ExprKind::Err => ExprPrecedence::Err,
|
ExprKind::Err | ExprKind::Dummy => ExprPrecedence::Err,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn take(&mut self) -> Self {
|
|
||||||
mem::replace(
|
|
||||||
self,
|
|
||||||
Expr {
|
|
||||||
id: DUMMY_NODE_ID,
|
|
||||||
kind: ExprKind::Err,
|
|
||||||
span: DUMMY_SP,
|
|
||||||
attrs: AttrVec::new(),
|
|
||||||
tokens: None,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// To a first-order approximation, is this a pattern?
|
/// To a first-order approximation, is this a pattern?
|
||||||
pub fn is_approximately_pattern(&self) -> bool {
|
pub fn is_approximately_pattern(&self) -> bool {
|
||||||
matches!(
|
matches!(
|
||||||
|
@ -1532,6 +1519,9 @@ pub enum ExprKind {
|
||||||
|
|
||||||
/// Placeholder for an expression that wasn't syntactically well formed in some way.
|
/// Placeholder for an expression that wasn't syntactically well formed in some way.
|
||||||
Err,
|
Err,
|
||||||
|
|
||||||
|
/// Acts as a null expression. Lowering it will always emit a bug.
|
||||||
|
Dummy,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Used to differentiate between `for` loops and `for await` loops.
|
/// Used to differentiate between `for` loops and `for await` loops.
|
||||||
|
|
|
@ -1526,7 +1526,7 @@ pub fn noop_visit_expr<T: MutVisitor>(
|
||||||
}
|
}
|
||||||
ExprKind::Try(expr) => vis.visit_expr(expr),
|
ExprKind::Try(expr) => vis.visit_expr(expr),
|
||||||
ExprKind::TryBlock(body) => vis.visit_block(body),
|
ExprKind::TryBlock(body) => vis.visit_block(body),
|
||||||
ExprKind::Lit(_) | ExprKind::IncludedBytes(..) | ExprKind::Err => {}
|
ExprKind::Lit(_) | ExprKind::IncludedBytes(..) | ExprKind::Err | ExprKind::Dummy => {}
|
||||||
}
|
}
|
||||||
vis.visit_id(id);
|
vis.visit_id(id);
|
||||||
vis.visit_span(span);
|
vis.visit_span(span);
|
||||||
|
@ -1642,7 +1642,7 @@ impl DummyAstNode for Expr {
|
||||||
fn dummy() -> Self {
|
fn dummy() -> Self {
|
||||||
Expr {
|
Expr {
|
||||||
id: DUMMY_NODE_ID,
|
id: DUMMY_NODE_ID,
|
||||||
kind: ExprKind::Err,
|
kind: ExprKind::Dummy,
|
||||||
span: Default::default(),
|
span: Default::default(),
|
||||||
attrs: Default::default(),
|
attrs: Default::default(),
|
||||||
tokens: Default::default(),
|
tokens: Default::default(),
|
||||||
|
|
|
@ -89,7 +89,8 @@ pub fn expr_trailing_brace(mut expr: &ast::Expr) -> Option<&ast::Expr> {
|
||||||
| Paren(_)
|
| Paren(_)
|
||||||
| Try(_)
|
| Try(_)
|
||||||
| Yeet(None)
|
| Yeet(None)
|
||||||
| Err => break None,
|
| Err
|
||||||
|
| Dummy => break None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1063,7 +1063,7 @@ pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) -> V
|
||||||
}
|
}
|
||||||
ExprKind::Try(subexpression) => try_visit!(visitor.visit_expr(subexpression)),
|
ExprKind::Try(subexpression) => try_visit!(visitor.visit_expr(subexpression)),
|
||||||
ExprKind::TryBlock(body) => try_visit!(visitor.visit_block(body)),
|
ExprKind::TryBlock(body) => try_visit!(visitor.visit_block(body)),
|
||||||
ExprKind::Lit(_) | ExprKind::IncludedBytes(..) | ExprKind::Err => {}
|
ExprKind::Lit(_) | ExprKind::IncludedBytes(..) | ExprKind::Err | ExprKind::Dummy => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
visitor.visit_expr_post(expression)
|
visitor.visit_expr_post(expression)
|
||||||
|
|
|
@ -14,6 +14,7 @@ use rustc_ast::*;
|
||||||
use rustc_data_structures::stack::ensure_sufficient_stack;
|
use rustc_data_structures::stack::ensure_sufficient_stack;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def::{DefKind, Res};
|
use rustc_hir::def::{DefKind, Res};
|
||||||
|
use rustc_middle::span_bug;
|
||||||
use rustc_session::errors::report_lit_error;
|
use rustc_session::errors::report_lit_error;
|
||||||
use rustc_span::source_map::{respan, Spanned};
|
use rustc_span::source_map::{respan, Spanned};
|
||||||
use rustc_span::symbol::{kw, sym, Ident, Symbol};
|
use rustc_span::symbol::{kw, sym, Ident, Symbol};
|
||||||
|
@ -331,6 +332,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
ExprKind::Err => {
|
ExprKind::Err => {
|
||||||
hir::ExprKind::Err(self.dcx().span_delayed_bug(e.span, "lowered ExprKind::Err"))
|
hir::ExprKind::Err(self.dcx().span_delayed_bug(e.span, "lowered ExprKind::Err"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ExprKind::Dummy => {
|
||||||
|
span_bug!(e.span, "lowered ExprKind::Dummy")
|
||||||
|
}
|
||||||
|
|
||||||
ExprKind::Try(sub_expr) => self.lower_expr_try(e.span, sub_expr),
|
ExprKind::Try(sub_expr) => self.lower_expr_try(e.span, sub_expr),
|
||||||
|
|
||||||
ExprKind::Paren(_) | ExprKind::ForLoop { .. } => {
|
ExprKind::Paren(_) | ExprKind::ForLoop { .. } => {
|
||||||
|
|
|
@ -331,7 +331,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
ExprKind::Lit(..)
|
ExprKind::Lit(..)
|
||||||
| ExprKind::ConstBlock(..)
|
| ExprKind::ConstBlock(..)
|
||||||
| ExprKind::IncludedBytes(..)
|
| ExprKind::IncludedBytes(..)
|
||||||
| ExprKind::Err => {}
|
| ExprKind::Err
|
||||||
|
| ExprKind::Dummy => {}
|
||||||
ExprKind::Path(..) if allow_paths => {}
|
ExprKind::Path(..) if allow_paths => {}
|
||||||
ExprKind::Unary(UnOp::Neg, inner) if matches!(inner.kind, ExprKind::Lit(_)) => {}
|
ExprKind::Unary(UnOp::Neg, inner) if matches!(inner.kind, ExprKind::Lit(_)) => {}
|
||||||
_ => {
|
_ => {
|
||||||
|
|
|
@ -898,6 +898,11 @@ impl<'a> State<'a> {
|
||||||
self.word("/*ERROR*/");
|
self.word("/*ERROR*/");
|
||||||
self.pclose()
|
self.pclose()
|
||||||
}
|
}
|
||||||
|
ast::ExprKind::Dummy => {
|
||||||
|
self.popen();
|
||||||
|
self.word("/*DUMMY*/");
|
||||||
|
self.pclose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.ann.post(self, AnnNode::Expr(expr));
|
self.ann.post(self, AnnNode::Expr(expr));
|
||||||
|
|
|
@ -303,6 +303,7 @@ impl<'cx, 'a> Context<'cx, 'a> {
|
||||||
| ExprKind::Closure(_)
|
| ExprKind::Closure(_)
|
||||||
| ExprKind::ConstBlock(_)
|
| ExprKind::ConstBlock(_)
|
||||||
| ExprKind::Continue(_)
|
| ExprKind::Continue(_)
|
||||||
|
| ExprKind::Dummy
|
||||||
| ExprKind::Err
|
| ExprKind::Err
|
||||||
| ExprKind::Field(_, _)
|
| ExprKind::Field(_, _)
|
||||||
| ExprKind::ForLoop { .. }
|
| ExprKind::ForLoop { .. }
|
||||||
|
|
|
@ -68,6 +68,7 @@ pub fn expand_concat(
|
||||||
ast::ExprKind::Err => {
|
ast::ExprKind::Err => {
|
||||||
has_errors = true;
|
has_errors = true;
|
||||||
}
|
}
|
||||||
|
ast::ExprKind::Dummy => cx.dcx().span_bug(e.span, "concatenating `ExprKind::Dummy`"),
|
||||||
_ => {
|
_ => {
|
||||||
missing_literal.push(e.span);
|
missing_literal.push(e.span);
|
||||||
}
|
}
|
||||||
|
|
|
@ -176,6 +176,7 @@ pub fn expand_concat_bytes(
|
||||||
ast::ExprKind::Err => {
|
ast::ExprKind::Err => {
|
||||||
has_errors = true;
|
has_errors = true;
|
||||||
}
|
}
|
||||||
|
ast::ExprKind::Dummy => cx.dcx().span_bug(e.span, "concatenating `ExprKind::Dummy`"),
|
||||||
_ => {
|
_ => {
|
||||||
missing_literals.push(e.span);
|
missing_literals.push(e.span);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1279,6 +1279,9 @@ pub fn expr_to_spanned_string<'a>(
|
||||||
_ => Some((cx.dcx().struct_span_err(expr.span, err_msg), false)),
|
_ => Some((cx.dcx().struct_span_err(expr.span, err_msg), false)),
|
||||||
},
|
},
|
||||||
ast::ExprKind::Err => None,
|
ast::ExprKind::Err => None,
|
||||||
|
ast::ExprKind::Dummy => {
|
||||||
|
cx.dcx().span_bug(expr.span, "tried to get a string literal from `ExprKind::Dummy`")
|
||||||
|
}
|
||||||
_ => Some((cx.dcx().struct_span_err(expr.span, err_msg), false)),
|
_ => Some((cx.dcx().struct_span_err(expr.span, err_msg), false)),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -3949,7 +3949,8 @@ impl MutVisitor for CondChecker<'_> {
|
||||||
| ExprKind::Become(_)
|
| ExprKind::Become(_)
|
||||||
| ExprKind::IncludedBytes(_)
|
| ExprKind::IncludedBytes(_)
|
||||||
| ExprKind::FormatArgs(_)
|
| ExprKind::FormatArgs(_)
|
||||||
| ExprKind::Err => {
|
| ExprKind::Err
|
||||||
|
| ExprKind::Dummy => {
|
||||||
// These would forbid any let expressions they contain already.
|
// These would forbid any let expressions they contain already.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -388,7 +388,7 @@ impl<'a> Parser<'a> {
|
||||||
// Parse `?`, `.f`, `(arg0, arg1, ...)` or `[expr]` until they've all been eaten.
|
// Parse `?`, `.f`, `(arg0, arg1, ...)` or `[expr]` until they've all been eaten.
|
||||||
if let Ok(expr) = snapshot
|
if let Ok(expr) = snapshot
|
||||||
.parse_expr_dot_or_call_with(
|
.parse_expr_dot_or_call_with(
|
||||||
self.mk_expr_err(pat_span), // equivalent to transforming the parsed pattern into an `Expr`
|
self.mk_expr(pat_span, ExprKind::Dummy), // equivalent to transforming the parsed pattern into an `Expr`
|
||||||
pat_span,
|
pat_span,
|
||||||
AttrVec::new(),
|
AttrVec::new(),
|
||||||
)
|
)
|
||||||
|
|
|
@ -589,7 +589,7 @@ impl<'v> ast_visit::Visitor<'v> for StatCollector<'v> {
|
||||||
If, While, ForLoop, Loop, Match, Closure, Block, Await, TryBlock, Assign,
|
If, While, ForLoop, Loop, Match, Closure, Block, Await, TryBlock, Assign,
|
||||||
AssignOp, Field, Index, Range, Underscore, Path, AddrOf, Break, Continue, Ret,
|
AssignOp, Field, Index, Range, Underscore, Path, AddrOf, Break, Continue, Ret,
|
||||||
InlineAsm, FormatArgs, OffsetOf, MacCall, Struct, Repeat, Paren, Try, Yield, Yeet,
|
InlineAsm, FormatArgs, OffsetOf, MacCall, Struct, Repeat, Paren, Try, Yield, Yeet,
|
||||||
Become, IncludedBytes, Gen, Err
|
Become, IncludedBytes, Gen, Err, Dummy
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
ast_visit::walk_expr(self, e)
|
ast_visit::walk_expr(self, e)
|
||||||
|
|
|
@ -144,6 +144,7 @@ pub fn eq_expr(l: &Expr, r: &Expr) -> bool {
|
||||||
(Paren(l), _) => eq_expr(l, r),
|
(Paren(l), _) => eq_expr(l, r),
|
||||||
(_, Paren(r)) => eq_expr(l, r),
|
(_, Paren(r)) => eq_expr(l, r),
|
||||||
(Err, Err) => true,
|
(Err, Err) => true,
|
||||||
|
(Dummy, _) | (_, Dummy) => unreachable!("comparing `ExprKind::Dummy`"),
|
||||||
(Try(l), Try(r)) | (Await(l, _), Await(r, _)) => eq_expr(l, r),
|
(Try(l), Try(r)) | (Await(l, _), Await(r, _)) => eq_expr(l, r),
|
||||||
(Array(l), Array(r)) => over(l, r, |l, r| eq_expr(l, r)),
|
(Array(l), Array(r)) => over(l, r, |l, r| eq_expr(l, r)),
|
||||||
(Tup(l), Tup(r)) => over(l, r, |l, r| eq_expr(l, r)),
|
(Tup(l), Tup(r)) => over(l, r, |l, r| eq_expr(l, r)),
|
||||||
|
|
|
@ -222,7 +222,8 @@ impl<'a> Sugg<'a> {
|
||||||
| ast::ExprKind::Array(..)
|
| ast::ExprKind::Array(..)
|
||||||
| ast::ExprKind::While(..)
|
| ast::ExprKind::While(..)
|
||||||
| ast::ExprKind::Await(..)
|
| ast::ExprKind::Await(..)
|
||||||
| ast::ExprKind::Err => Sugg::NonParen(snippet_with_context(cx, expr.span, ctxt, default, app).0),
|
| ast::ExprKind::Err
|
||||||
|
| ast::ExprKind::Dummy => Sugg::NonParen(snippet_with_context(cx, expr.span, ctxt, default, app).0),
|
||||||
ast::ExprKind::Range(ref lhs, ref rhs, RangeLimits::HalfOpen) => Sugg::BinOp(
|
ast::ExprKind::Range(ref lhs, ref rhs, RangeLimits::HalfOpen) => Sugg::BinOp(
|
||||||
AssocOp::DotDot,
|
AssocOp::DotDot,
|
||||||
lhs.as_ref().map_or("".into(), |lhs| {
|
lhs.as_ref().map_or("".into(), |lhs| {
|
||||||
|
|
|
@ -404,7 +404,7 @@ pub(crate) fn format_expr(
|
||||||
// These do not occur in the AST because macros aren't expanded.
|
// These do not occur in the AST because macros aren't expanded.
|
||||||
unreachable!()
|
unreachable!()
|
||||||
}
|
}
|
||||||
ast::ExprKind::Err => None,
|
ast::ExprKind::Err | ast::ExprKind::Dummy => None,
|
||||||
};
|
};
|
||||||
|
|
||||||
expr_rw
|
expr_rw
|
||||||
|
|
|
@ -497,6 +497,7 @@ pub(crate) fn is_block_expr(context: &RewriteContext<'_>, expr: &ast::Expr, repr
|
||||||
| ast::ExprKind::Break(..)
|
| ast::ExprKind::Break(..)
|
||||||
| ast::ExprKind::Cast(..)
|
| ast::ExprKind::Cast(..)
|
||||||
| ast::ExprKind::Continue(..)
|
| ast::ExprKind::Continue(..)
|
||||||
|
| ast::ExprKind::Dummy
|
||||||
| ast::ExprKind::Err
|
| ast::ExprKind::Err
|
||||||
| ast::ExprKind::Field(..)
|
| ast::ExprKind::Field(..)
|
||||||
| ast::ExprKind::IncludedBytes(..)
|
| ast::ExprKind::IncludedBytes(..)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue