Skip to content

Commit

Permalink
Auto merge of rust-lang#37292 - jseyfried:import_macros_in_resolve, r…
Browse files Browse the repository at this point in the history
…=nrc

Process `#[macro_use]` imports in `resolve` and clean up macro loading

Groundwork macro modularization (cc rust-lang#35896).
r? @nrc
  • Loading branch information
bors authored Oct 25, 2016
2 parents 7a20864 + 5e8951d commit affc3b7
Show file tree
Hide file tree
Showing 15 changed files with 490 additions and 642 deletions.
2 changes: 0 additions & 2 deletions src/librustc/hir/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -716,8 +716,6 @@ impl<'a> LoweringContext<'a> {
id: m.id,
span: m.span,
imported_from: m.imported_from.map(|x| x.name),
export: m.export,
use_locally: m.use_locally,
allow_internal_unstable: m.allow_internal_unstable,
body: m.body.clone().into(),
}
Expand Down
2 changes: 0 additions & 2 deletions src/librustc/hir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -458,8 +458,6 @@ pub struct MacroDef {
pub id: NodeId,
pub span: Span,
pub imported_from: Option<Name>,
pub export: bool,
pub use_locally: bool,
pub allow_internal_unstable: bool,
pub body: HirVec<TokenTree>,
}
Expand Down
22 changes: 13 additions & 9 deletions src/librustc/middle/cstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ use util::nodemap::{NodeSet, DefIdMap};
use std::path::PathBuf;
use syntax::ast;
use syntax::attr;
use syntax::ext::base::MultiItemModifier;
use syntax::ext::base::SyntaxExtension;
use syntax::ptr::P;
use syntax::parse::token::InternedString;
use syntax_pos::Span;
Expand Down Expand Up @@ -417,18 +417,22 @@ impl<'tcx> CrateStore<'tcx> for DummyCrateStore {
fn metadata_encoding_version(&self) -> &[u8] { bug!("metadata_encoding_version") }
}

pub struct LoadedMacro {
pub import_site: Span,
pub kind: LoadedMacroKind,
pub enum LoadedMacros {
MacroRules(Vec<ast::MacroDef>),
ProcMacros(Vec<(ast::Name, SyntaxExtension)>),
}

pub enum LoadedMacroKind {
Def(ast::MacroDef),
CustomDerive(String, Box<MultiItemModifier>),
impl LoadedMacros {
pub fn is_proc_macros(&self) -> bool {
match *self {
LoadedMacros::ProcMacros(_) => true,
_ => false,
}
}
}

pub trait CrateLoader {
fn load_macros(&mut self, extern_crate: &ast::Item, allows_macros: bool) -> Vec<LoadedMacro>;
fn process_item(&mut self, item: &ast::Item, defs: &Definitions);
fn process_item(&mut self, item: &ast::Item, defs: &Definitions, load_macros: bool)
-> Option<LoadedMacros>;
fn postprocess(&mut self, krate: &ast::Crate);
}
12 changes: 5 additions & 7 deletions src/librustc_incremental/calculate_svh/svh_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -675,13 +675,11 @@ impl<'a, 'hash, 'tcx> visit::Visitor<'tcx> for StrictVersionHashVisitor<'a, 'has

fn visit_macro_def(&mut self, macro_def: &'tcx MacroDef) {
debug!("visit_macro_def: st={:?}", self.st);
if macro_def.export {
SawMacroDef.hash(self.st);
hash_attrs!(self, &macro_def.attrs);
visit::walk_macro_def(self, macro_def)
// FIXME(mw): We should hash the body of the macro too but we don't
// have a stable way of doing so yet.
}
SawMacroDef.hash(self.st);
hash_attrs!(self, &macro_def.attrs);
visit::walk_macro_def(self, macro_def)
// FIXME(mw): We should hash the body of the macro too but we don't
// have a stable way of doing so yet.
}
}

Expand Down
Loading

0 comments on commit affc3b7

Please sign in to comment.