From 29791ada1ddfbb37c5ad90fc8149577f426cc995 Mon Sep 17 00:00:00 2001 From: Jeffrey Seyfried Date: Sun, 27 Nov 2016 10:27:41 +0000 Subject: [PATCH] Minor cleanup. --- src/librustc_resolve/build_reduced_graph.rs | 8 +++----- src/librustc_resolve/lib.rs | 8 ++++++++ src/librustc_resolve/macros.rs | 12 ++++++------ 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/librustc_resolve/build_reduced_graph.rs b/src/librustc_resolve/build_reduced_graph.rs index d90a49213d1..7bcc543023e 100644 --- a/src/librustc_resolve/build_reduced_graph.rs +++ b/src/librustc_resolve/build_reduced_graph.rs @@ -501,11 +501,9 @@ impl<'b> Resolver<'b> { }) } - pub fn get_macro(&mut self, binding: &'b NameBinding<'b>) -> Rc { - 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 { + 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) { diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index e1200149dcc..1c8c77a13d9 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -925,6 +925,14 @@ impl<'a> NameBinding<'a> { } } + fn get_macro(&self, resolver: &mut Resolver<'a>) -> Rc { + 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 } diff --git a/src/librustc_resolve/macros.rs b/src/librustc_resolve/macros.rs index 3b34a60c585..ff91e7dc971 100644 --- a/src/librustc_resolve/macros.rs +++ b/src/librustc_resolve/macros.rs @@ -193,7 +193,7 @@ impl<'a> base::Resolver for Resolver<'a> { fn find_attr_invoc(&mut self, attrs: &mut Vec) -> Option { 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) } }