File: can-reveal-opaques.rs

package info (click to toggle)
rustc 1.85.0%2Bdfsg3-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental, forky, sid, trixie
  • size: 893,396 kB
  • sloc: xml: 158,127; python: 35,830; javascript: 19,497; cpp: 19,002; sh: 17,245; ansic: 13,127; asm: 4,376; makefile: 1,051; perl: 29; lisp: 29; ruby: 19; sql: 11
file content (44 lines) | stat: -rw-r--r-- 1,455 bytes parent folder | download | duplicates (6)
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//@ needs-sanitizer-cfi
//@ compile-flags: -Ccodegen-units=1 -Clto -Ctarget-feature=-crt-static -Zsanitizer=cfi
//@ no-prefer-dynamic
//@ only-x86_64-unknown-linux-gnu
//@ build-pass

// See comment below for why this test exists.

trait Tr<U> {
    type Projection;
}

impl<F, U> Tr<U> for F
where
    F: Fn() -> U
{
    type Projection = U;
}

fn test<B: Tr<U>, U>(b: B) -> B::Projection
{
    todo!()
}

fn main() {
    fn rpit_fn() -> impl Sized {}

    // When CFI runs, it tries to compute the signature of the call. This
    // ends up giving us a signature of:
    //     `fn test::<rpit_fn, ()>() -> <rpit_fn as Tr<()>>::Projection`,
    // where `rpit_fn` is the ZST FnDef for the function. However, we were
    // previously using a Reveal::UserFacing param-env. This means that the
    // `<rpit_fn as Tr<()>>::Projection` return type is impossible to normalize,
    // since it would require proving `rpit_fn: Fn() -> ()`, but we cannot
    // prove that the `impl Sized` opaque is `()` with a user-facing param-env.
    // This leads to a normalization error, and then an ICE.
    //
    // Side-note:
    // So why is the second generic of `test` "`()`", and not the
    // `impl Sized` since we inferred it from the return type of `rpit_fn`
    // during typeck? Well, that's because we're using the generics from the
    // terminator of the MIR, which has had the PostAnalysisNormalize pass performed on it.
    let _ = test(rpit_fn);
}