Refactor away get_trait_name
This commit is contained in:
parent
82e0dd5ac1
commit
6da115374f
1 changed files with 4 additions and 13 deletions
|
@ -829,7 +829,7 @@ pub struct ModuleS<'a> {
|
||||||
globs: RefCell<Vec<&'a ImportDirective<'a>>>,
|
globs: RefCell<Vec<&'a ImportDirective<'a>>>,
|
||||||
|
|
||||||
// Used to memoize the traits in this module for faster searches through all traits in scope.
|
// Used to memoize the traits in this module for faster searches through all traits in scope.
|
||||||
traits: RefCell<Option<Box<[&'a NameBinding<'a>]>>>,
|
traits: RefCell<Option<Box<[(Name, &'a NameBinding<'a>)]>>>,
|
||||||
|
|
||||||
// Whether this module is populated. If not populated, any attempt to
|
// Whether this module is populated. If not populated, any attempt to
|
||||||
// access the children must be preceded with a
|
// access the children must be preceded with a
|
||||||
|
@ -1234,14 +1234,6 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
self.glob_map.insert(directive.id, new_set);
|
self.glob_map.insert(directive.id, new_set);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_trait_name(&self, did: DefId) -> Name {
|
|
||||||
if let Some(node_id) = self.ast_map.as_local_node_id(did) {
|
|
||||||
self.ast_map.expect_item(node_id).name
|
|
||||||
} else {
|
|
||||||
self.session.cstore.item_name(did)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Resolves the given module path from the given root `module_`.
|
/// Resolves the given module path from the given root `module_`.
|
||||||
fn resolve_module_path_from_root(&mut self,
|
fn resolve_module_path_from_root(&mut self,
|
||||||
module_: Module<'a>,
|
module_: Module<'a>,
|
||||||
|
@ -3146,20 +3138,19 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
let mut traits = module.traits.borrow_mut();
|
let mut traits = module.traits.borrow_mut();
|
||||||
if traits.is_none() {
|
if traits.is_none() {
|
||||||
let mut collected_traits = Vec::new();
|
let mut collected_traits = Vec::new();
|
||||||
module.for_each_child(|_, ns, binding| {
|
module.for_each_child(|name, ns, binding| {
|
||||||
if ns != TypeNS { return }
|
if ns != TypeNS { return }
|
||||||
if let Some(Def::Trait(_)) = binding.def() {
|
if let Some(Def::Trait(_)) = binding.def() {
|
||||||
collected_traits.push(binding);
|
collected_traits.push((name, binding));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
*traits = Some(collected_traits.into_boxed_slice());
|
*traits = Some(collected_traits.into_boxed_slice());
|
||||||
}
|
}
|
||||||
|
|
||||||
for binding in traits.as_ref().unwrap().iter() {
|
for &(trait_name, binding) in traits.as_ref().unwrap().iter() {
|
||||||
let trait_def_id = binding.def().unwrap().def_id();
|
let trait_def_id = binding.def().unwrap().def_id();
|
||||||
if self.trait_item_map.contains_key(&(name, trait_def_id)) {
|
if self.trait_item_map.contains_key(&(name, trait_def_id)) {
|
||||||
add_trait_info(&mut found_traits, trait_def_id, name);
|
add_trait_info(&mut found_traits, trait_def_id, name);
|
||||||
let trait_name = self.get_trait_name(trait_def_id);
|
|
||||||
self.record_use(trait_name, TypeNS, binding);
|
self.record_use(trait_name, TypeNS, binding);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue