Test and gate empty structures and variants better

This commit is contained in:
Vadim Petrochenkov 2015-10-02 22:41:24 +03:00
parent beda1f88a7
commit 8a12c19171
16 changed files with 291 additions and 69 deletions

View file

@ -0,0 +1,26 @@
// Copyright 2015 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.
// Can't use empty braced struct as constant or constructor function
#![feature(braced_empty_structs)]
struct Empty1 {}
enum E {
Empty2 {}
}
fn main() {
let e1 = Empty1; //~ ERROR `Empty1` is the name of a struct or struct variant
let e1 = Empty1(); //~ ERROR `Empty1` is the name of a struct or struct variant
let e2 = E::Empty2; //~ ERROR `E::Empty2` is the name of a struct or struct variant
let e2 = E::Empty2(); //~ ERROR `E::Empty2` is the name of a struct or struct variant
}

View file

@ -9,13 +9,15 @@
// except according to those terms.
// Feature gate test for empty struct with braces
// Can't define an empty braced struct
struct Empty {} //~ ERROR empty structs with braces are unstable
struct Empty1 {} //~ ERROR empty structs and enum variants with braces are unstable
struct Empty2;
enum E {
Empty4 {}, //~ ERROR empty structs and enum variants with braces are unstable
Empty5,
}
fn main() {
let e = Empty {}; //~ ERROR empty structs with braces are unstable
match e {
Empty {} => {} //~ ERROR empty structs with braces are unstable
}
}

View file

@ -0,0 +1,49 @@
// Copyright 2015 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.
// Feature gate test for empty struct with braces
// Can't use braced expressions and patterns with structs defined without braces
struct Empty2;
enum E {
Empty5,
}
fn main() {
let e2: Empty2 = Empty2 {}; //~ ERROR empty structs and enum variants with braces are unstable
let e2: Empty2 = Empty2;
// Issue #28692
// let e5: E = E::Empty5 {}; // ERROR empty structs and enum variants with braces are unstable
let e5: E = E::Empty5;
match e2 {
Empty2 {} => {} //~ ERROR empty structs and enum variants with braces are unstable
}
match e2 {
Empty2 => {}
}
match e2 {
Empty2 { .. } => {} //~ ERROR empty structs and enum variants with braces are unstable
}
// Issue #28692
// match e5 {
// E::Empty5 {} => {} // ERROR empty structs and enum variants with braces are unstable
// }
match e5 {
E::Empty5 => {}
}
// Issue #28692
// match e5 {
// E::Empty5 { .. } => {} // ERROR empty structs and enum variants with braces are unstable
// }
let e22 = Empty2 { ..e2 }; //~ ERROR empty structs and enum variants with braces are unstable
}

View file

@ -8,18 +8,26 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// Empty struct defined with braces shouldn't add names into value namespace
// Can't use empty braced struct as constant pattern
#![feature(braced_empty_structs)]
#![deny(warnings)]
#![feature(braced_empty_structs)]
struct Empty {}
struct Empty1 {}
enum E {
Empty2 {}
}
fn main() {
let e = Empty {};
let e1 = Empty1 {};
let e2 = E::Empty2 {};
match e {
Empty => () //~ ERROR unused variable: `Empty`
//~^ ERROR variable `Empty` should have a snake case name such as `empty`
// Issue #28692
// match e1 {
// Empty1 => () // ERROR incorrect error
// }
match e2 {
E::Empty2 => () //~ ERROR `E::Empty2` does not name a non-struct variant or a tuple struct
}
}

View file

@ -0,0 +1,39 @@
// Copyright 2015 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.
// Can't use empty braced struct as enum pattern
#![feature(braced_empty_structs)]
struct Empty1 {}
enum E {
Empty2 {}
}
fn main() {
let e1 = Empty1 {};
let e2 = E::Empty2 {};
// Rejected by parser as yet
// match e1 {
// Empty1() => () // ERROR unresolved enum variant, struct or const `Empty1`
// }
match e1 {
Empty1(..) => () //~ ERROR unresolved enum variant, struct or const `Empty1`
}
// Issue #28692
// match e2 {
// E::Empty2() => () // ERROR unresolved enum variant, struct or const `Empty2`
// }
// match e2 {
// E::Empty2(..) => () // ERROR unresolved enum variant, struct or const `Empty2`
// }
}

View file

@ -8,12 +8,17 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// Empty struct defined with braces shouldn't add names into value namespace
// Can't use unit struct as constructor function
#![feature(braced_empty_structs)]
struct Empty {}
struct Empty1;
enum E {
Empty2
}
fn main() {
let e = Empty; //~ ERROR `Empty` is the name of a struct or struct variant
let e1 = Empty1(); //~ ERROR expected function, found `Empty1`
let e2 = E::Empty2(); //~ ERROR expected function, found `E`
}

View file

@ -0,0 +1,40 @@
// Copyright 2015 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.
// Can't use unit struct as enum pattern
#![feature(braced_empty_structs)]
FIXME //~ ERROR expected item, found `FIXME`
struct Empty1;
enum E {
Empty2
}
fn main() {
let e1 = Empty1;
let e2 = E::Empty2;
// Issue #28692
// match e1 {
// Empty1() => () // ERROR variable `Empty1` should have a snake case name
// }
// match e1 {
// Empty1(..) => () // ERROR variable `Empty1` should have a snake case name
// }
// match e2 {
// E::Empty2() => () // ERROR variable `Empty2` should have a snake case name
// }
// match e2 {
// E::Empty2(..) => () // ERROR variable `Empty2` should have a snake case name
// }
}

View file

@ -0,0 +1,18 @@
// Copyright 2015 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.
struct TS ( //~ ERROR empty tuple structs and enum variants are not allowed
#[cfg(untrue)]
int,
);
fn main() {
let s = S;
}

View file

@ -22,8 +22,8 @@ fn main() {
let Foo { .. } = x; //~ ERROR `Foo` does not name a struct
let x = Bar;
Bar { ..x };
let Bar { .. } = x;
Bar { ..x }; //~ ERROR empty structs and enum variants with braces are unstable
let Bar { .. } = x; //~ ERROR empty structs and enum variants with braces are unstable
match Enum::Bar {
Enum::Bar { .. } //~ ERROR `Enum::Bar` does not name a struct

View file

@ -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.
struct Foo(); //~ ERROR empty tuple structs and enum variants are not allowed
fn main() {}