diff options
| author | Patrick Walton <pcwalton@mimiga.net> | 2014-07-04 16:45:47 -0700 |
|---|---|---|
| committer | Patrick Walton <pcwalton@mimiga.net> | 2014-07-04 17:07:31 -0700 |
| commit | aaaf7e00ec67961e89806e0ad58a0ec9bad07ae8 (patch) | |
| tree | dfcb5a2bb80b42a676529462306d8ceb23aec934 /src/test | |
| parent | 9897160523ab3e792f0309250da49d289d2a5598 (diff) | |
| download | rust-aaaf7e00ec67961e89806e0ad58a0ec9bad07ae8.tar.gz rust-aaaf7e00ec67961e89806e0ad58a0ec9bad07ae8.zip | |
librustc: Accept type aliases for structures in structure literals and
structure patterns. Closes #4508.
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/auxiliary/xcrate_struct_aliases.rs | 17 | ||||
| -rw-r--r-- | src/test/compile-fail/issue-14541.rs | 4 | ||||
| -rw-r--r-- | src/test/run-pass/struct-aliases-xcrate.rs | 31 | ||||
| -rw-r--r-- | src/test/run-pass/struct-aliases.rs | 33 |
4 files changed, 83 insertions, 2 deletions
diff --git a/src/test/auxiliary/xcrate_struct_aliases.rs b/src/test/auxiliary/xcrate_struct_aliases.rs new file mode 100644 index 00000000000..a0ec7272720 --- /dev/null +++ b/src/test/auxiliary/xcrate_struct_aliases.rs @@ -0,0 +1,17 @@ +// Copyright 2012 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. + +pub struct S { + pub x: int, + pub y: int, +} + +pub type S2 = S; + diff --git a/src/test/compile-fail/issue-14541.rs b/src/test/compile-fail/issue-14541.rs index 2dcfeac513c..921e331e960 100644 --- a/src/test/compile-fail/issue-14541.rs +++ b/src/test/compile-fail/issue-14541.rs @@ -13,8 +13,8 @@ struct vec3 { y: f32, z: f32 } fn make(v: vec2) { let vec3 { y: _, z: _ } = v; - //~^ ERROR mismatched types: expected `vec2` but found `vec3` + //~^ ERROR `vec3` does not name the structure `vec2` //~^^ ERROR struct `vec2` does not have a field named `z` } -fn main() { } \ No newline at end of file +fn main() { } diff --git a/src/test/run-pass/struct-aliases-xcrate.rs b/src/test/run-pass/struct-aliases-xcrate.rs new file mode 100644 index 00000000000..9046cafe757 --- /dev/null +++ b/src/test/run-pass/struct-aliases-xcrate.rs @@ -0,0 +1,31 @@ +// Copyright 2012 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. + +// aux-build:xcrate_struct_aliases.rs +extern crate xcrate_struct_aliases; + +use xcrate_struct_aliases::{S, S2}; + +fn main() { + let s = S2 { + x: 1, + y: 2, + }; + match s { + S2 { + x: x, + y: y + } => { + assert_eq!(x, 1); + assert_eq!(y, 2); + } + } +} + diff --git a/src/test/run-pass/struct-aliases.rs b/src/test/run-pass/struct-aliases.rs new file mode 100644 index 00000000000..2cf961a5c0c --- /dev/null +++ b/src/test/run-pass/struct-aliases.rs @@ -0,0 +1,33 @@ +// Copyright 2012 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 S { + x: int, + y: int, +} + +type S2 = S; + +fn main() { + let s = S2 { + x: 1, + y: 2, + }; + match s { + S2 { + x: x, + y: y + } => { + assert_eq!(x, 1); + assert_eq!(y, 2); + } + } +} + |
