rust/tests/ui/structs-enums/rec-tup.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

32 lines
759 B
Rust
Raw Normal View History

// run-pass
#![allow(non_camel_case_types)]
2015-03-30 13:38:27 +00:00
#[derive(Copy, Clone)]
struct Point {x: isize, y: isize}
2011-08-15 11:39:45 +00:00
type rect = (Point, Point);
2011-08-15 11:39:45 +00:00
fn fst(r: rect) -> Point { let (fst, _) = r; return fst; }
fn snd(r: rect) -> Point { let (_, snd) = r; return snd; }
2011-08-15 11:39:45 +00:00
fn f(r: rect, x1: isize, y1: isize, x2: isize, y2: isize) {
assert_eq!(fst(r).x, x1);
assert_eq!(fst(r).y, y1);
assert_eq!(snd(r).x, x2);
assert_eq!(snd(r).y, y2);
2011-08-15 11:39:45 +00:00
}
pub fn main() {
let r: rect = (Point {x: 10, y: 20}, Point {x: 11, y: 22});
assert_eq!(fst(r).x, 10);
assert_eq!(fst(r).y, 20);
assert_eq!(snd(r).x, 11);
assert_eq!(snd(r).y, 22);
2011-08-15 11:39:45 +00:00
let r2 = r;
let x: isize = fst(r2).x;
assert_eq!(x, 10);
2011-08-15 11:39:45 +00:00
f(r, 10, 20, 11, 22);
f(r2, 10, 20, 11, 22);
}