rust/src/test/run-pass/generic-fn.rs

28 lines
499 B
Rust
Raw Normal View History

2010-06-23 23:03:09 -05:00
// -*- rust -*-
2012-08-01 19:30:05 -05:00
fn id<T: copy>(x: T) -> T { return x; }
2010-06-23 23:03:09 -05:00
2011-07-27 07:19:39 -05:00
type triple = {x: int, y: int, z: int};
2010-06-23 23:03:09 -05:00
fn main() {
let mut x = 62;
let mut y = 63;
2011-07-27 07:19:39 -05:00
let a = 'a';
let mut b = 'b';
2011-07-27 07:19:39 -05:00
let p: triple = {x: 65, y: 66, z: 67};
let mut q: triple = {x: 68, y: 69, z: 70};
y = id::<int>(x);
log(debug, y);
assert (x == y);
b = id::<char>(a);
log(debug, b);
assert (a == b);
q = id::<triple>(p);
x = p.z;
y = q.z;
log(debug, y);
assert (x == y);
}