Skip to content

Commit f712a6f

Browse files
author
Jakub Bukaj
committed
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
2 parents f1fd6b9 + 8000482 commit f712a6f

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/libsyntax/parse/parser.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5178,7 +5178,15 @@ impl<'a> Parser<'a> {
51785178
if self.eat(&token::OpenDelim(token::Brace)) {
51795179
// Parse a struct variant.
51805180
all_nullary = false;
5181-
kind = StructVariantKind(self.parse_struct_def());
5181+
let start_span = self.span;
5182+
let struct_def = self.parse_struct_def();
5183+
if struct_def.fields.len() == 0 {
5184+
self.span_err(start_span,
5185+
format!("unit-like struct variant should be written \
5186+
without braces, as `{},`",
5187+
token::get_ident(ident)).as_slice());
5188+
}
5189+
kind = StructVariantKind(struct_def);
51825190
} else if self.token == token::OpenDelim(token::Paren) {
51835191
all_nullary = false;
51845192
let arg_tys = self.parse_enum_variant_seq(
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
enum Foo {
12+
Bar {} //~ ERROR unit-like struct variant should be written without braces, as `Bar,`
13+
}

0 commit comments

Comments
 (0)