diff --git a/src/librustc_resolve/build_reduced_graph.rs b/src/librustc_resolve/build_reduced_graph.rs index f6d632461175..a1d866fc48be 100644 --- a/src/librustc_resolve/build_reduced_graph.rs +++ b/src/librustc_resolve/build_reduced_graph.rs @@ -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(..) | diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 90a913f32d59..3a6bc678dfc3 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -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, diff --git a/src/librustc_resolve/resolve_imports.rs b/src/librustc_resolve/resolve_imports.rs index 4694f5218841..07f6a0f95499 100644 --- a/src/librustc_resolve/resolve_imports.rs +++ b/src/librustc_resolve/resolve_imports.rs @@ -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,