]> git.lizzy.rs Git - rust.git/blob - src/test/ui/unboxed-closures/unboxed-closures-monomorphization.rs
Rollup merge of #95376 - WaffleLapkin:drain_keep_rest, r=dtolnay
[rust.git] / src / test / ui / unboxed-closures / unboxed-closures-monomorphization.rs
1 // run-pass
2 // Test that unboxed closures in contexts with free type parameters
3 // monomorphize correctly (issue #16791)
4
5 fn main(){
6     fn bar<'a, T:Clone+'a> (t: T) -> Box<dyn FnMut()->T + 'a> {
7         Box::new(move || t.clone())
8     }
9
10     let mut f = bar(42_u32);
11     assert_eq!(f(), 42);
12
13     let mut f = bar("forty-two");
14     assert_eq!(f(), "forty-two");
15
16     let x = 42_u32;
17     let mut f = bar(&x);
18     assert_eq!(f(), &x);
19
20     #[derive(Clone, Copy, Debug, PartialEq)]
21     struct Foo(usize, &'static str);
22
23     let x = Foo(42, "forty-two");
24     let mut f = bar(x);
25     assert_eq!(f(), x);
26 }