diff options
| author | Tim Chevalier <chevalier@alum.wellesley.edu> | 2012-06-05 20:46:10 -0700 |
|---|---|---|
| committer | Tim Chevalier <chevalier@alum.wellesley.edu> | 2012-06-05 20:47:55 -0700 |
| commit | 8fd9986f0ff1d0414cc064451f72748065a77cdf (patch) | |
| tree | 51be90e6e4a5fef05fae84e4bb091064fadc58dd /src/rustc | |
| parent | 167d72618371b7f7dd75df7c5a5b1375d1823a3d (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.rs | 6 |
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); } |
