Minor cleanup.
This commit is contained in:
parent
5a0248068c
commit
29791ada1d
@ -501,11 +501,9 @@ impl<'b> Resolver<'b> {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn get_macro(&mut self, binding: &'b NameBinding<'b>) -> Rc<SyntaxExtension> {
|
||||
let def_id = match binding.kind {
|
||||
NameBindingKind::Def(Def::Macro(def_id)) => def_id,
|
||||
NameBindingKind::Import { binding, .. } => return self.get_macro(binding),
|
||||
NameBindingKind::Ambiguity { b1, .. } => return self.get_macro(b1),
|
||||
pub fn get_macro(&mut self, def: Def) -> Rc<SyntaxExtension> {
|
||||
let def_id = match def {
|
||||
Def::Macro(def_id) => def_id,
|
||||
_ => panic!("Expected Def::Macro(..)"),
|
||||
};
|
||||
if let Some(ext) = self.macro_map.get(&def_id) {
|
||||
|
@ -925,6 +925,14 @@ impl<'a> NameBinding<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
fn get_macro(&self, resolver: &mut Resolver<'a>) -> Rc<SyntaxExtension> {
|
||||
match self.kind {
|
||||
NameBindingKind::Import { binding, .. } => binding.get_macro(resolver),
|
||||
NameBindingKind::Ambiguity { b1, .. } => b1.get_macro(resolver),
|
||||
_ => resolver.get_macro(self.def()),
|
||||
}
|
||||
}
|
||||
|
||||
// We sometimes need to treat variants as `pub` for backwards compatibility
|
||||
fn pseudo_vis(&self) -> ty::Visibility {
|
||||
if self.is_variant() { ty::Visibility::Public } else { self.vis }
|
||||
|
@ -193,7 +193,7 @@ 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() {
|
||||
match self.builtin_macros.get(&attrs[i].name()).cloned() {
|
||||
Some(binding) => match *self.get_macro(binding) {
|
||||
Some(binding) => match *binding.get_macro(self) {
|
||||
MultiModifier(..) | MultiDecorator(..) | SyntaxExtension::AttrProcMacro(..) => {
|
||||
return Some(attrs.remove(i))
|
||||
}
|
||||
@ -215,11 +215,11 @@ impl<'a> base::Resolver for Resolver<'a> {
|
||||
|
||||
let invocation = self.invocations[&scope];
|
||||
self.current_module = invocation.module.get();
|
||||
let result = match self.resolve_legacy_scope(&invocation.legacy_scope, name, false) {
|
||||
Some(MacroBinding::Legacy(binding)) => Ok(binding.ext.clone()),
|
||||
Some(MacroBinding::Modern(binding)) => Ok(self.get_macro(binding)),
|
||||
let ext = match self.resolve_legacy_scope(&invocation.legacy_scope, name, false) {
|
||||
Some(MacroBinding::Legacy(binding)) => binding.ext.clone(),
|
||||
Some(MacroBinding::Modern(binding)) => binding.get_macro(self),
|
||||
None => match self.resolve_in_item_lexical_scope(name, MacroNS, None) {
|
||||
Some(binding) => Ok(self.get_macro(binding)),
|
||||
Some(binding) => binding.get_macro(self),
|
||||
None => return Err(if force {
|
||||
let msg = format!("macro undefined: '{}!'", name);
|
||||
let mut err = self.session.struct_span_err(path.span, &msg);
|
||||
@ -236,7 +236,7 @@ impl<'a> base::Resolver for Resolver<'a> {
|
||||
self.current_module.legacy_macro_resolutions.borrow_mut()
|
||||
.push((scope, name, path.span));
|
||||
}
|
||||
result
|
||||
Ok(ext)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user