]> git.lizzy.rs Git - rust.git/blob - src/test/ui/polymorphization/closure_in_upvar/fnonce.rs
Auto merge of #75137 - Aaron1011:fix/hygiene-skip-expndata, r=petrochenkov
[rust.git] / src / test / ui / polymorphization / closure_in_upvar / fnonce.rs
1 // build-pass
2 // compile-flags:-Zpolymorphize=on -Zsymbol-mangling-version=v0
3
4 fn foo(f: impl Fn()) {
5     // Move a non-copy type into `x` so that it implements `FnOnce`.
6     let outer = Vec::<u32>::new();
7     let x = move |_: ()| {
8         let inner = outer;
9         ()
10     };
11
12     // Don't use `f` in `y`, but refer to `x` so that the closure substs contain a reference to
13     // `x` that will differ for each instantiation despite polymorphisation of the varying
14     // argument.
15     let y = || x(());
16
17     // Consider `f` used in `foo`.
18     f();
19     // Use `y` so that it is visited in monomorphisation collection.
20     y();
21 }
22
23 fn entry_a() {
24     foo(|| ());
25 }
26
27 fn entry_b() {
28     foo(|| ());
29 }
30
31 fn main() {
32     entry_a();
33     entry_b();
34 }