Skip to content

Commit 82e0dd5

Browse files
committed
Refactor away is_static_method
1 parent 2ccaeed commit 82e0dd5

File tree

2 files changed

+10
-25
lines changed

2 files changed

+10
-25
lines changed

src/librustc_resolve/build_reduced_graph.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -334,15 +334,19 @@ impl<'b, 'tcx:'b> Resolver<'b, 'tcx> {
334334
// Add the names of all the items to the trait info.
335335
for item in items {
336336
let item_def_id = self.ast_map.local_def_id(item.id);
337+
let mut is_static_method = false;
337338
let (def, ns) = match item.node {
338339
hir::ConstTraitItem(..) => (Def::AssociatedConst(item_def_id), ValueNS),
339-
hir::MethodTraitItem(..) => (Def::Method(item_def_id), ValueNS),
340+
hir::MethodTraitItem(ref sig, _) => {
341+
is_static_method = sig.explicit_self.node == hir::SelfStatic;
342+
(Def::Method(item_def_id), ValueNS)
343+
}
340344
hir::TypeTraitItem(..) => (Def::AssociatedTy(def_id, item_def_id), TypeNS),
341345
};
342346

343347
self.define(module_parent, item.name, ns, (def, item.span, vis));
344348

345-
self.trait_item_map.insert((item.name, def_id), item_def_id);
349+
self.trait_item_map.insert((item.name, def_id), is_static_method);
346350
}
347351
}
348352
}
@@ -464,7 +468,7 @@ impl<'b, 'tcx:'b> Resolver<'b, 'tcx> {
464468
'{}'",
465469
trait_item_name);
466470

467-
self.trait_item_map.insert((trait_item_name, def_id), trait_item_def.def_id());
471+
self.trait_item_map.insert((trait_item_name, def_id), false);
468472
}
469473

470474
let parent_link = ModuleParentLink(parent, name);

src/librustc_resolve/lib.rs

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,7 +1016,7 @@ pub struct Resolver<'a, 'tcx: 'a> {
10161016

10171017
graph_root: Module<'a>,
10181018

1019-
trait_item_map: FnvHashMap<(Name, DefId), DefId>,
1019+
trait_item_map: FnvHashMap<(Name, DefId), bool /* is static method? */>,
10201020

10211021
structs: FnvHashMap<DefId, Vec<Name>>,
10221022

@@ -2823,25 +2823,6 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
28232823
}
28242824
}
28252825

2826-
fn is_static_method(this: &Resolver, did: DefId) -> bool {
2827-
if let Some(node_id) = this.ast_map.as_local_node_id(did) {
2828-
let sig = match this.ast_map.get(node_id) {
2829-
hir_map::NodeTraitItem(trait_item) => match trait_item.node {
2830-
hir::MethodTraitItem(ref sig, _) => sig,
2831-
_ => return false,
2832-
},
2833-
hir_map::NodeImplItem(impl_item) => match impl_item.node {
2834-
hir::ImplItemKind::Method(ref sig, _) => sig,
2835-
_ => return false,
2836-
},
2837-
_ => return false,
2838-
};
2839-
sig.explicit_self.node == hir::SelfStatic
2840-
} else {
2841-
this.session.cstore.is_static_method(did)
2842-
}
2843-
}
2844-
28452826
if let Some(node_id) = self.current_self_type.as_ref().and_then(extract_node_id) {
28462827
// Look for a field with the same name in the current self_type.
28472828
match self.def_map.borrow().get(&node_id).map(|d| d.full_def()) {
@@ -2862,8 +2843,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
28622843

28632844
// Look for a method in the current trait.
28642845
if let Some((trait_did, ref trait_ref)) = self.current_trait_ref {
2865-
if let Some(&did) = self.trait_item_map.get(&(name, trait_did)) {
2866-
if is_static_method(self, did) {
2846+
if let Some(&is_static_method) = self.trait_item_map.get(&(name, trait_did)) {
2847+
if is_static_method {
28672848
return TraitMethod(path_names_to_string(&trait_ref.path, 0));
28682849
} else {
28692850
return TraitItem;

0 commit comments

Comments
 (0)