Skip to content

Commit affc3b7

Browse files
authored
Auto merge of #37292 - jseyfried:import_macros_in_resolve, r=nrc
Process `#[macro_use]` imports in `resolve` and clean up macro loading Groundwork macro modularization (cc #35896). r? @nrc
2 parents 7a20864 + 5e8951d commit affc3b7

File tree

15 files changed

+490
-642
lines changed

15 files changed

+490
-642
lines changed

src/librustc/hir/lowering.rs

-2
Original file line numberDiff line numberDiff line change
@@ -716,8 +716,6 @@ impl<'a> LoweringContext<'a> {
716716
id: m.id,
717717
span: m.span,
718718
imported_from: m.imported_from.map(|x| x.name),
719-
export: m.export,
720-
use_locally: m.use_locally,
721719
allow_internal_unstable: m.allow_internal_unstable,
722720
body: m.body.clone().into(),
723721
}

src/librustc/hir/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -458,8 +458,6 @@ pub struct MacroDef {
458458
pub id: NodeId,
459459
pub span: Span,
460460
pub imported_from: Option<Name>,
461-
pub export: bool,
462-
pub use_locally: bool,
463461
pub allow_internal_unstable: bool,
464462
pub body: HirVec<TokenTree>,
465463
}

src/librustc/middle/cstore.rs

+13-9
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use util::nodemap::{NodeSet, DefIdMap};
3737
use std::path::PathBuf;
3838
use syntax::ast;
3939
use syntax::attr;
40-
use syntax::ext::base::MultiItemModifier;
40+
use syntax::ext::base::SyntaxExtension;
4141
use syntax::ptr::P;
4242
use syntax::parse::token::InternedString;
4343
use syntax_pos::Span;
@@ -417,18 +417,22 @@ impl<'tcx> CrateStore<'tcx> for DummyCrateStore {
417417
fn metadata_encoding_version(&self) -> &[u8] { bug!("metadata_encoding_version") }
418418
}
419419

420-
pub struct LoadedMacro {
421-
pub import_site: Span,
422-
pub kind: LoadedMacroKind,
420+
pub enum LoadedMacros {
421+
MacroRules(Vec<ast::MacroDef>),
422+
ProcMacros(Vec<(ast::Name, SyntaxExtension)>),
423423
}
424424

425-
pub enum LoadedMacroKind {
426-
Def(ast::MacroDef),
427-
CustomDerive(String, Box<MultiItemModifier>),
425+
impl LoadedMacros {
426+
pub fn is_proc_macros(&self) -> bool {
427+
match *self {
428+
LoadedMacros::ProcMacros(_) => true,
429+
_ => false,
430+
}
431+
}
428432
}
429433

430434
pub trait CrateLoader {
431-
fn load_macros(&mut self, extern_crate: &ast::Item, allows_macros: bool) -> Vec<LoadedMacro>;
432-
fn process_item(&mut self, item: &ast::Item, defs: &Definitions);
435+
fn process_item(&mut self, item: &ast::Item, defs: &Definitions, load_macros: bool)
436+
-> Option<LoadedMacros>;
433437
fn postprocess(&mut self, krate: &ast::Crate);
434438
}

src/librustc_incremental/calculate_svh/svh_visitor.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -675,13 +675,11 @@ impl<'a, 'hash, 'tcx> visit::Visitor<'tcx> for StrictVersionHashVisitor<'a, 'has
675675

676676
fn visit_macro_def(&mut self, macro_def: &'tcx MacroDef) {
677677
debug!("visit_macro_def: st={:?}", self.st);
678-
if macro_def.export {
679-
SawMacroDef.hash(self.st);
680-
hash_attrs!(self, &macro_def.attrs);
681-
visit::walk_macro_def(self, macro_def)
682-
// FIXME(mw): We should hash the body of the macro too but we don't
683-
// have a stable way of doing so yet.
684-
}
678+
SawMacroDef.hash(self.st);
679+
hash_attrs!(self, &macro_def.attrs);
680+
visit::walk_macro_def(self, macro_def)
681+
// FIXME(mw): We should hash the body of the macro too but we don't
682+
// have a stable way of doing so yet.
685683
}
686684
}
687685

0 commit comments

Comments
 (0)