about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>2015-10-02 22:41:24 +0300
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>2015-10-13 15:19:20 +0300
commit8a12c19171887ea6d7ff708db2e2581ceaf16c14 (patch)
tree2ff02dad84730da28dc96d487d96a442350ee320 /src/test
parentbeda1f88a7d87cf994fe8e3a5b2fe126e31fcae9 (diff)
downloadrust-8a12c19171887ea6d7ff708db2e2581ceaf16c14.tar.gz
rust-8a12c19171887ea6d7ff708db2e2581ceaf16c14.zip
Test and gate empty structures and variants better
Diffstat (limited to 'src/test')
-rw-r--r--src/test/compile-fail/empty-struct-braces-expr.rs26
-rw-r--r--src/test/compile-fail/empty-struct-braces-gate-1.rs (renamed from src/test/compile-fail/empty-struct-with-braces-3.rs)14
-rw-r--r--src/test/compile-fail/empty-struct-braces-gate-2.rs49
-rw-r--r--src/test/compile-fail/empty-struct-braces-pat-1.rs (renamed from src/test/compile-fail/empty-struct-with-braces-2.rs)22
-rw-r--r--src/test/compile-fail/empty-struct-braces-pat-2.rs39
-rw-r--r--src/test/compile-fail/empty-struct-unit-expr.rs (renamed from src/test/compile-fail/empty-struct-with-braces-1.rs)11
-rw-r--r--src/test/compile-fail/empty-struct-unit-pat.rs40
-rw-r--r--src/test/compile-fail/issue-16819.rs18
-rw-r--r--src/test/compile-fail/issue-27831.rs4
-rw-r--r--src/test/compile-fail/struct-no-fields-enumlike.rs (renamed from src/test/parse-fail/struct-no-fields-enumlike.rs)4
-rw-r--r--src/test/run-pass/empty-struct-braces.rs (renamed from src/test/run-pass/empty-struct-with-braces.rs)60
11 files changed, 252 insertions, 35 deletions
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 <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
+}
diff --git a/src/test/compile-fail/empty-struct-with-braces-3.rs b/src/test/compile-fail/empty-struct-braces-gate-1.rs
index e6f20ba345a..a131b46e1c1 100644
--- a/src/test/compile-fail/empty-struct-with-braces-3.rs
+++ b/src/test/compile-fail/empty-struct-braces-gate-1.rs
@@ -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;
 
-fn main() {
-    let e = Empty {}; //~ ERROR empty structs with braces are unstable
+enum E {
+    Empty4 {}, //~ ERROR empty structs and enum variants with braces are unstable
+    Empty5,
+}
 
-    match e {
-        Empty {} => {} //~ ERROR empty structs with braces are unstable
-    }
+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 <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
+}
diff --git a/src/test/compile-fail/empty-struct-with-braces-2.rs b/src/test/compile-fail/empty-struct-braces-pat-1.rs
index 0e72e7dc441..e095f69ed7d 100644
--- a/src/test/compile-fail/empty-struct-with-braces-2.rs
+++ b/src/test/compile-fail/empty-struct-braces-pat-1.rs
@@ -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
     }
 }
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 <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`
+    // }
+}
diff --git a/src/test/compile-fail/empty-struct-with-braces-1.rs b/src/test/compile-fail/empty-struct-unit-expr.rs
index ad412259faa..199065665b9 100644
--- a/src/test/compile-fail/empty-struct-with-braces-1.rs
+++ b/src/test/compile-fail/empty-struct-unit-expr.rs
@@ -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`
 }
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 <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
+    // }
+}
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 <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;
+}
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/parse-fail/struct-no-fields-enumlike.rs b/src/test/compile-fail/struct-no-fields-enumlike.rs
index 19a395806d6..6bdbae1e4b9 100644
--- a/src/test/parse-fail/struct-no-fields-enumlike.rs
+++ b/src/test/compile-fail/struct-no-fields-enumlike.rs
@@ -8,8 +8,6 @@
 // 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;`
+struct Foo(); //~ ERROR empty tuple structs and enum variants are not allowed
 
 fn main() {}
diff --git a/src/test/run-pass/empty-struct-with-braces.rs b/src/test/run-pass/empty-struct-braces.rs
index dc806acb980..f2fbf2dd337 100644
--- a/src/test/run-pass/empty-struct-with-braces.rs
+++ b/src/test/run-pass/empty-struct-braces.rs
@@ -18,39 +18,71 @@ 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 {} => ()
+        Empty1 {} => {}
     }
     match e2 {
-        Empty2 => ()
+        Empty2 {} => {}
     }
     match e3 {
-        Empty3 {} => ()
+        Empty3 {} => {}
     }
-    match e3 {
-        Empty3 => ()
+    match e4 {
+        E::Empty4 {} => {}
+        _ => {}
     }
+    // Issue #28692
+    // match e5 {
+    //     E::Empty5 {} => {}
+    //     _ => {}
+    // }
+
     match e1 {
-        Empty1 { .. } => ()
+        Empty1 { .. } => {}
     }
     match e2 {
-        Empty2 { .. } => ()
+        Empty2 { .. } => {}
     }
     match e3 {
-        Empty3 { .. } => ()
+        Empty3 { .. } => {}
+    }
+    match e4 {
+        E::Empty4 { .. } => {}
+        _ => {}
+    }
+    // Issue #28692
+    // match e5 {
+    //     E::Empty5 { .. } => {}
+    //     _ => {}
+    // }
+
+    match e2 {
+        Empty2 => {}
+    }
+    match e3 {
+        Empty3 => {}
+    }
+    match e5 {
+        E::Empty5 => {}
+        _ => {}
     }
 
-    let e11 = Empty1 { ..e1 };
-    let e22 = Empty2 { ..e2 };
-    let e33 = Empty3 { ..e3 };
+    let e11: Empty1 = Empty1 { ..e1 };
+    let e22: Empty2 = Empty2 { ..e2 };
+    let e33: Empty3 = Empty3 { ..e3 };
 }