]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/generic-fn.rs
auto merge of #19628 : jbranchaud/rust/add-string-as-string-doctest, r=steveklabnik
[rust.git] / src / test / run-pass / generic-fn.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 #![allow(dead_assignment)]
12
13 fn id<T>(x: T) -> T { return x; }
14
15 struct Triple {x: int, y: int, z: int}
16
17 impl Copy for Triple {}
18
19 pub fn main() {
20     let mut x = 62;
21     let mut y = 63;
22     let a = 'a';
23     let mut b = 'b';
24     let p: Triple = Triple {x: 65, y: 66, z: 67};
25     let mut q: Triple = Triple {x: 68, y: 69, z: 70};
26     y = id::<int>(x);
27     println!("{}", y);
28     assert_eq!(x, y);
29     b = id::<char>(a);
30     println!("{}", b);
31     assert_eq!(a, b);
32     q = id::<Triple>(p);
33     x = p.z;
34     y = q.z;
35     println!("{}", y);
36     assert_eq!(x, y);
37 }