about summary refs log tree commit diff
path: root/src/rustc
diff options
context:
space:
mode:
authorTim Chevalier <chevalier@alum.wellesley.edu>2012-06-05 20:46:10 -0700
committerTim Chevalier <chevalier@alum.wellesley.edu>2012-06-05 20:47:55 -0700
commit8fd9986f0ff1d0414cc064451f72748065a77cdf (patch)
tree51be90e6e4a5fef05fae84e4bb091064fadc58dd /src/rustc
parent167d72618371b7f7dd75df7c5a5b1375d1823a3d (diff)
Forbid classes with no fields
Classes with no fields don't really make sense, so forbid them
(just as records with no fields aren't allowed). Closes #2509
Diffstat (limited to 'src/rustc')
-rw-r--r--src/rustc/middle/typeck/check.rs6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/rustc/middle/typeck/check.rs b/src/rustc/middle/typeck/check.rs
index 70167192afc..b3f7c5a9388 100644
--- a/src/rustc/middle/typeck/check.rs
+++ b/src/rustc/middle/typeck/check.rs
@@ -387,6 +387,12 @@ fn check_item(ccx: @crate_ctxt, it: @ast::item) {
           };
           // typecheck the members
           for members.each {|m| check_class_member(class_ccx, class_t, m); }
+          // Check that there's at least one field
+          let (fields,_) = split_class_items(members);
+          if fields.len() < 1u {
+              ccx.tcx.sess.span_err(it.span, "A class must have at least one \
+                field");
+          }
           // Check that the class is instantiable
           check_instantiable(ccx.tcx, it.span, it.id);
       }