diff options
| author | Jeffrey Seyfried <jeffrey.seyfried@gmail.com> | 2016-04-26 08:29:13 +0000 |
|---|---|---|
| committer | Jeffrey Seyfried <jeffrey.seyfried@gmail.com> | 2016-04-27 01:13:22 +0000 |
| commit | 82e0dd5ac1166426f4b1b91cc184ae3797842467 (patch) | |
| tree | 98df12bb16d9bc8a7aaaa28ea8a10ebc2e3eec93 | |
| parent | 2ccaeed50efc2d55ea05ad4c1178b6ce38bf9aca (diff) | |
| download | rust-82e0dd5ac1166426f4b1b91cc184ae3797842467.tar.gz rust-82e0dd5ac1166426f4b1b91cc184ae3797842467.zip | |
Refactor away `is_static_method`
| -rw-r--r-- | src/librustc_resolve/build_reduced_graph.rs | 10 | ||||
| -rw-r--r-- | src/librustc_resolve/lib.rs | 25 |
2 files changed, 10 insertions, 25 deletions
diff --git a/src/librustc_resolve/build_reduced_graph.rs b/src/librustc_resolve/build_reduced_graph.rs index 6a8779d79db..4dc19434c80 100644 --- a/src/librustc_resolve/build_reduced_graph.rs +++ b/src/librustc_resolve/build_reduced_graph.rs @@ -334,15 +334,19 @@ impl<'b, 'tcx:'b> Resolver<'b, 'tcx> { // Add the names of all the items to the trait info. for item in items { let item_def_id = self.ast_map.local_def_id(item.id); + let mut is_static_method = false; let (def, ns) = match item.node { hir::ConstTraitItem(..) => (Def::AssociatedConst(item_def_id), ValueNS), - hir::MethodTraitItem(..) => (Def::Method(item_def_id), ValueNS), + hir::MethodTraitItem(ref sig, _) => { + is_static_method = sig.explicit_self.node == hir::SelfStatic; + (Def::Method(item_def_id), ValueNS) + } hir::TypeTraitItem(..) => (Def::AssociatedTy(def_id, item_def_id), TypeNS), }; self.define(module_parent, item.name, ns, (def, item.span, vis)); - self.trait_item_map.insert((item.name, def_id), item_def_id); + self.trait_item_map.insert((item.name, def_id), is_static_method); } } } @@ -464,7 +468,7 @@ impl<'b, 'tcx:'b> Resolver<'b, 'tcx> { '{}'", trait_item_name); - self.trait_item_map.insert((trait_item_name, def_id), trait_item_def.def_id()); + self.trait_item_map.insert((trait_item_name, def_id), false); } let parent_link = ModuleParentLink(parent, name); diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index e9bbd686a3f..16e97e56755 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -1016,7 +1016,7 @@ pub struct Resolver<'a, 'tcx: 'a> { graph_root: Module<'a>, - trait_item_map: FnvHashMap<(Name, DefId), DefId>, + trait_item_map: FnvHashMap<(Name, DefId), bool /* is static method? */>, structs: FnvHashMap<DefId, Vec<Name>>, @@ -2823,25 +2823,6 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { } } - fn is_static_method(this: &Resolver, did: DefId) -> bool { - if let Some(node_id) = this.ast_map.as_local_node_id(did) { - let sig = match this.ast_map.get(node_id) { - hir_map::NodeTraitItem(trait_item) => match trait_item.node { - hir::MethodTraitItem(ref sig, _) => sig, - _ => return false, - }, - hir_map::NodeImplItem(impl_item) => match impl_item.node { - hir::ImplItemKind::Method(ref sig, _) => sig, - _ => return false, - }, - _ => return false, - }; - sig.explicit_self.node == hir::SelfStatic - } else { - this.session.cstore.is_static_method(did) - } - } - if let Some(node_id) = self.current_self_type.as_ref().and_then(extract_node_id) { // Look for a field with the same name in the current self_type. match self.def_map.borrow().get(&node_id).map(|d| d.full_def()) { @@ -2862,8 +2843,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { // Look for a method in the current trait. if let Some((trait_did, ref trait_ref)) = self.current_trait_ref { - if let Some(&did) = self.trait_item_map.get(&(name, trait_did)) { - if is_static_method(self, did) { + if let Some(&is_static_method) = self.trait_item_map.get(&(name, trait_did)) { + if is_static_method { return TraitMethod(path_names_to_string(&trait_ref.path, 0)); } else { return TraitItem; |
