Skip to content

Commit ce9ff20

Browse files
committed
Decouple DummyAstNode and DummyResult.
They are two different ways of creating dummy results, with two different purposes. Their implementations are separate except for crates, where `DummyResult` depends on `DummyAstNode`. This commit removes that dependency, so they are now fully separate. It also expands the comment on `DummyAstNode`.
1 parent 1a1876c commit ce9ff20

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

compiler/rustc_ast/src/mut_visit.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1603,7 +1603,9 @@ pub fn noop_visit_capture_by<T: MutVisitor>(capture_by: &mut CaptureBy, vis: &mu
16031603
}
16041604
}
16051605

1606-
/// Some value for the AST node that is valid but possibly meaningless.
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.
16071609
pub trait DummyAstNode {
16081610
fn dummy() -> Self;
16091611
}

compiler/rustc_expand/src/base.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use crate::expand::{self, AstFragment, Invocation};
44
use crate::module::DirOwnership;
55

66
use rustc_ast::attr::MarkedAttrs;
7-
use rustc_ast::mut_visit::DummyAstNode;
87
use rustc_ast::ptr::P;
98
use rustc_ast::token::{self, Nonterminal};
109
use rustc_ast::tokenstream::TokenStream;
@@ -582,6 +581,17 @@ impl DummyResult {
582581
tokens: None,
583582
})
584583
}
584+
585+
/// A plain dummy crate.
586+
pub fn raw_crate() -> ast::Crate {
587+
ast::Crate {
588+
attrs: Default::default(),
589+
items: Default::default(),
590+
spans: Default::default(),
591+
id: ast::DUMMY_NODE_ID,
592+
is_placeholder: Default::default(),
593+
}
594+
}
585595
}
586596

587597
impl MacResult for DummyResult {
@@ -650,7 +660,7 @@ impl MacResult for DummyResult {
650660
}
651661

652662
fn make_crate(self: Box<DummyResult>) -> Option<ast::Crate> {
653-
Some(DummyAstNode::dummy())
663+
Some(DummyResult::raw_crate())
654664
}
655665
}
656666

0 commit comments

Comments
 (0)