Nits and other local improvements in resolve

This commit is contained in:
Jeffrey Seyfried 2016-01-28 03:03:40 +00:00
parent e13a0450d3
commit 1ca9f03ead
3 changed files with 25 additions and 48 deletions

View File

@ -360,21 +360,14 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
// These items live in both the type and value namespaces.
ItemStruct(ref struct_def, _) => {
// Adding to both Type and Value namespaces or just Type?
let ctor_id = if struct_def.is_struct() {
None
} else {
Some(struct_def.id())
};
// Define a name in the type namespace.
let def = Def::Struct(self.ast_map.local_def_id(item.id));
self.define(parent, name, TypeNS, (def, sp, modifiers));
// If this is a newtype or unit-like struct, define a name
// in the value namespace as well
if let Some(cid) = ctor_id {
let def = Def::Struct(self.ast_map.local_def_id(cid));
if !struct_def.is_struct() {
let def = Def::Struct(self.ast_map.local_def_id(struct_def.id()));
self.define(parent, name, ValueNS, (def, sp, modifiers));
}
@ -516,19 +509,9 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
if is_exported {
self.external_exports.insert(def.def_id());
}
let is_struct_ctor = if let Def::Struct(def_id) = def {
self.session.cstore.tuple_struct_definition_if_ctor(def_id).is_some()
} else {
false
};
// Define a module if necessary.
match def {
Def::Mod(_) |
Def::ForeignMod(_) |
Def::Trait(..) |
Def::Enum(..) |
Def::TyAlias(..) if !is_struct_ctor => {
Def::Mod(_) | Def::ForeignMod(_) | Def::Enum(..) | Def::TyAlias(..) => {
debug!("(building reduced graph for external crate) building module {} {}",
final_ident,
is_public);
@ -536,11 +519,6 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
let module = self.new_module(parent_link, Some(def), true, is_public);
self.try_define(new_parent, name, TypeNS, (module, DUMMY_SP));
}
_ => {}
}
match def {
Def::Mod(_) | Def::ForeignMod(_) | Def::Enum(..) | Def::TyAlias(..) => {}
Def::Variant(_, variant_id) => {
debug!("(building reduced graph for external crate) building variant {}",
final_ident);
@ -585,16 +563,18 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
self.external_exports.insert(trait_item_def.def_id());
}
}
let parent_link = ModuleParentLink(new_parent, name);
let module = self.new_module(parent_link, Some(def), true, is_public);
self.try_define(new_parent, name, TypeNS, (module, DUMMY_SP));
}
Def::AssociatedTy(..) => {
debug!("(building reduced graph for external crate) building type {}",
final_ident);
self.try_define(new_parent, name, TypeNS, (def, DUMMY_SP, modifiers));
}
Def::Struct(..) if is_struct_ctor => {
// Do nothing
}
Def::Struct(def_id) => {
Def::Struct(def_id)
if self.session.cstore.tuple_struct_definition_if_ctor(def_id).is_none() => {
debug!("(building reduced graph for external crate) building type and value for \
{}",
final_ident);
@ -608,6 +588,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
let fields = self.session.cstore.struct_field_names(def_id);
self.structs.insert(def_id, fields);
}
Def::Struct(..) => {}
Def::Local(..) |
Def::PrimTy(..) |
Def::TyParam(..) |

View File

@ -3579,27 +3579,23 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
// Look for trait children.
build_reduced_graph::populate_module_if_necessary(self, &search_module);
{
for (_, name_binding) in search_module.children.borrow().iter() {
let def = match name_binding.def() {
Some(def) => def,
None => continue,
};
let trait_def_id = match def {
Def::Trait(trait_def_id) => trait_def_id,
_ => continue,
};
if self.trait_item_map.contains_key(&(name, trait_def_id)) {
add_trait_info(&mut found_traits, trait_def_id, name);
}
for (&(_, ns), name_binding) in search_module.children.borrow().iter() {
if ns != TypeNS { continue }
let trait_def_id = match name_binding.def() {
Some(Def::Trait(trait_def_id)) => trait_def_id,
Some(..) | None => continue,
};
if self.trait_item_map.contains_key(&(name, trait_def_id)) {
add_trait_info(&mut found_traits, trait_def_id, name);
}
}
// Look for imports.
for (&(_, ns), import) in search_module.import_resolutions.borrow().iter() {
let target = match (ns, &import.target) {
(TypeNS, &Some(ref target)) => target.clone(),
_ => continue,
if ns != TypeNS { continue }
let target = match import.target {
Some(ref target) => target,
None => continue,
};
let did = match target.binding.def() {
Some(Def::Trait(trait_def_id)) => trait_def_id,

View File

@ -389,7 +389,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
return (Success((module, name_binding)), false);
}
if let TypeNS = ns {
if ns == TypeNS {
if let Some(extern_crate) = module.external_module_children.borrow().get(&name) {
// track the extern crate as used.
if let Some(DefId{ krate: kid, .. }) = extern_crate.def_id() {
@ -882,7 +882,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
import_span: Span,
(name, ns): (Name, Namespace)) {
// First, check for conflicts between imports and `extern crate`s.
if let TypeNS = ns {
if ns == TypeNS {
if module.external_module_children.borrow().contains_key(&name) {
match import.target {
Some(ref target) if target.shadowable != Shadowable::Always => {
@ -905,7 +905,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
Some(name_binding) => name_binding,
};
if let ValueNS = ns {
if ns == ValueNS {
match import.target {
Some(ref target) if target.shadowable != Shadowable::Always => {
let mut err = struct_span_err!(self.resolver.session,