]> git.lizzy.rs Git - rust.git/blob - src/test/ui/close-over-big-then-small-data.rs
Auto merge of #81507 - weiznich:add_diesel_to_cargo_test, r=Mark-Simulacrum
[rust.git] / src / test / ui / close-over-big-then-small-data.rs
1 // run-pass
2
3 #![allow(dead_code)]
4 // If we use GEPi rather than GEP_tup_like when
5 // storing closure data (as we used to do), the u64 would
6 // overwrite the u16.
7
8 #![feature(box_syntax)]
9
10 struct Pair<A,B> {
11     a: A, b: B
12 }
13
14 struct Invoker<A> {
15     a: A,
16     b: u16,
17 }
18
19 trait Invokable<A> {
20     fn f(&self) -> (A, u16);
21 }
22
23 impl<A:Clone> Invokable<A> for Invoker<A> {
24     fn f(&self) -> (A, u16) {
25         (self.a.clone(), self.b)
26     }
27 }
28
29 fn f<A:Clone + 'static>(a: A, b: u16) -> Box<dyn Invokable<A>+'static> {
30     box Invoker {
31         a: a,
32         b: b,
33     } as Box<dyn Invokable<A>+'static>
34 }
35
36 pub fn main() {
37     let (a, b) = f(22_u64, 44u16).f();
38     println!("a={} b={}", a, b);
39     assert_eq!(a, 22u64);
40     assert_eq!(b, 44u16);
41 }