Skip to content

Commit b5d7da8

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 279c9ba commit b5d7da8

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

compiler/rustc_ast/src/mut_visit.rs

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

1607-
/// Some value for the AST node that is valid but possibly meaningless.
1607+
/// Some value for the AST node that is valid but possibly meaningless. Similar
1608+
/// to `Default` but not intended for wide use. The value will never be used
1609+
/// meaningfully, it exists just to support unwinding in `visit_clobber` in the
1610+
/// case where its closure panics.
16081611
pub trait DummyAstNode {
16091612
fn dummy() -> Self;
16101613
}

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)