Skip to content

Commit 691e788

Browse files
committed
Remove DummyAstNode.
It was added in #91519 to allow `visit_clobber` to be used in one extra place, but is seemingly no longer needed.
1 parent ce9ff20 commit 691e788

File tree

2 files changed

+9
-126
lines changed

2 files changed

+9
-126
lines changed

compiler/rustc_ast/src/mut_visit.rs

+7-117
Original file line numberDiff line numberDiff line change
@@ -310,21 +310,19 @@ pub trait MutVisitor: Sized {
310310

311311
/// Use a map-style function (`FnOnce(T) -> T`) to overwrite a `&mut T`. Useful
312312
/// when using a `flat_map_*` or `filter_map_*` method within a `visit_`
313-
/// method.
313+
/// method. Abort the program if the closure panics. (We used to overwrite `t`
314+
/// with a dummy value and then resume unwinding, but having to provide a dummy
315+
/// value for all the relevant AST nodes was a pain. If you need that back,
316+
/// revert the relevant change from #121827.)
314317
//
315318
// No `noop_` prefix because there isn't a corresponding method in `MutVisitor`.
316-
pub fn visit_clobber<T: DummyAstNode>(t: &mut T, f: impl FnOnce(T) -> T) {
319+
pub fn visit_clobber<T>(t: &mut T, f: impl FnOnce(T) -> T) {
317320
unsafe {
318321
// Safe because `t` is used in a read-only fashion by `read()` before
319322
// being overwritten by `write()`.
320323
let old_t = ptr::read(t);
321-
let new_t =
322-
panic::catch_unwind(panic::AssertUnwindSafe(|| f(old_t))).unwrap_or_else(|err| {
323-
// Set `t` to some valid but possible meaningless value,
324-
// and pass the fatal error further.
325-
ptr::write(t, T::dummy());
326-
panic::resume_unwind(err);
327-
});
324+
let new_t = panic::catch_unwind(panic::AssertUnwindSafe(|| f(old_t)))
325+
.unwrap_or_else(|_| std::process::abort());
328326
ptr::write(t, new_t);
329327
}
330328
}
@@ -1602,111 +1600,3 @@ pub fn noop_visit_capture_by<T: MutVisitor>(capture_by: &mut CaptureBy, vis: &mu
16021600
}
16031601
}
16041602
}
1605-
1606-
/// Some value for the AST node that is valid but possibly meaningless. The
1607-
/// value will never be used meaningfully, it exists just to support unwinding
1608-
/// in `visit_clobber` in the case where its closure panics.
1609-
pub trait DummyAstNode {
1610-
fn dummy() -> Self;
1611-
}
1612-
1613-
impl<T> DummyAstNode for Option<T> {
1614-
fn dummy() -> Self {
1615-
Default::default()
1616-
}
1617-
}
1618-
1619-
impl<T: DummyAstNode + 'static> DummyAstNode for P<T> {
1620-
fn dummy() -> Self {
1621-
P(DummyAstNode::dummy())
1622-
}
1623-
}
1624-
1625-
impl DummyAstNode for Item {
1626-
fn dummy() -> Self {
1627-
Item {
1628-
attrs: Default::default(),
1629-
id: DUMMY_NODE_ID,
1630-
span: Default::default(),
1631-
vis: Visibility {
1632-
kind: VisibilityKind::Public,
1633-
span: Default::default(),
1634-
tokens: Default::default(),
1635-
},
1636-
ident: Ident::empty(),
1637-
kind: ItemKind::ExternCrate(None),
1638-
tokens: Default::default(),
1639-
}
1640-
}
1641-
}
1642-
1643-
impl DummyAstNode for Expr {
1644-
fn dummy() -> Self {
1645-
Expr {
1646-
id: DUMMY_NODE_ID,
1647-
kind: ExprKind::Dummy,
1648-
span: Default::default(),
1649-
attrs: Default::default(),
1650-
tokens: Default::default(),
1651-
}
1652-
}
1653-
}
1654-
1655-
impl DummyAstNode for Ty {
1656-
fn dummy() -> Self {
1657-
Ty {
1658-
id: DUMMY_NODE_ID,
1659-
kind: TyKind::Dummy,
1660-
span: Default::default(),
1661-
tokens: Default::default(),
1662-
}
1663-
}
1664-
}
1665-
1666-
impl DummyAstNode for Pat {
1667-
fn dummy() -> Self {
1668-
Pat {
1669-
id: DUMMY_NODE_ID,
1670-
kind: PatKind::Wild,
1671-
span: Default::default(),
1672-
tokens: Default::default(),
1673-
}
1674-
}
1675-
}
1676-
1677-
impl DummyAstNode for Stmt {
1678-
fn dummy() -> Self {
1679-
Stmt { id: DUMMY_NODE_ID, kind: StmtKind::Empty, span: Default::default() }
1680-
}
1681-
}
1682-
1683-
impl DummyAstNode for Block {
1684-
fn dummy() -> Self {
1685-
Block {
1686-
stmts: Default::default(),
1687-
id: DUMMY_NODE_ID,
1688-
rules: BlockCheckMode::Default,
1689-
span: Default::default(),
1690-
tokens: Default::default(),
1691-
could_be_bare_literal: Default::default(),
1692-
}
1693-
}
1694-
}
1695-
1696-
impl DummyAstNode for Crate {
1697-
fn dummy() -> Self {
1698-
Crate {
1699-
attrs: Default::default(),
1700-
items: Default::default(),
1701-
spans: Default::default(),
1702-
id: DUMMY_NODE_ID,
1703-
is_placeholder: Default::default(),
1704-
}
1705-
}
1706-
}
1707-
1708-
impl<N: DummyAstNode, T: DummyAstNode> DummyAstNode for crate::ast_traits::AstNodeWrapper<N, T> {
1709-
fn dummy() -> Self {
1710-
crate::ast_traits::AstNodeWrapper::new(N::dummy(), T::dummy())
1711-
}
1712-
}

compiler/rustc_expand/src/expand.rs

+2-9
Original file line numberDiff line numberDiff line change
@@ -1556,11 +1556,7 @@ impl InvocationCollectorNode for AstNodeWrapper<P<ast::Expr>, OptExprTag> {
15561556
/// This struct is a hack to workaround unstable of `stmt_expr_attributes`.
15571557
/// It can be removed once that feature is stabilized.
15581558
struct MethodReceiverTag;
1559-
impl DummyAstNode for MethodReceiverTag {
1560-
fn dummy() -> MethodReceiverTag {
1561-
MethodReceiverTag
1562-
}
1563-
}
1559+
15641560
impl InvocationCollectorNode for AstNodeWrapper<P<ast::Expr>, MethodReceiverTag> {
15651561
type OutputTy = Self;
15661562
type AttrsTy = ast::AttrVec;
@@ -1822,10 +1818,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
18221818
}
18231819
}
18241820

1825-
fn visit_node<Node: InvocationCollectorNode<OutputTy = Node> + DummyAstNode>(
1826-
&mut self,
1827-
node: &mut Node,
1828-
) {
1821+
fn visit_node<Node: InvocationCollectorNode<OutputTy = Node>>(&mut self, node: &mut Node) {
18291822
loop {
18301823
return match self.take_first_attr(node) {
18311824
Some((attr, pos, derives)) => match attr.name_or_empty() {

0 commit comments

Comments
 (0)