File: fn.rs

package info (click to toggle)
rustc-web 1.78.0%2Bdfsg1-2~deb11u3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,245,360 kB
  • sloc: xml: 147,985; javascript: 18,022; sh: 11,083; python: 10,265; ansic: 6,172; cpp: 5,023; asm: 4,390; makefile: 4,269
file content (29 lines) | stat: -rw-r--r-- 593 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
//@ build-pass
//@ compile-flags:-Zpolymorphize=on -Csymbol-mangling-version=v0

fn foo(f: impl Fn()) {
    let x = |_: ()| ();

    // Don't use `f` in `y`, but refer to `x` so that the closure substs contain a reference to
    // `x` that will differ for each instantiation despite polymorphisation of the varying
    // argument.
    let y = || x(());

    // Consider `f` used in `foo`.
    f();
    // Use `y` so that it is visited in monomorphisation collection.
    y();
}

fn entry_a() {
    foo(|| ());
}

fn entry_b() {
    foo(|| ());
}

fn main() {
    entry_a();
    entry_b();
}