Skip to content

Commit

Permalink
librustc: Don't allow newtype or unit-like structs to shadow other na…
Browse files Browse the repository at this point in the history
…mes in the value namespace.
  • Loading branch information
luqmana committed Jun 10, 2013
1 parent 2ff6b29 commit 5a3e1cd
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions src/librustc/middle/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1195,22 +1195,22 @@ impl Resolver {

// These items live in both the type and value namespaces.
item_struct(struct_def, _) => {
let (name_bindings, new_parent) =
self.add_child(ident, parent, ForbidDuplicateTypes, sp);
// Adding to both Type and Value namespaces or just Type?
let (forbid, ctor_id) = match struct_def.ctor_id {
Some(ctor_id) => (ForbidDuplicateTypesAndValues, Some(ctor_id)),
None => (ForbidDuplicateTypes, None)
};

name_bindings.define_type(
privacy, def_ty(local_def(item.id)), sp);
let (name_bindings, new_parent) = self.add_child(ident, parent, forbid, sp);

// If this struct is tuple-like or enum-like, define a name
// in the value namespace.
match struct_def.ctor_id {
None => {}
Some(ctor_id) => {
name_bindings.define_value(
privacy,
def_struct(local_def(ctor_id)),
sp);
}
// Define a name in the type namespace.
name_bindings.define_type(privacy, def_ty(local_def(item.id)), sp);

// If this is a newtype or unit-like struct, define a name
// in the value namespace as well
do ctor_id.while_some |cid| {
name_bindings.define_value(privacy, def_struct(local_def(cid)), sp);
None
}

// Record the def ID of this struct.
Expand Down

0 comments on commit 5a3e1cd

Please sign in to comment.