about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorPatrick Walton <pcwalton@mimiga.net>2012-10-23 19:18:18 -0700
committerPatrick Walton <pcwalton@mimiga.net>2012-10-24 10:54:09 -0700
commit4da58a5bd6f921b446e46cf65790975598289308 (patch)
tree3e0de65d3b2b901ebf2ca5adaa587036fcbbc336 /src/libsyntax
parent61bb3571a59f4659a0a46565c71fa7ecfa352811 (diff)
downloadrust-4da58a5bd6f921b446e46cf65790975598289308.tar.gz
rust-4da58a5bd6f921b446e46cf65790975598289308.zip
rustc: Implement typechecking for tuple structs. r=nmatsakis
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/ast.rs30
-rw-r--r--src/libsyntax/fold.rs6
-rw-r--r--src/libsyntax/parse/parser.rs7
3 files changed, 38 insertions, 5 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs
index 8aef8a0caee..e25fb470bb9 100644
--- a/src/libsyntax/ast.rs
+++ b/src/libsyntax/ast.rs
@@ -1444,6 +1444,31 @@ enum struct_field_kind {
     unnamed_field   // element of a tuple-like struct
 }
 
+impl struct_field_kind : cmp::Eq {
+    pure fn eq(other: &struct_field_kind) -> bool {
+        match self {
+            named_field(ident_a, class_mutability_a, visibility_a) => {
+                match *other {
+                    named_field(ident_b, class_mutability_b, visibility_b)
+                            => {
+                        ident_a == ident_b &&
+                        class_mutability_a == class_mutability_b &&
+                        visibility_a == visibility_b
+                    }
+                    unnamed_field => false
+                }
+            }
+            unnamed_field => {
+                match *other {
+                    named_field(*) => false,
+                    unnamed_field => true
+                }
+            }
+        }
+    }
+    pure fn ne(other: &struct_field_kind) -> bool { !self.eq(other) }
+}
+
 #[auto_serialize]
 #[auto_deserialize]
 type struct_def = {
@@ -1452,7 +1477,10 @@ type struct_def = {
     methods: ~[@method],    /* methods */
     /* (not including ctor or dtor) */
     /* dtor is optional */
-    dtor: Option<class_dtor>
+    dtor: Option<class_dtor>,
+    /* ID of the constructor. This is only used for tuple- or enum-like
+     * structs. */
+    ctor_id: node_id
 };
 
 /*
diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs
index 2fd1d8ec928..d1b97549225 100644
--- a/src/libsyntax/fold.rs
+++ b/src/libsyntax/fold.rs
@@ -280,7 +280,8 @@ fn fold_struct_def(struct_def: @ast::struct_def, fld: ast_fold)
         traits: vec::map(struct_def.traits, |p| fold_trait_ref(*p, fld)),
         fields: vec::map(struct_def.fields, |f| fold_struct_field(*f, fld)),
         methods: vec::map(struct_def.methods, |m| fld.fold_method(*m)),
-        dtor: dtor
+        dtor: dtor,
+        ctor_id: fld.new_id(struct_def.ctor_id)
     };
 }
 
@@ -563,7 +564,8 @@ fn noop_fold_variant(v: variant_, fld: ast_fold) -> variant_ {
                                  |f| fld.fold_struct_field(*f)),
                 methods: vec::map(struct_def.methods,
                                   |m| fld.fold_method(*m)),
-                dtor: dtor
+                dtor: dtor,
+                ctor_id: fld.new_id(struct_def.ctor_id)
             })
         }
 
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index 6e16e4eec1a..e0570c537a7 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -2722,12 +2722,14 @@ impl Parser {
                     self_id: self.get_id(),
                     body: d_body},
              span: d_s}};
+        let _ = self.get_id();  // XXX: Workaround for crazy bug.
         (class_name,
          item_class(@{
              traits: traits,
              fields: move fields,
              methods: move methods,
-             dtor: actual_dtor
+             dtor: actual_dtor,
+             ctor_id: self.get_id()
          }, ty_params),
          None)
     }
@@ -3073,7 +3075,8 @@ impl Parser {
             traits: ~[],
             fields: move fields,
             methods: move methods,
-            dtor: actual_dtor
+            dtor: actual_dtor,
+            ctor_id: self.get_id()
         };
     }