Skip to content

Commit

Permalink
Add an ExpnKind for AST passes
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewjasper committed Sep 5, 2019
1 parent 5ade61a commit 0133941
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/librustc/ich/impls_syntax.rs
Expand Up @@ -411,9 +411,17 @@ impl_stable_hash_for!(struct ::syntax_pos::hygiene::ExpnData {
impl_stable_hash_for!(enum ::syntax_pos::hygiene::ExpnKind {
Root,
Macro(kind, descr),
AstPass(kind),
Desugaring(kind)
});

impl_stable_hash_for!(enum ::syntax_pos::hygiene::AstPass {
StdImports,
TestHarness,
ProcMacroHarness,
PluginMacroDefs,
});

impl_stable_hash_for!(enum ::syntax_pos::hygiene::DesugaringKind {
CondTemporary,
Async,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/lint/mod.rs
Expand Up @@ -888,7 +888,7 @@ pub fn in_external_macro(sess: &Session, span: Span) -> bool {
let expn_data = span.ctxt().outer_expn_data();
match expn_data.kind {
ExpnKind::Root | ExpnKind::Desugaring(DesugaringKind::ForLoop) => false,
ExpnKind::Desugaring(_) => true, // well, it's "external"
ExpnKind::AstPass(_) | ExpnKind::Desugaring(_) => true, // well, it's "external"
ExpnKind::Macro(MacroKind::Bang, _) => {
if expn_data.def_site.is_dummy() {
// dummy span for the def_site means it's an external macro
Expand Down
24 changes: 23 additions & 1 deletion src/libsyntax_pos/hygiene.rs
Expand Up @@ -639,8 +639,9 @@ pub enum ExpnKind {
/// No expansion, aka root expansion. Only `ExpnId::root()` has this kind.
Root,
/// Expansion produced by a macro.
/// FIXME: Some code injected by the compiler before HIR lowering also gets this kind.
Macro(MacroKind, Symbol),
/// Transform done by the compiler on the AST.
AstPass(AstPass),
/// Desugaring done by the compiler during HIR lowering.
Desugaring(DesugaringKind)
}
Expand All @@ -650,6 +651,7 @@ impl ExpnKind {
match *self {
ExpnKind::Root => kw::PathRoot,
ExpnKind::Macro(_, descr) => descr,
ExpnKind::AstPass(kind) => Symbol::intern(kind.descr()),
ExpnKind::Desugaring(kind) => Symbol::intern(kind.descr()),
}
}
Expand Down Expand Up @@ -683,6 +685,26 @@ impl MacroKind {
}
}

/// The kind of AST transform.
#[derive(Clone, Copy, PartialEq, Debug, RustcEncodable, RustcDecodable)]
pub enum AstPass {
StdImports,
TestHarness,
ProcMacroHarness,
PluginMacroDefs,
}

impl AstPass {
fn descr(self) -> &'static str {
match self {
AstPass::StdImports => "standard library imports",
AstPass::TestHarness => "test harness",
AstPass::ProcMacroHarness => "proc macro harness",
AstPass::PluginMacroDefs => "plugin macro definitions",
}
}
}

/// The kind of compiler desugaring.
#[derive(Clone, Copy, PartialEq, Debug, RustcEncodable, RustcDecodable)]
pub enum DesugaringKind {
Expand Down
1 change: 1 addition & 0 deletions src/libsyntax_pos/lib.rs
Expand Up @@ -442,6 +442,7 @@ impl Span {
let (pre, post) = match expn_data.kind {
ExpnKind::Root => break,
ExpnKind::Desugaring(..) => ("desugaring of ", ""),
ExpnKind::AstPass(..) => ("", ""),
ExpnKind::Macro(macro_kind, _) => match macro_kind {
MacroKind::Bang => ("", "!"),
MacroKind::Attr => ("#[", "]"),
Expand Down

0 comments on commit 0133941

Please sign in to comment.