about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJakub Bukaj <jakub@jakub.cc>2014-11-18 00:24:04 +0100
committerJakub Bukaj <jakub@jakub.cc>2014-11-18 00:24:04 +0100
commitf712a6fd014011ed1889c0ee046cfffda1e4e6e5 (patch)
tree6e565757ba459b55110c756dc88c96cf8b4d0552
parentf1fd6b940725bdf98147609c7cdb7fbf9bf3e29d (diff)
parent8000482e86808f7e36b8d7e595cea7c712d09a6c (diff)
downloadrust-f712a6fd014011ed1889c0ee046cfffda1e4e6e5.tar.gz
rust-f712a6fd014011ed1889c0ee046cfffda1e4e6e5.zip
rollup merge of #19018: tomjakubowski/fix-issue-19003
Make struct variant syntax more consistent with struct syntax and fix an
assert in middle::typeck.

Fix #19003
-rw-r--r--src/libsyntax/parse/parser.rs10
-rw-r--r--src/test/compile-fail/struct-variant-no-fields.rs13
2 files changed, 22 insertions, 1 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index 5c95c369f94..2bb1546cb08 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -5178,7 +5178,15 @@ impl<'a> Parser<'a> {
             if self.eat(&token::OpenDelim(token::Brace)) {
                 // Parse a struct variant.
                 all_nullary = false;
-                kind = StructVariantKind(self.parse_struct_def());
+                let start_span = self.span;
+                let struct_def = self.parse_struct_def();
+                if struct_def.fields.len() == 0 {
+                    self.span_err(start_span,
+                        format!("unit-like struct variant should be written \
+                                 without braces, as `{},`",
+                                token::get_ident(ident)).as_slice());
+                }
+                kind = StructVariantKind(struct_def);
             } else if self.token == token::OpenDelim(token::Paren) {
                 all_nullary = false;
                 let arg_tys = self.parse_enum_variant_seq(
diff --git a/src/test/compile-fail/struct-variant-no-fields.rs b/src/test/compile-fail/struct-variant-no-fields.rs
new file mode 100644
index 00000000000..41dbbeefc0a
--- /dev/null
+++ b/src/test/compile-fail/struct-variant-no-fields.rs
@@ -0,0 +1,13 @@
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+enum Foo {
+    Bar {} //~ ERROR unit-like struct variant should be written without braces, as `Bar,`
+}