]> git.lizzy.rs Git - rust.git/blob - tests/ui/close-over-big-then-small-data.rs
Rollup merge of #107615 - notriddle:notriddle/nbsp, r=GuillaumeGomez
[rust.git] / tests / 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 struct Pair<A,B> {
9     a: A, b: B
10 }
11
12 struct Invoker<A> {
13     a: A,
14     b: u16,
15 }
16
17 trait Invokable<A> {
18     fn f(&self) -> (A, u16);
19 }
20
21 impl<A:Clone> Invokable<A> for Invoker<A> {
22     fn f(&self) -> (A, u16) {
23         (self.a.clone(), self.b)
24     }
25 }
26
27 fn f<A:Clone + 'static>(a: A, b: u16) -> Box<dyn Invokable<A>+'static> {
28     Box::new(Invoker {
29         a: a,
30         b: b,
31     }) as Box<dyn Invokable<A>+'static>
32 }
33
34 pub fn main() {
35     let (a, b) = f(22_u64, 44u16).f();
36     println!("a={} b={}", a, b);
37     assert_eq!(a, 22u64);
38     assert_eq!(b, 44u16);
39 }