Skip to content

Commit 4ecdc68

Browse files
Move MacroKind into Def::Macro
1 parent 306035c commit 4ecdc68

File tree

8 files changed

+28
-15
lines changed

8 files changed

+28
-15
lines changed

src/librustc/hir/def.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use hir::def_id::DefId;
1212
use util::nodemap::NodeMap;
1313
use syntax::ast;
14+
use syntax::ext::base::MacroKind;
1415
use hir;
1516

1617
#[derive(Clone, Copy, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
@@ -53,7 +54,7 @@ pub enum Def {
5354
Label(ast::NodeId),
5455

5556
// Macro namespace
56-
Macro(DefId),
57+
Macro(DefId, MacroKind),
5758

5859
// Both namespaces
5960
Err,
@@ -128,7 +129,7 @@ impl Def {
128129
Def::Variant(id) | Def::VariantCtor(id, ..) | Def::Enum(id) | Def::TyAlias(id) |
129130
Def::AssociatedTy(id) | Def::TyParam(id) | Def::Struct(id) | Def::StructCtor(id, ..) |
130131
Def::Union(id) | Def::Trait(id) | Def::Method(id) | Def::Const(id) |
131-
Def::AssociatedConst(id) | Def::Local(id) | Def::Upvar(id, ..) | Def::Macro(id) => {
132+
Def::AssociatedConst(id) | Def::Local(id) | Def::Upvar(id, ..) | Def::Macro(id, ..) => {
132133
id
133134
}
134135

src/librustc_metadata/decoder.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ use rustc_serialize::{Decodable, Decoder, SpecializedDecoder, opaque};
3939
use syntax::attr;
4040
use syntax::ast;
4141
use syntax::codemap;
42+
use syntax::ext::base::MacroKind;
4243
use syntax_pos::{self, Span, BytePos, Pos, DUMMY_SP};
4344

4445
pub struct DecodeContext<'a, 'tcx: 'a> {
@@ -434,7 +435,7 @@ impl<'tcx> EntryKind<'tcx> {
434435
EntryKind::Variant(_) => Def::Variant(did),
435436
EntryKind::Trait(_) => Def::Trait(did),
436437
EntryKind::Enum(..) => Def::Enum(did),
437-
EntryKind::MacroDef(_) => Def::Macro(did),
438+
EntryKind::MacroDef(_) => Def::Macro(did, MacroKind::Bang),
438439

439440
EntryKind::ForeignMod |
440441
EntryKind::Impl(_) |
@@ -483,9 +484,11 @@ impl<'a, 'tcx> CrateMetadata {
483484
}
484485

485486
pub fn get_def(&self, index: DefIndex) -> Option<Def> {
486-
match self.is_proc_macro(index) {
487-
true => Some(Def::Macro(self.local_def_id(index))),
488-
false => self.entry(index).kind.to_def(self.local_def_id(index)),
487+
if !self.is_proc_macro(index) {
488+
self.entry(index).kind.to_def(self.local_def_id(index))
489+
} else {
490+
let kind = self.proc_macros.as_ref().unwrap()[index.as_usize() - 1].1.kind();
491+
Some(Def::Macro(self.local_def_id(index), kind))
489492
}
490493
}
491494

@@ -688,8 +691,14 @@ impl<'a, 'tcx> CrateMetadata {
688691
{
689692
if let Some(ref proc_macros) = self.proc_macros {
690693
if id == CRATE_DEF_INDEX {
691-
for (id, &(name, _)) in proc_macros.iter().enumerate() {
692-
let def = Def::Macro(DefId { krate: self.cnum, index: DefIndex::new(id + 1) });
694+
for (id, &(name, ref ext)) in proc_macros.iter().enumerate() {
695+
let def = Def::Macro(
696+
DefId {
697+
krate: self.cnum,
698+
index: DefIndex::new(id + 1)
699+
},
700+
ext.kind()
701+
);
693702
callback(def::Export { name: name, def: def });
694703
}
695704
}

src/librustc_resolve/build_reduced_graph.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ impl<'a> Resolver<'a> {
495495

496496
pub fn get_macro(&mut self, def: Def) -> Rc<SyntaxExtension> {
497497
let def_id = match def {
498-
Def::Macro(def_id) => def_id,
498+
Def::Macro(def_id, ..) => def_id,
499499
_ => panic!("Expected Def::Macro(..)"),
500500
};
501501
if let Some(ext) = self.macro_map.get(&def_id) {

src/librustc_resolve/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2329,7 +2329,9 @@ impl<'a> Resolver<'a> {
23292329
if primary_ns != MacroNS && path.len() == 1 &&
23302330
self.macro_names.contains(&path[0].name) {
23312331
// Return some dummy definition, it's enough for error reporting.
2332-
return Some(PathResolution::new(Def::Macro(DefId::local(CRATE_DEF_INDEX))));
2332+
return Some(
2333+
PathResolution::new(Def::Macro(DefId::local(CRATE_DEF_INDEX), MacroKind::Bang))
2334+
);
23332335
}
23342336
fin_res
23352337
}

src/librustc_resolve/macros.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,10 @@ impl<'a> base::Resolver for Resolver<'a> {
159159
krate: BUILTIN_MACROS_CRATE,
160160
index: DefIndex::new(self.macro_map.len()),
161161
};
162+
let kind = ext.kind();
162163
self.macro_map.insert(def_id, ext);
163164
let binding = self.arenas.alloc_name_binding(NameBinding {
164-
kind: NameBindingKind::Def(Def::Macro(def_id)),
165+
kind: NameBindingKind::Def(Def::Macro(def_id, kind)),
165166
span: DUMMY_SP,
166167
vis: ty::Visibility::Invisible,
167168
expansion: Mark::root(),
@@ -561,7 +562,7 @@ impl<'a> Resolver<'a> {
561562
});
562563
self.macro_exports.push(Export {
563564
name: def.ident.name,
564-
def: Def::Macro(self.definitions.local_def_id(def.id)),
565+
def: Def::Macro(self.definitions.local_def_id(def.id), MacroKind::Bang),
565566
});
566567
self.exported_macros.push(def);
567568
}

src/librustc_save_analysis/dump_visitor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
336336
Def::AssociatedTy(..) |
337337
Def::AssociatedConst(..) |
338338
Def::PrimTy(_) |
339-
Def::Macro(_) |
339+
Def::Macro(..) |
340340
Def::Err => {
341341
span_bug!(span,
342342
"process_def_kind for unexpected item: {:?}",

src/librustdoc/visit_ast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
199199
self.inside_public_path = orig_inside_public_path;
200200
if let Some(exports) = self.cx.export_map.get(&id) {
201201
for export in exports {
202-
if let Def::Macro(def_id) = export.def {
202+
if let Def::Macro(def_id, ..) = export.def {
203203
if def_id.krate == LOCAL_CRATE {
204204
continue // These are `krate.exported_macros`, handled in `self.visit()`.
205205
}

src/libsyntax/ext/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ pub type BuiltinDeriveFn =
475475
for<'cx> fn(&'cx mut ExtCtxt, Span, &MetaItem, &Annotatable, &mut FnMut(Annotatable));
476476

477477
/// Represents different kinds of macro invocations that can be resolved.
478-
#[derive(Clone, Copy, PartialEq, Eq)]
478+
#[derive(Clone, Copy, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
479479
pub enum MacroKind {
480480
/// A bang macro - foo!()
481481
Bang,

0 commit comments

Comments
 (0)