Skip to content

Commit 0133941

Browse files
committed
Add an ExpnKind for AST passes
1 parent 5ade61a commit 0133941

File tree

4 files changed

+33
-2
lines changed

4 files changed

+33
-2
lines changed

src/librustc/ich/impls_syntax.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,9 +411,17 @@ impl_stable_hash_for!(struct ::syntax_pos::hygiene::ExpnData {
411411
impl_stable_hash_for!(enum ::syntax_pos::hygiene::ExpnKind {
412412
Root,
413413
Macro(kind, descr),
414+
AstPass(kind),
414415
Desugaring(kind)
415416
});
416417

418+
impl_stable_hash_for!(enum ::syntax_pos::hygiene::AstPass {
419+
StdImports,
420+
TestHarness,
421+
ProcMacroHarness,
422+
PluginMacroDefs,
423+
});
424+
417425
impl_stable_hash_for!(enum ::syntax_pos::hygiene::DesugaringKind {
418426
CondTemporary,
419427
Async,

src/librustc/lint/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -888,7 +888,7 @@ pub fn in_external_macro(sess: &Session, span: Span) -> bool {
888888
let expn_data = span.ctxt().outer_expn_data();
889889
match expn_data.kind {
890890
ExpnKind::Root | ExpnKind::Desugaring(DesugaringKind::ForLoop) => false,
891-
ExpnKind::Desugaring(_) => true, // well, it's "external"
891+
ExpnKind::AstPass(_) | ExpnKind::Desugaring(_) => true, // well, it's "external"
892892
ExpnKind::Macro(MacroKind::Bang, _) => {
893893
if expn_data.def_site.is_dummy() {
894894
// dummy span for the def_site means it's an external macro

src/libsyntax_pos/hygiene.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,8 +639,9 @@ pub enum ExpnKind {
639639
/// No expansion, aka root expansion. Only `ExpnId::root()` has this kind.
640640
Root,
641641
/// Expansion produced by a macro.
642-
/// FIXME: Some code injected by the compiler before HIR lowering also gets this kind.
643642
Macro(MacroKind, Symbol),
643+
/// Transform done by the compiler on the AST.
644+
AstPass(AstPass),
644645
/// Desugaring done by the compiler during HIR lowering.
645646
Desugaring(DesugaringKind)
646647
}
@@ -650,6 +651,7 @@ impl ExpnKind {
650651
match *self {
651652
ExpnKind::Root => kw::PathRoot,
652653
ExpnKind::Macro(_, descr) => descr,
654+
ExpnKind::AstPass(kind) => Symbol::intern(kind.descr()),
653655
ExpnKind::Desugaring(kind) => Symbol::intern(kind.descr()),
654656
}
655657
}
@@ -683,6 +685,26 @@ impl MacroKind {
683685
}
684686
}
685687

688+
/// The kind of AST transform.
689+
#[derive(Clone, Copy, PartialEq, Debug, RustcEncodable, RustcDecodable)]
690+
pub enum AstPass {
691+
StdImports,
692+
TestHarness,
693+
ProcMacroHarness,
694+
PluginMacroDefs,
695+
}
696+
697+
impl AstPass {
698+
fn descr(self) -> &'static str {
699+
match self {
700+
AstPass::StdImports => "standard library imports",
701+
AstPass::TestHarness => "test harness",
702+
AstPass::ProcMacroHarness => "proc macro harness",
703+
AstPass::PluginMacroDefs => "plugin macro definitions",
704+
}
705+
}
706+
}
707+
686708
/// The kind of compiler desugaring.
687709
#[derive(Clone, Copy, PartialEq, Debug, RustcEncodable, RustcDecodable)]
688710
pub enum DesugaringKind {

src/libsyntax_pos/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,7 @@ impl Span {
442442
let (pre, post) = match expn_data.kind {
443443
ExpnKind::Root => break,
444444
ExpnKind::Desugaring(..) => ("desugaring of ", ""),
445+
ExpnKind::AstPass(..) => ("", ""),
445446
ExpnKind::Macro(macro_kind, _) => match macro_kind {
446447
MacroKind::Bang => ("", "!"),
447448
MacroKind::Attr => ("#[", "]"),

0 commit comments

Comments
 (0)