Refactor Resolver::builtin_macros
to use NameBinding
s instead of DefId
s.
This commit is contained in:
parent
641274f907
commit
83aac43f52
3 changed files with 20 additions and 12 deletions
|
@ -518,10 +518,12 @@ impl<'b> Resolver<'b> {
|
|||
module.populated.set(true)
|
||||
}
|
||||
|
||||
fn legacy_import_macro(&mut self, name: Name, def: Def, span: Span, allow_shadowing: bool) {
|
||||
self.used_crates.insert(def.def_id().krate);
|
||||
fn legacy_import_macro(
|
||||
&mut self, name: Name, binding: &'b NameBinding<'b>, span: Span, allow_shadowing: bool,
|
||||
) {
|
||||
self.used_crates.insert(binding.def().def_id().krate);
|
||||
self.macro_names.insert(name);
|
||||
if self.builtin_macros.insert(name, def.def_id()).is_some() && !allow_shadowing {
|
||||
if self.builtin_macros.insert(name, binding).is_some() && !allow_shadowing {
|
||||
let msg = format!("`{}` is already in scope", name);
|
||||
let note =
|
||||
"macro-expanded `#[macro_use]`s may not shadow existing macros (see RFC 1560)";
|
||||
|
@ -548,13 +550,13 @@ impl<'b> Resolver<'b> {
|
|||
|
||||
if let Some(span) = legacy_imports.import_all {
|
||||
module.for_each_child(|name, ns, binding| if ns == MacroNS {
|
||||
self.legacy_import_macro(name, binding.def(), span, allow_shadowing);
|
||||
self.legacy_import_macro(name, binding, span, allow_shadowing);
|
||||
});
|
||||
} else {
|
||||
for (name, span) in legacy_imports.imports {
|
||||
let result = self.resolve_name_in_module(module, name, MacroNS, false, None);
|
||||
if let Success(binding) = result {
|
||||
self.legacy_import_macro(name, binding.def(), span, allow_shadowing);
|
||||
self.legacy_import_macro(name, binding, span, allow_shadowing);
|
||||
} else {
|
||||
span_err!(self.session, span, E0469, "imported macro not found");
|
||||
}
|
||||
|
|
|
@ -1115,7 +1115,7 @@ pub struct Resolver<'a> {
|
|||
pub exported_macros: Vec<ast::MacroDef>,
|
||||
crate_loader: &'a mut CrateLoader,
|
||||
macro_names: FxHashSet<Name>,
|
||||
builtin_macros: FxHashMap<Name, DefId>,
|
||||
builtin_macros: FxHashMap<Name, &'a NameBinding<'a>>,
|
||||
lexical_macro_resolutions: Vec<(Name, LegacyScope<'a>)>,
|
||||
macro_map: FxHashMap<DefId, Rc<SyntaxExtension>>,
|
||||
macro_exports: Vec<Export>,
|
||||
|
|
|
@ -8,12 +8,13 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use {Module, ModuleKind, Resolver};
|
||||
use {Module, ModuleKind, NameBinding, NameBindingKind, Resolver};
|
||||
use build_reduced_graph::BuildReducedGraphVisitor;
|
||||
use resolve_imports::ImportResolver;
|
||||
use rustc::hir::def_id::{DefId, BUILTIN_MACROS_CRATE, CRATE_DEF_INDEX, DefIndex};
|
||||
use rustc::hir::def::{Def, Export};
|
||||
use rustc::hir::map::{self, DefCollector};
|
||||
use rustc::ty;
|
||||
use std::cell::Cell;
|
||||
use std::rc::Rc;
|
||||
use syntax::ast;
|
||||
|
@ -28,7 +29,7 @@ use syntax::parse::token::intern;
|
|||
use syntax::ptr::P;
|
||||
use syntax::util::lev_distance::find_best_match_for_name;
|
||||
use syntax::visit::Visitor;
|
||||
use syntax_pos::Span;
|
||||
use syntax_pos::{Span, DUMMY_SP};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct InvocationData<'a> {
|
||||
|
@ -179,7 +180,12 @@ impl<'a> base::Resolver for Resolver<'a> {
|
|||
index: DefIndex::new(self.macro_map.len()),
|
||||
};
|
||||
self.macro_map.insert(def_id, ext);
|
||||
self.builtin_macros.insert(ident.name, def_id);
|
||||
let binding = self.arenas.alloc_name_binding(NameBinding {
|
||||
kind: NameBindingKind::Def(Def::Macro(def_id)),
|
||||
span: DUMMY_SP,
|
||||
vis: ty::Visibility::PrivateExternal,
|
||||
});
|
||||
self.builtin_macros.insert(ident.name, binding);
|
||||
}
|
||||
|
||||
fn add_expansions_at_stmt(&mut self, id: ast::NodeId, macros: Vec<Mark>) {
|
||||
|
@ -193,8 +199,8 @@ impl<'a> base::Resolver for Resolver<'a> {
|
|||
fn find_attr_invoc(&mut self, attrs: &mut Vec<ast::Attribute>) -> Option<ast::Attribute> {
|
||||
for i in 0..attrs.len() {
|
||||
let name = intern(&attrs[i].name());
|
||||
match self.builtin_macros.get(&name) {
|
||||
Some(&def_id) => match *self.get_macro(Def::Macro(def_id)) {
|
||||
match self.builtin_macros.get(&name).cloned() {
|
||||
Some(binding) => match *self.get_macro(binding.def()) {
|
||||
MultiModifier(..) | MultiDecorator(..) | SyntaxExtension::AttrProcMacro(..) => {
|
||||
return Some(attrs.remove(i))
|
||||
}
|
||||
|
@ -273,7 +279,7 @@ impl<'a> Resolver<'a> {
|
|||
if let Some(scope) = possible_time_travel {
|
||||
self.lexical_macro_resolutions.push((name, scope));
|
||||
}
|
||||
self.builtin_macros.get(&name).cloned().map(|def_id| self.get_macro(Def::Macro(def_id)))
|
||||
self.builtin_macros.get(&name).cloned().map(|binding| self.get_macro(binding.def()))
|
||||
}
|
||||
|
||||
fn suggest_macro_name(&mut self, name: &str, err: &mut DiagnosticBuilder<'a>) {
|
||||
|
|
Loading…
Add table
Reference in a new issue