diff options
| author | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2016-01-14 14:26:50 +0300 |
|---|---|---|
| committer | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2016-01-15 19:57:53 +0300 |
| commit | ccb4b35897c0356bb397fe045fa23ddbce9fc134 (patch) | |
| tree | 395778e0f9f1e96f92593c4021d08b5c77bab9fe /src/test | |
| parent | 1f4e317e45349eb2d3c853e96bfd24dd574b36d1 (diff) | |
| download | rust-ccb4b35897c0356bb397fe045fa23ddbce9fc134.tar.gz rust-ccb4b35897c0356bb397fe045fa23ddbce9fc134.zip | |
Preserve struct/variant kinds in metadata
Add tests for use of empty structs in cross-crate scenarios
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/auxiliary/empty-struct.rs | 19 | ||||
| -rw-r--r-- | src/test/compile-fail/empty-struct-braces-expr.rs | 17 | ||||
| -rw-r--r-- | src/test/compile-fail/empty-struct-braces-pat-1.rs | 21 | ||||
| -rw-r--r-- | src/test/compile-fail/empty-struct-braces-pat-2.rs | 12 | ||||
| -rw-r--r-- | src/test/compile-fail/empty-struct-braces-pat-3.rs | 24 | ||||
| -rw-r--r-- | src/test/compile-fail/empty-struct-unit-expr.rs | 15 | ||||
| -rw-r--r-- | src/test/compile-fail/empty-struct-unit-pat.rs | 47 | ||||
| -rw-r--r-- | src/test/run-pass/empty-struct-braces.rs | 63 |
8 files changed, 188 insertions, 30 deletions
diff --git a/src/test/auxiliary/empty-struct.rs b/src/test/auxiliary/empty-struct.rs new file mode 100644 index 00000000000..3b92bc31217 --- /dev/null +++ b/src/test/auxiliary/empty-struct.rs @@ -0,0 +1,19 @@ +// 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(braced_empty_structs)] + +pub struct XEmpty1 {} +pub struct XEmpty2; + +pub enum XE { + XEmpty3 {}, + XEmpty4, +} diff --git a/src/test/compile-fail/empty-struct-braces-expr.rs b/src/test/compile-fail/empty-struct-braces-expr.rs index 67167086b9c..6ae0dad0e7b 100644 --- a/src/test/compile-fail/empty-struct-braces-expr.rs +++ b/src/test/compile-fail/empty-struct-braces-expr.rs @@ -10,17 +10,28 @@ // Can't use empty braced struct as constant or constructor function +// aux-build:empty-struct.rs + #![feature(braced_empty_structs)] +extern crate empty_struct; +use empty_struct::*; + struct Empty1 {} enum E { - Empty2 {} + Empty3 {} } 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 + let e3 = E::Empty3; //~ ERROR `E::Empty3` is the name of a struct or struct variant + let e3 = E::Empty3(); //~ ERROR `E::Empty3` is the name of a struct or struct variant + + // FIXME: non-local struct kind should be known early (e.g. kept in `DefStruct`) + // let xe1 = XEmpty1; // ERROR `XEmpty1` is the name of a struct or struct variant + let xe1 = XEmpty1(); //~ ERROR expected function, found `empty_struct::XEmpty1` + let xe3 = XE::Empty3; //~ ERROR no associated item named `Empty3` found for type + let xe3 = XE::Empty3(); //~ ERROR no associated item named `Empty3` found for type } diff --git a/src/test/compile-fail/empty-struct-braces-pat-1.rs b/src/test/compile-fail/empty-struct-braces-pat-1.rs index 6a6c3f16c04..27c97a3a550 100644 --- a/src/test/compile-fail/empty-struct-braces-pat-1.rs +++ b/src/test/compile-fail/empty-struct-braces-pat-1.rs @@ -10,22 +10,35 @@ // Can't use empty braced struct as constant pattern +// aux-build:empty-struct.rs + #![feature(braced_empty_structs)] +extern crate empty_struct; +use empty_struct::*; + struct Empty1 {} enum E { - Empty2 {} + Empty3 {} } fn main() { let e1 = Empty1 {}; - let e2 = E::Empty2 {}; + let e3 = E::Empty3 {}; + let xe1 = XEmpty1 {}; + let xe3 = XE::XEmpty3 {}; match e1 { Empty1 => () // Not an error, `Empty1` is interpreted as a new binding } - match e2 { - E::Empty2 => () //~ ERROR `E::Empty2` does not name a tuple variant or a tuple struct + match e3 { + E::Empty3 => () //~ ERROR `E::Empty3` does not name a tuple variant or a tuple struct + } + match xe1 { + XEmpty1 => () // Not an error, `XEmpty1` is interpreted as a new binding + } + match xe3 { + XE::XEmpty3 => () //~ ERROR no associated item named `XEmpty3` found for type } } diff --git a/src/test/compile-fail/empty-struct-braces-pat-2.rs b/src/test/compile-fail/empty-struct-braces-pat-2.rs index d98d64b712a..3436e2a2cd7 100644 --- a/src/test/compile-fail/empty-struct-braces-pat-2.rs +++ b/src/test/compile-fail/empty-struct-braces-pat-2.rs @@ -10,18 +10,30 @@ // Can't use empty braced struct as enum pattern +// aux-build:empty-struct.rs + #![feature(braced_empty_structs)] +extern crate empty_struct; +use empty_struct::*; + struct Empty1 {} fn main() { let e1 = Empty1 {}; + let xe1 = XEmpty1 {}; // Rejected by parser as yet // match e1 { // Empty1() => () // ERROR unresolved enum variant, struct or const `Empty1` // } + // match xe1 { + // XEmpty1() => () // ERROR unresolved enum variant, struct or const `XEmpty1` + // } match e1 { Empty1(..) => () //~ ERROR unresolved enum variant, struct or const `Empty1` } + match xe1 { + XEmpty1(..) => () //~ ERROR `XEmpty1` does not name a tuple variant or a tuple struct + } } diff --git a/src/test/compile-fail/empty-struct-braces-pat-3.rs b/src/test/compile-fail/empty-struct-braces-pat-3.rs index 9fae203f389..ca51a1cfc21 100644 --- a/src/test/compile-fail/empty-struct-braces-pat-3.rs +++ b/src/test/compile-fail/empty-struct-braces-pat-3.rs @@ -10,20 +10,32 @@ // Can't use empty braced struct as enum pattern +// aux-build:empty-struct.rs + #![feature(braced_empty_structs)] +extern crate empty_struct; +use empty_struct::*; + enum E { - Empty2 {} + Empty3 {} } fn main() { - let e2 = E::Empty2 {}; + let e3 = E::Empty3 {}; + let xe3 = XE::XEmpty3 {}; // Rejected by parser as yet - // match e2 { - // E::Empty2() => () // ERROR `E::Empty2` does not name a tuple variant or a tuple struct + // match e3 { + // E::Empty3() => () // ERROR `E::Empty3` does not name a tuple variant or a tuple struct // } - match e2 { - E::Empty2(..) => () //~ ERROR `E::Empty2` does not name a tuple variant or a tuple struct + // match xe3 { + // E::Empty3() => () // ERROR `XE::XEmpty3` does not name a tuple variant or a tuple struct + // } + match e3 { + E::Empty3(..) => () //~ ERROR `E::Empty3` does not name a tuple variant or a tuple struct + } + match xe3 { + XE::XEmpty3(..) => () //~ ERROR no associated item named `XEmpty3` found for type } } diff --git a/src/test/compile-fail/empty-struct-unit-expr.rs b/src/test/compile-fail/empty-struct-unit-expr.rs index 199065665b9..822ee9e0dbc 100644 --- a/src/test/compile-fail/empty-struct-unit-expr.rs +++ b/src/test/compile-fail/empty-struct-unit-expr.rs @@ -10,15 +10,22 @@ // Can't use unit struct as constructor function +// aux-build:empty-struct.rs + #![feature(braced_empty_structs)] -struct Empty1; +extern crate empty_struct; +use empty_struct::*; + +struct Empty2; enum E { - Empty2 + Empty4 } fn main() { - let e1 = Empty1(); //~ ERROR expected function, found `Empty1` - let e2 = E::Empty2(); //~ ERROR expected function, found `E` + let e2 = Empty2(); //~ ERROR expected function, found `Empty2` + let e4 = E::Empty4(); //~ ERROR expected function, found `E` + let xe2 = XEmpty2(); //~ ERROR expected function, found `empty_struct::XEmpty2` + let xe4 = XE::XEmpty4(); //~ ERROR expected function, found `empty_struct::XE` } diff --git a/src/test/compile-fail/empty-struct-unit-pat.rs b/src/test/compile-fail/empty-struct-unit-pat.rs index cffd9fd9b49..0f54d1b7365 100644 --- a/src/test/compile-fail/empty-struct-unit-pat.rs +++ b/src/test/compile-fail/empty-struct-unit-pat.rs @@ -10,36 +10,59 @@ // Can't use unit struct as enum pattern +// aux-build:empty-struct.rs + #![feature(rustc_attrs)] // remove prior feature after warning cycle and promoting warnings to errors #![feature(braced_empty_structs)] -struct Empty1; +extern crate empty_struct; +use empty_struct::*; + +struct Empty2; enum E { - Empty2 + Empty4 } // remove attribute after warning cycle and promoting warnings to errors #[rustc_error] fn main() { //~ ERROR: compilation successful - let e1 = Empty1; - let e2 = E::Empty2; + let e2 = Empty2; + let e4 = E::Empty4; + let xe2 = XEmpty2; + let xe4 = XE::XEmpty4; // Rejected by parser as yet - // match e1 { - // Empty1() => () // ERROR `Empty1` does not name a tuple variant or a tuple struct + // match e2 { + // Empty2() => () // ERROR `Empty2` does not name a tuple variant or a tuple struct // } - match e1 { - Empty1(..) => () //~ WARN `Empty1` does not name a tuple variant or a tuple struct + // match xe2 { + // XEmpty2() => () // ERROR `XEmpty2` does not name a tuple variant or a tuple struct + // } + match e2 { + Empty2(..) => () //~ WARN `Empty2` does not name a tuple variant or a tuple struct + //~^ WARN hard error + } + match xe2 { + XEmpty2(..) => () //~ WARN `XEmpty2` does not name a tuple variant or a tuple struct //~^ WARN hard error } // Rejected by parser as yet - // match e2 { - // E::Empty2() => () // ERROR `E::Empty2` does not name a tuple variant or a tuple struct + // match e4 { + // E::Empty4() => () // ERROR `E::Empty4` does not name a tuple variant or a tuple struct // } - match e2 { - E::Empty2(..) => () //~ WARN `E::Empty2` does not name a tuple variant or a tuple struct + // match xe4 { + // XE::XEmpty4() => (), // ERROR `XE::XEmpty4` does not name a tuple variant or a tuple + // _ => {}, + // } + match e4 { + E::Empty4(..) => () //~ WARN `E::Empty4` does not name a tuple variant or a tuple struct + //~^ WARN hard error + } + match xe4 { + XE::XEmpty4(..) => (), //~ WARN `XE::XEmpty4` does not name a tuple variant or a tuple //~^ WARN hard error + _ => {}, } } diff --git a/src/test/run-pass/empty-struct-braces.rs b/src/test/run-pass/empty-struct-braces.rs index 80ea1bc3a0e..b4ce1b97a4c 100644 --- a/src/test/run-pass/empty-struct-braces.rs +++ b/src/test/run-pass/empty-struct-braces.rs @@ -11,8 +11,13 @@ // Empty struct defined with braces add names into type namespace // Empty struct defined without braces add names into both type and value namespaces +// aux-build:empty-struct.rs + #![feature(braced_empty_structs)] +extern crate empty_struct; +use empty_struct::*; + struct Empty1 {} struct Empty2; struct Empty3 {} @@ -23,7 +28,7 @@ enum E { Empty5, } -fn main() { +fn local() { let e1: Empty1 = Empty1 {}; let e2: Empty2 = Empty2 {}; let e2: Empty2 = Empty2; @@ -84,3 +89,59 @@ fn main() { let e22: Empty2 = Empty2 { ..e2 }; let e33: Empty3 = Empty3 { ..e3 }; } + +fn xcrate() { + let e1: XEmpty1 = XEmpty1 {}; + let e2: XEmpty2 = XEmpty2 {}; + let e2: XEmpty2 = XEmpty2; + let e3: XE = XE::XEmpty3 {}; + // FIXME: Commented out tests are waiting for PR 30882 (fixes for variant namespaces) + // let e4: XE = XE::XEmpty4 {}; + let e4: XE = XE::XEmpty4; + + match e1 { + XEmpty1 {} => {} + } + match e2 { + XEmpty2 {} => {} + } + match e3 { + XE::XEmpty3 {} => {} + _ => {} + } + // match e4 { + // XE::XEmpty4 {} => {} + // _ => {} + // } + + match e1 { + XEmpty1 { .. } => {} + } + match e2 { + XEmpty2 { .. } => {} + } + match e3 { + XE::XEmpty3 { .. } => {} + _ => {} + } + // match e4 { + // XE::XEmpty4 { .. } => {} + // _ => {} + // } + + match e2 { + XEmpty2 => {} + } + // match e4 { + // XE::XEmpty4 => {} + // _ => {} + // } + + let e11: XEmpty1 = XEmpty1 { ..e1 }; + let e22: XEmpty2 = XEmpty2 { ..e2 }; +} + +fn main() { + local(); + xcrate(); +} |
