Disallow parsing of struct variants with 0 fields
Make struct variant syntax more consistent with struct syntax and fix an assert in middle::typeck. Fix #19003
This commit is contained in:
parent
0b7b4f075a
commit
8000482e86
2 changed files with 22 additions and 1 deletions
|
@ -5175,7 +5175,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(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue