auto merge of #15440 : pcwalton/rust/struct-aliases, r=brson
Closes #4508. r? @nick29581
This commit is contained in:
commit
c175ed4425
11 changed files with 173 additions and 68 deletions
17
src/test/auxiliary/xcrate_struct_aliases.rs
Normal file
17
src/test/auxiliary/xcrate_struct_aliases.rs
Normal file
|
|
@ -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;
|
||||
|
||||
|
|
@ -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() { }
|
||||
fn main() { }
|
||||
|
|
|
|||
31
src/test/run-pass/struct-aliases-xcrate.rs
Normal file
31
src/test/run-pass/struct-aliases-xcrate.rs
Normal file
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
33
src/test/run-pass/struct-aliases.rs
Normal file
33
src/test/run-pass/struct-aliases.rs
Normal file
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue