Skip to content

Commit 1ca9f03

Browse files
committed
Nits and other local improvements in resolve
1 parent e13a045 commit 1ca9f03

File tree

3 files changed

+25
-48
lines changed

3 files changed

+25
-48
lines changed

src/librustc_resolve/build_reduced_graph.rs

+10-29
Original file line numberDiff line numberDiff line change
@@ -360,21 +360,14 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
360360

361361
// These items live in both the type and value namespaces.
362362
ItemStruct(ref struct_def, _) => {
363-
// Adding to both Type and Value namespaces or just Type?
364-
let ctor_id = if struct_def.is_struct() {
365-
None
366-
} else {
367-
Some(struct_def.id())
368-
};
369-
370363
// Define a name in the type namespace.
371364
let def = Def::Struct(self.ast_map.local_def_id(item.id));
372365
self.define(parent, name, TypeNS, (def, sp, modifiers));
373366

374367
// If this is a newtype or unit-like struct, define a name
375368
// in the value namespace as well
376-
if let Some(cid) = ctor_id {
377-
let def = Def::Struct(self.ast_map.local_def_id(cid));
369+
if !struct_def.is_struct() {
370+
let def = Def::Struct(self.ast_map.local_def_id(struct_def.id()));
378371
self.define(parent, name, ValueNS, (def, sp, modifiers));
379372
}
380373

@@ -516,31 +509,16 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
516509
if is_exported {
517510
self.external_exports.insert(def.def_id());
518511
}
519-
let is_struct_ctor = if let Def::Struct(def_id) = def {
520-
self.session.cstore.tuple_struct_definition_if_ctor(def_id).is_some()
521-
} else {
522-
false
523-
};
524512

525-
// Define a module if necessary.
526513
match def {
527-
Def::Mod(_) |
528-
Def::ForeignMod(_) |
529-
Def::Trait(..) |
530-
Def::Enum(..) |
531-
Def::TyAlias(..) if !is_struct_ctor => {
514+
Def::Mod(_) | Def::ForeignMod(_) | Def::Enum(..) | Def::TyAlias(..) => {
532515
debug!("(building reduced graph for external crate) building module {} {}",
533516
final_ident,
534517
is_public);
535518
let parent_link = ModuleParentLink(new_parent, name);
536519
let module = self.new_module(parent_link, Some(def), true, is_public);
537520
self.try_define(new_parent, name, TypeNS, (module, DUMMY_SP));
538521
}
539-
_ => {}
540-
}
541-
542-
match def {
543-
Def::Mod(_) | Def::ForeignMod(_) | Def::Enum(..) | Def::TyAlias(..) => {}
544522
Def::Variant(_, variant_id) => {
545523
debug!("(building reduced graph for external crate) building variant {}",
546524
final_ident);
@@ -585,16 +563,18 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
585563
self.external_exports.insert(trait_item_def.def_id());
586564
}
587565
}
566+
567+
let parent_link = ModuleParentLink(new_parent, name);
568+
let module = self.new_module(parent_link, Some(def), true, is_public);
569+
self.try_define(new_parent, name, TypeNS, (module, DUMMY_SP));
588570
}
589571
Def::AssociatedTy(..) => {
590572
debug!("(building reduced graph for external crate) building type {}",
591573
final_ident);
592574
self.try_define(new_parent, name, TypeNS, (def, DUMMY_SP, modifiers));
593575
}
594-
Def::Struct(..) if is_struct_ctor => {
595-
// Do nothing
596-
}
597-
Def::Struct(def_id) => {
576+
Def::Struct(def_id)
577+
if self.session.cstore.tuple_struct_definition_if_ctor(def_id).is_none() => {
598578
debug!("(building reduced graph for external crate) building type and value for \
599579
{}",
600580
final_ident);
@@ -608,6 +588,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
608588
let fields = self.session.cstore.struct_field_names(def_id);
609589
self.structs.insert(def_id, fields);
610590
}
591+
Def::Struct(..) => {}
611592
Def::Local(..) |
612593
Def::PrimTy(..) |
613594
Def::TyParam(..) |

src/librustc_resolve/lib.rs

+12-16
Original file line numberDiff line numberDiff line change
@@ -3579,27 +3579,23 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
35793579
// Look for trait children.
35803580
build_reduced_graph::populate_module_if_necessary(self, &search_module);
35813581

3582-
{
3583-
for (_, name_binding) in search_module.children.borrow().iter() {
3584-
let def = match name_binding.def() {
3585-
Some(def) => def,
3586-
None => continue,
3587-
};
3588-
let trait_def_id = match def {
3589-
Def::Trait(trait_def_id) => trait_def_id,
3590-
_ => continue,
3591-
};
3592-
if self.trait_item_map.contains_key(&(name, trait_def_id)) {
3593-
add_trait_info(&mut found_traits, trait_def_id, name);
3594-
}
3582+
for (&(_, ns), name_binding) in search_module.children.borrow().iter() {
3583+
if ns != TypeNS { continue }
3584+
let trait_def_id = match name_binding.def() {
3585+
Some(Def::Trait(trait_def_id)) => trait_def_id,
3586+
Some(..) | None => continue,
3587+
};
3588+
if self.trait_item_map.contains_key(&(name, trait_def_id)) {
3589+
add_trait_info(&mut found_traits, trait_def_id, name);
35953590
}
35963591
}
35973592

35983593
// Look for imports.
35993594
for (&(_, ns), import) in search_module.import_resolutions.borrow().iter() {
3600-
let target = match (ns, &import.target) {
3601-
(TypeNS, &Some(ref target)) => target.clone(),
3602-
_ => continue,
3595+
if ns != TypeNS { continue }
3596+
let target = match import.target {
3597+
Some(ref target) => target,
3598+
None => continue,
36033599
};
36043600
let did = match target.binding.def() {
36053601
Some(Def::Trait(trait_def_id)) => trait_def_id,

src/librustc_resolve/resolve_imports.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
389389
return (Success((module, name_binding)), false);
390390
}
391391

392-
if let TypeNS = ns {
392+
if ns == TypeNS {
393393
if let Some(extern_crate) = module.external_module_children.borrow().get(&name) {
394394
// track the extern crate as used.
395395
if let Some(DefId{ krate: kid, .. }) = extern_crate.def_id() {
@@ -882,7 +882,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
882882
import_span: Span,
883883
(name, ns): (Name, Namespace)) {
884884
// First, check for conflicts between imports and `extern crate`s.
885-
if let TypeNS = ns {
885+
if ns == TypeNS {
886886
if module.external_module_children.borrow().contains_key(&name) {
887887
match import.target {
888888
Some(ref target) if target.shadowable != Shadowable::Always => {
@@ -905,7 +905,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
905905
Some(name_binding) => name_binding,
906906
};
907907

908-
if let ValueNS = ns {
908+
if ns == ValueNS {
909909
match import.target {
910910
Some(ref target) if target.shadowable != Shadowable::Always => {
911911
let mut err = struct_span_err!(self.resolver.session,

0 commit comments

Comments
 (0)