Skip to content

Commit a3fce72

Browse files
committed
Add ast::ExprKind::Dummy
1 parent 8c0b1fc commit a3fce72

File tree

18 files changed

+37
-24
lines changed

18 files changed

+37
-24
lines changed

compiler/rustc_ast/src/ast.rs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,23 +1296,10 @@ impl Expr {
12961296
ExprKind::Yeet(..) => ExprPrecedence::Yeet,
12971297
ExprKind::FormatArgs(..) => ExprPrecedence::FormatArgs,
12981298
ExprKind::Become(..) => ExprPrecedence::Become,
1299-
ExprKind::Err => ExprPrecedence::Err,
1299+
ExprKind::Err | ExprKind::Dummy => ExprPrecedence::Err,
13001300
}
13011301
}
13021302

1303-
pub fn take(&mut self) -> Self {
1304-
mem::replace(
1305-
self,
1306-
Expr {
1307-
id: DUMMY_NODE_ID,
1308-
kind: ExprKind::Err,
1309-
span: DUMMY_SP,
1310-
attrs: AttrVec::new(),
1311-
tokens: None,
1312-
},
1313-
)
1314-
}
1315-
13161303
/// To a first-order approximation, is this a pattern?
13171304
pub fn is_approximately_pattern(&self) -> bool {
13181305
matches!(
@@ -1532,6 +1519,9 @@ pub enum ExprKind {
15321519

15331520
/// Placeholder for an expression that wasn't syntactically well formed in some way.
15341521
Err,
1522+
1523+
/// Acts as a null expression. Lowering it will always emit a bug.
1524+
Dummy,
15351525
}
15361526

15371527
/// Used to differentiate between `for` loops and `for await` loops.

compiler/rustc_ast/src/mut_visit.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1526,7 +1526,7 @@ pub fn noop_visit_expr<T: MutVisitor>(
15261526
}
15271527
ExprKind::Try(expr) => vis.visit_expr(expr),
15281528
ExprKind::TryBlock(body) => vis.visit_block(body),
1529-
ExprKind::Lit(_) | ExprKind::IncludedBytes(..) | ExprKind::Err => {}
1529+
ExprKind::Lit(_) | ExprKind::IncludedBytes(..) | ExprKind::Err | ExprKind::Dummy => {}
15301530
}
15311531
vis.visit_id(id);
15321532
vis.visit_span(span);
@@ -1642,7 +1642,7 @@ impl DummyAstNode for Expr {
16421642
fn dummy() -> Self {
16431643
Expr {
16441644
id: DUMMY_NODE_ID,
1645-
kind: ExprKind::Err,
1645+
kind: ExprKind::Dummy,
16461646
span: Default::default(),
16471647
attrs: Default::default(),
16481648
tokens: Default::default(),

compiler/rustc_ast/src/util/classify.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ pub fn expr_trailing_brace(mut expr: &ast::Expr) -> Option<&ast::Expr> {
8989
| Paren(_)
9090
| Try(_)
9191
| Yeet(None)
92-
| Err => break None,
92+
| Err
93+
| Dummy => break None,
9394
}
9495
}
9596
}

compiler/rustc_ast/src/visit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1063,7 +1063,7 @@ pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) -> V
10631063
}
10641064
ExprKind::Try(subexpression) => try_visit!(visitor.visit_expr(subexpression)),
10651065
ExprKind::TryBlock(body) => try_visit!(visitor.visit_block(body)),
1066-
ExprKind::Lit(_) | ExprKind::IncludedBytes(..) | ExprKind::Err => {}
1066+
ExprKind::Lit(_) | ExprKind::IncludedBytes(..) | ExprKind::Err | ExprKind::Dummy => {}
10671067
}
10681068

10691069
visitor.visit_expr_post(expression)

compiler/rustc_ast_lowering/src/expr.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use rustc_ast::*;
1414
use rustc_data_structures::stack::ensure_sufficient_stack;
1515
use rustc_hir as hir;
1616
use rustc_hir::def::{DefKind, Res};
17+
use rustc_middle::span_bug;
1718
use rustc_session::errors::report_lit_error;
1819
use rustc_span::source_map::{respan, Spanned};
1920
use rustc_span::symbol::{kw, sym, Ident, Symbol};
@@ -331,6 +332,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
331332
ExprKind::Err => {
332333
hir::ExprKind::Err(self.dcx().span_delayed_bug(e.span, "lowered ExprKind::Err"))
333334
}
335+
336+
ExprKind::Dummy => {
337+
span_bug!(e.span, "lowered ExprKind::Dummy")
338+
}
339+
334340
ExprKind::Try(sub_expr) => self.lower_expr_try(e.span, sub_expr),
335341

336342
ExprKind::Paren(_) | ExprKind::ForLoop { .. } => {

compiler/rustc_ast_lowering/src/pat.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
331331
ExprKind::Lit(..)
332332
| ExprKind::ConstBlock(..)
333333
| ExprKind::IncludedBytes(..)
334-
| ExprKind::Err => {}
334+
| ExprKind::Err
335+
| ExprKind::Dummy => {}
335336
ExprKind::Path(..) if allow_paths => {}
336337
ExprKind::Unary(UnOp::Neg, inner) if matches!(inner.kind, ExprKind::Lit(_)) => {}
337338
_ => {

compiler/rustc_ast_pretty/src/pprust/state/expr.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -898,6 +898,11 @@ impl<'a> State<'a> {
898898
self.word("/*ERROR*/");
899899
self.pclose()
900900
}
901+
ast::ExprKind::Dummy => {
902+
self.popen();
903+
self.word("/*DUMMY*/");
904+
self.pclose();
905+
}
901906
}
902907

903908
self.ann.post(self, AnnNode::Expr(expr));

compiler/rustc_builtin_macros/src/assert/context.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ impl<'cx, 'a> Context<'cx, 'a> {
303303
| ExprKind::Closure(_)
304304
| ExprKind::ConstBlock(_)
305305
| ExprKind::Continue(_)
306+
| ExprKind::Dummy
306307
| ExprKind::Err
307308
| ExprKind::Field(_, _)
308309
| ExprKind::ForLoop { .. }

compiler/rustc_builtin_macros/src/concat.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ pub fn expand_concat(
6868
ast::ExprKind::Err => {
6969
has_errors = true;
7070
}
71+
ast::ExprKind::Dummy => cx.dcx().span_bug(e.span, "concatenating `ExprKind::Dummy`"),
7172
_ => {
7273
missing_literal.push(e.span);
7374
}

compiler/rustc_builtin_macros/src/concat_bytes.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ pub fn expand_concat_bytes(
176176
ast::ExprKind::Err => {
177177
has_errors = true;
178178
}
179+
ast::ExprKind::Dummy => cx.dcx().span_bug(e.span, "concatenating `ExprKind::Dummy`"),
179180
_ => {
180181
missing_literals.push(e.span);
181182
}

0 commit comments

Comments
 (0)