From aaaf7e00ec67961e89806e0ad58a0ec9bad07ae8 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Fri, 4 Jul 2014 16:45:47 -0700 Subject: librustc: Accept type aliases for structures in structure literals and structure patterns. Closes #4508. --- src/test/auxiliary/xcrate_struct_aliases.rs | 17 +++++++++++++++ src/test/compile-fail/issue-14541.rs | 4 ++-- src/test/run-pass/struct-aliases-xcrate.rs | 31 +++++++++++++++++++++++++++ src/test/run-pass/struct-aliases.rs | 33 +++++++++++++++++++++++++++++ 4 files changed, 83 insertions(+), 2 deletions(-) create mode 100644 src/test/auxiliary/xcrate_struct_aliases.rs create mode 100644 src/test/run-pass/struct-aliases-xcrate.rs create mode 100644 src/test/run-pass/struct-aliases.rs (limited to 'src/test') 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 or the MIT license +// , 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 or the MIT license +// , 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 or the MIT license +// , 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); + } + } +} + -- cgit 1.4.1-3-g733a5