about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLuqman Aden <me@luqman.ca>2013-06-10 17:29:48 -0400
committerLuqman Aden <me@luqman.ca>2013-06-10 17:29:48 -0400
commit5a3e1cdaec91b6fc43d4a95670859b8b5637e397 (patch)
tree6b0c0236ed1d13db168766c0159b773c5bba6b89
parent2ff6b298c5f23f48aa993fced41b6e29e446b7ce (diff)
downloadrust-5a3e1cdaec91b6fc43d4a95670859b8b5637e397.tar.gz
rust-5a3e1cdaec91b6fc43d4a95670859b8b5637e397.zip
librustc: Don't allow newtype or unit-like structs to shadow other names in the value namespace.
-rw-r--r--src/librustc/middle/resolve.rs28
1 files changed, 14 insertions, 14 deletions
diff --git a/src/librustc/middle/resolve.rs b/src/librustc/middle/resolve.rs
index 2d2eeff199f..23b410c3d49 100644
--- a/src/librustc/middle/resolve.rs
+++ b/src/librustc/middle/resolve.rs
@@ -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.