]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/close-over-big-then-small-data.rs
libsyntax: Allow `+` to separate trait bounds from objects.
[rust.git] / src / test / run-pass / close-over-big-then-small-data.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 // If we use GEPi rathern than GEP_tup_like when
12 // storing closure data (as we used to do), the u64 would
13 // overwrite the u16.
14
15 extern crate debug;
16
17 struct Pair<A,B> {
18     a: A, b: B
19 }
20
21 struct Invoker<A> {
22     a: A,
23     b: u16,
24 }
25
26 trait Invokable<A> {
27     fn f(&self) -> (A, u16);
28 }
29
30 impl<A:Clone> Invokable<A> for Invoker<A> {
31     fn f(&self) -> (A, u16) {
32         (self.a.clone(), self.b)
33     }
34 }
35
36 fn f<A:Clone + 'static>(a: A, b: u16) -> Box<Invokable<A>+> {
37     box Invoker {
38         a: a,
39         b: b,
40     } as (Box<Invokable<A>>+)
41 }
42
43 pub fn main() {
44     let (a, b) = f(22_u64, 44u16).f();
45     println!("a={:?} b={:?}", a, b);
46     assert_eq!(a, 22u64);
47     assert_eq!(b, 44u16);
48 }