]> git.proxmox.com Git - rustc.git/blob - src/test/run-pass/rec-tup.rs
New upstream version 1.19.0+dfsg1
[rustc.git] / src / test / run-pass / rec-tup.rs
1 // Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11
12 #[derive(Copy, Clone)]
13 struct Point {x: isize, y: isize}
14
15 type rect = (Point, Point);
16
17 fn fst(r: rect) -> Point { let (fst, _) = r; return fst; }
18 fn snd(r: rect) -> Point { let (_, snd) = r; return snd; }
19
20 fn f(r: rect, x1: isize, y1: isize, x2: isize, y2: isize) {
21 assert_eq!(fst(r).x, x1);
22 assert_eq!(fst(r).y, y1);
23 assert_eq!(snd(r).x, x2);
24 assert_eq!(snd(r).y, y2);
25 }
26
27 pub fn main() {
28 let r: rect = (Point {x: 10, y: 20}, Point {x: 11, y: 22});
29 assert_eq!(fst(r).x, 10);
30 assert_eq!(fst(r).y, 20);
31 assert_eq!(snd(r).x, 11);
32 assert_eq!(snd(r).y, 22);
33 let r2 = r;
34 let x: isize = fst(r2).x;
35 assert_eq!(x, 10);
36 f(r, 10, 20, 11, 22);
37 f(r2, 10, 20, 11, 22);
38 }