From 8a12c19171887ea6d7ff708db2e2581ceaf16c14 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Fri, 2 Oct 2015 22:41:24 +0300 Subject: Test and gate empty structures and variants better --- src/test/compile-fail/empty-struct-braces-expr.rs | 26 +++++++ .../compile-fail/empty-struct-braces-gate-1.rs | 23 ++++++ .../compile-fail/empty-struct-braces-gate-2.rs | 49 ++++++++++++ src/test/compile-fail/empty-struct-braces-pat-1.rs | 33 ++++++++ src/test/compile-fail/empty-struct-braces-pat-2.rs | 39 ++++++++++ src/test/compile-fail/empty-struct-unit-expr.rs | 24 ++++++ src/test/compile-fail/empty-struct-unit-pat.rs | 40 ++++++++++ .../compile-fail/empty-struct-with-braces-1.rs | 19 ----- .../compile-fail/empty-struct-with-braces-2.rs | 25 ------ .../compile-fail/empty-struct-with-braces-3.rs | 21 ------ src/test/compile-fail/issue-16819.rs | 18 +++++ src/test/compile-fail/issue-27831.rs | 4 +- src/test/compile-fail/struct-no-fields-enumlike.rs | 13 ++++ src/test/parse-fail/struct-no-fields-enumlike.rs | 15 ---- src/test/run-pass/empty-struct-braces.rs | 88 ++++++++++++++++++++++ src/test/run-pass/empty-struct-with-braces.rs | 56 -------------- 16 files changed, 355 insertions(+), 138 deletions(-) create mode 100644 src/test/compile-fail/empty-struct-braces-expr.rs create mode 100644 src/test/compile-fail/empty-struct-braces-gate-1.rs create mode 100644 src/test/compile-fail/empty-struct-braces-gate-2.rs create mode 100644 src/test/compile-fail/empty-struct-braces-pat-1.rs create mode 100644 src/test/compile-fail/empty-struct-braces-pat-2.rs create mode 100644 src/test/compile-fail/empty-struct-unit-expr.rs create mode 100644 src/test/compile-fail/empty-struct-unit-pat.rs delete mode 100644 src/test/compile-fail/empty-struct-with-braces-1.rs delete mode 100644 src/test/compile-fail/empty-struct-with-braces-2.rs delete mode 100644 src/test/compile-fail/empty-struct-with-braces-3.rs create mode 100644 src/test/compile-fail/issue-16819.rs create mode 100644 src/test/compile-fail/struct-no-fields-enumlike.rs delete mode 100644 src/test/parse-fail/struct-no-fields-enumlike.rs create mode 100644 src/test/run-pass/empty-struct-braces.rs delete mode 100644 src/test/run-pass/empty-struct-with-braces.rs (limited to 'src/test') diff --git a/src/test/compile-fail/empty-struct-braces-expr.rs b/src/test/compile-fail/empty-struct-braces-expr.rs new file mode 100644 index 00000000000..67167086b9c --- /dev/null +++ b/src/test/compile-fail/empty-struct-braces-expr.rs @@ -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 or the MIT license +// , 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 +} diff --git a/src/test/compile-fail/empty-struct-braces-gate-1.rs b/src/test/compile-fail/empty-struct-braces-gate-1.rs new file mode 100644 index 00000000000..a131b46e1c1 --- /dev/null +++ b/src/test/compile-fail/empty-struct-braces-gate-1.rs @@ -0,0 +1,23 @@ +// 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 or the MIT license +// , 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 define an empty braced struct + +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() { +} diff --git a/src/test/compile-fail/empty-struct-braces-gate-2.rs b/src/test/compile-fail/empty-struct-braces-gate-2.rs new file mode 100644 index 00000000000..c1b73bdc96a --- /dev/null +++ b/src/test/compile-fail/empty-struct-braces-gate-2.rs @@ -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 or the MIT license +// , 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 +} diff --git a/src/test/compile-fail/empty-struct-braces-pat-1.rs b/src/test/compile-fail/empty-struct-braces-pat-1.rs new file mode 100644 index 00000000000..e095f69ed7d --- /dev/null +++ b/src/test/compile-fail/empty-struct-braces-pat-1.rs @@ -0,0 +1,33 @@ +// 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 or the MIT license +// , 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 pattern + +#![deny(warnings)] +#![feature(braced_empty_structs)] + +struct Empty1 {} + +enum E { + Empty2 {} +} + +fn main() { + let e1 = Empty1 {}; + let e2 = E::Empty2 {}; + + // 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 + } +} diff --git a/src/test/compile-fail/empty-struct-braces-pat-2.rs b/src/test/compile-fail/empty-struct-braces-pat-2.rs new file mode 100644 index 00000000000..0e7152ec89a --- /dev/null +++ b/src/test/compile-fail/empty-struct-braces-pat-2.rs @@ -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 or the MIT license +// , 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` + // } +} diff --git a/src/test/compile-fail/empty-struct-unit-expr.rs b/src/test/compile-fail/empty-struct-unit-expr.rs new file mode 100644 index 00000000000..199065665b9 --- /dev/null +++ b/src/test/compile-fail/empty-struct-unit-expr.rs @@ -0,0 +1,24 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Can't use unit struct as constructor function + +#![feature(braced_empty_structs)] + +struct Empty1; + +enum E { + Empty2 +} + +fn main() { + let e1 = Empty1(); //~ ERROR expected function, found `Empty1` + let e2 = E::Empty2(); //~ ERROR expected function, found `E` +} diff --git a/src/test/compile-fail/empty-struct-unit-pat.rs b/src/test/compile-fail/empty-struct-unit-pat.rs new file mode 100644 index 00000000000..966a2780f9f --- /dev/null +++ b/src/test/compile-fail/empty-struct-unit-pat.rs @@ -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 or the MIT license +// , 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 + // } +} diff --git a/src/test/compile-fail/empty-struct-with-braces-1.rs b/src/test/compile-fail/empty-struct-with-braces-1.rs deleted file mode 100644 index ad412259faa..00000000000 --- a/src/test/compile-fail/empty-struct-with-braces-1.rs +++ /dev/null @@ -1,19 +0,0 @@ -// 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 or the MIT license -// , at your -// 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 - -#![feature(braced_empty_structs)] - -struct Empty {} - -fn main() { - let e = Empty; //~ ERROR `Empty` is the name of a struct or struct variant -} diff --git a/src/test/compile-fail/empty-struct-with-braces-2.rs b/src/test/compile-fail/empty-struct-with-braces-2.rs deleted file mode 100644 index 0e72e7dc441..00000000000 --- a/src/test/compile-fail/empty-struct-with-braces-2.rs +++ /dev/null @@ -1,25 +0,0 @@ -// 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 or the MIT license -// , at your -// 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 - -#![feature(braced_empty_structs)] -#![deny(warnings)] - -struct Empty {} - -fn main() { - let e = Empty {}; - - match e { - Empty => () //~ ERROR unused variable: `Empty` - //~^ ERROR variable `Empty` should have a snake case name such as `empty` - } -} diff --git a/src/test/compile-fail/empty-struct-with-braces-3.rs b/src/test/compile-fail/empty-struct-with-braces-3.rs deleted file mode 100644 index e6f20ba345a..00000000000 --- a/src/test/compile-fail/empty-struct-with-braces-3.rs +++ /dev/null @@ -1,21 +0,0 @@ -// 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 or the MIT license -// , 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 - -struct Empty {} //~ ERROR empty structs with braces are unstable - -fn main() { - let e = Empty {}; //~ ERROR empty structs with braces are unstable - - match e { - Empty {} => {} //~ ERROR empty structs with braces are unstable - } -} diff --git a/src/test/compile-fail/issue-16819.rs b/src/test/compile-fail/issue-16819.rs new file mode 100644 index 00000000000..065b29d29ac --- /dev/null +++ b/src/test/compile-fail/issue-16819.rs @@ -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 or the MIT license +// , 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; +} diff --git a/src/test/compile-fail/issue-27831.rs b/src/test/compile-fail/issue-27831.rs index 533387c5760..3cdb370f0e9 100644 --- a/src/test/compile-fail/issue-27831.rs +++ b/src/test/compile-fail/issue-27831.rs @@ -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 diff --git a/src/test/compile-fail/struct-no-fields-enumlike.rs b/src/test/compile-fail/struct-no-fields-enumlike.rs new file mode 100644 index 00000000000..6bdbae1e4b9 --- /dev/null +++ b/src/test/compile-fail/struct-no-fields-enumlike.rs @@ -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 or the MIT license +// , 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() {} diff --git a/src/test/parse-fail/struct-no-fields-enumlike.rs b/src/test/parse-fail/struct-no-fields-enumlike.rs deleted file mode 100644 index 19a395806d6..00000000000 --- a/src/test/parse-fail/struct-no-fields-enumlike.rs +++ /dev/null @@ -1,15 +0,0 @@ -// 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 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// compile-flags: -Z parse-only - -struct Foo(); //~ ERROR unit-like struct definition should be written as `struct Foo;` - -fn main() {} diff --git a/src/test/run-pass/empty-struct-braces.rs b/src/test/run-pass/empty-struct-braces.rs new file mode 100644 index 00000000000..f2fbf2dd337 --- /dev/null +++ b/src/test/run-pass/empty-struct-braces.rs @@ -0,0 +1,88 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Empty struct defined with braces add names into type namespace +// Empty struct defined without braces add names into both type and value namespaces + +#![feature(braced_empty_structs)] + +struct Empty1 {} +struct Empty2; +struct Empty3 {} +const Empty3: Empty3 = Empty3 {}; + +enum E { + Empty4 {}, + Empty5, +} + +fn main() { + let e1: Empty1 = Empty1 {}; + let e2: Empty2 = Empty2 {}; + let e2: Empty2 = Empty2; + let e3: Empty3 = Empty3 {}; + let e3: Empty3 = Empty3; + let e4: E = E::Empty4 {}; + // let e5: E = E::Empty5 {}; // Issue #28692 + let e5: E = E::Empty5; + + match e1 { + Empty1 {} => {} + } + match e2 { + Empty2 {} => {} + } + match e3 { + Empty3 {} => {} + } + match e4 { + E::Empty4 {} => {} + _ => {} + } + // Issue #28692 + // match e5 { + // E::Empty5 {} => {} + // _ => {} + // } + + match e1 { + Empty1 { .. } => {} + } + match e2 { + Empty2 { .. } => {} + } + match e3 { + Empty3 { .. } => {} + } + match e4 { + E::Empty4 { .. } => {} + _ => {} + } + // Issue #28692 + // match e5 { + // E::Empty5 { .. } => {} + // _ => {} + // } + + match e2 { + Empty2 => {} + } + match e3 { + Empty3 => {} + } + match e5 { + E::Empty5 => {} + _ => {} + } + + let e11: Empty1 = Empty1 { ..e1 }; + let e22: Empty2 = Empty2 { ..e2 }; + let e33: Empty3 = Empty3 { ..e3 }; +} diff --git a/src/test/run-pass/empty-struct-with-braces.rs b/src/test/run-pass/empty-struct-with-braces.rs deleted file mode 100644 index dc806acb980..00000000000 --- a/src/test/run-pass/empty-struct-with-braces.rs +++ /dev/null @@ -1,56 +0,0 @@ -// 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 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// Empty struct defined with braces add names into type namespace -// Empty struct defined without braces add names into both type and value namespaces - -#![feature(braced_empty_structs)] - -struct Empty1 {} -struct Empty2; -struct Empty3 {} -const Empty3: Empty3 = Empty3 {}; - -fn main() { - let e1: Empty1 = Empty1 {}; - let e2: Empty2 = Empty2 {}; - let e2: Empty2 = Empty2; - let e3: Empty3 = Empty3 {}; - let e3: Empty3 = Empty3; - - match e1 { - Empty1 {} => () - } - match e2 { - Empty2 {} => () - } - match e2 { - Empty2 => () - } - match e3 { - Empty3 {} => () - } - match e3 { - Empty3 => () - } - match e1 { - Empty1 { .. } => () - } - match e2 { - Empty2 { .. } => () - } - match e3 { - Empty3 { .. } => () - } - - let e11 = Empty1 { ..e1 }; - let e22 = Empty2 { ..e2 }; - let e33 = Empty3 { ..e3 }; -} -- cgit 1.4.1-3-g733a5