Test and gate empty structures and variants better
This commit is contained in:
parent
beda1f88a7
commit
8a12c19171
16 changed files with 291 additions and 69 deletions
26
src/test/compile-fail/empty-struct-braces-expr.rs
Normal file
26
src/test/compile-fail/empty-struct-braces-expr.rs
Normal 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
|
||||
}
|
||||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
49
src/test/compile-fail/empty-struct-braces-gate-2.rs
Normal file
49
src/test/compile-fail/empty-struct-braces-gate-2.rs
Normal 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
|
||||
}
|
||||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
39
src/test/compile-fail/empty-struct-braces-pat-2.rs
Normal file
39
src/test/compile-fail/empty-struct-braces-pat-2.rs
Normal 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`
|
||||
// }
|
||||
}
|
||||
|
|
@ -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`
|
||||
}
|
||||
40
src/test/compile-fail/empty-struct-unit-pat.rs
Normal file
40
src/test/compile-fail/empty-struct-unit-pat.rs
Normal 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
|
||||
// }
|
||||
}
|
||||
18
src/test/compile-fail/issue-16819.rs
Normal file
18
src/test/compile-fail/issue-16819.rs
Normal 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;
|
||||
}
|
||||
|
|
@ -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
|
||||
|
|
|
|||
13
src/test/compile-fail/struct-no-fields-enumlike.rs
Normal file
13
src/test/compile-fail/struct-no-fields-enumlike.rs
Normal 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() {}
|
||||
Loading…
Add table
Add a link
Reference in a new issue