Skip to content

Commit baa7208

Browse files
committed
auto merge of #15098 : ben0x539/rust/nullary-tuple-struct, r=pcwalton
Reject `struct Foo();` to fix #15095.
2 parents 4362db0 + ff50ce9 commit baa7208

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

src/libsyntax/parse/parser.rs

+5
Original file line numberDiff line numberDiff line change
@@ -4116,6 +4116,11 @@ impl<'a> Parser<'a> {
41164116
};
41174117
spanned(lo, p.span.hi, struct_field_)
41184118
});
4119+
if fields.len() == 0 {
4120+
self.fatal(format!("unit-like struct definition should be \
4121+
written as `struct {};`",
4122+
token::get_ident(class_name)).as_slice());
4123+
}
41194124
self.expect(&token::SEMI);
41204125
} else if self.eat(&token::SEMI) {
41214126
// It's a unit-like struct.

src/test/compile-fail/lint-dead-code-1.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ static USED_STATIC: int = 0;
3737
static STATIC_USED_IN_ENUM_DISCRIMINANT: uint = 10;
3838

3939
pub type typ = *UsedStruct4;
40-
pub struct PubStruct();
40+
pub struct PubStruct;
4141
struct PrivStruct; //~ ERROR: code is never used
4242
struct UsedStruct1 {
4343
#[allow(dead_code)]
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+
struct Foo(); //~ ERROR unit-like struct definition should be written as `struct Foo;`
12+
13+
fn main() {}

0 commit comments

Comments
 (0)