rustc: disallow trailing parentheses for nullary enum variants

Fixes #12560
This commit is contained in:
Laurent Bonnans 2014-03-16 16:07:39 +01:00
parent e4c91e6c7c
commit 695114ea2c
6 changed files with 74 additions and 7 deletions

View file

@ -1,4 +1,4 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
@ -12,5 +12,5 @@
fn main() {
// a bug in the parser is allowing this:
let a() = 13;
let a(1) = 13;
}

View file

@ -0,0 +1,23 @@
// 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.
// For style and consistency reasons, non-parametrized enum variants must
// be used simply as `ident` instead of `ident ()`.
// This test-case covers enum declaration.
enum Foo {
Bar(), //~ ERROR nullary enum variants are written with no trailing `( )`
Baz(), //~ ERROR nullary enum variants are written with no trailing `( )`
Bazar
}
fn main() {
println!("{}", match Bar { Bar => 1, Baz => 2, Bazar => 3 })
}

View file

@ -0,0 +1,27 @@
// 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.
// For style and consistency reasons, non-parametrized enum variants must
// be used simply as `ident` instead of `ident ()`.
// This test-case covers enum matching.
enum Foo {
Bar,
Baz,
Bazar
}
fn main() {
println!("{}", match Bar {
Bar() => 1, //~ ERROR nullary enum variants are written with no trailing `( )`
Baz() => 2, //~ ERROR nullary enum variants are written with no trailing `( )`
Bazar => 3
})
}

View file

@ -1,4 +1,4 @@
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
// Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
@ -14,7 +14,7 @@
fn main() {
let z = match 3 {
x() => x
x(1) => x(1)
};
assert_eq!(z,3);
}