File: copy-check-deferred-after-fallback.rs

package info (click to toggle)
rustc 1.88.0%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 934,128 kB
  • sloc: xml: 158,127; python: 36,062; javascript: 19,855; sh: 19,700; cpp: 18,947; ansic: 12,993; asm: 4,792; makefile: 690; lisp: 29; perl: 29; ruby: 19; sql: 11
file content (37 lines) | stat: -rw-r--r-- 1,193 bytes parent folder | download | duplicates (5)
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
#![feature(generic_arg_infer)]

// Test that would start passing if we defer repeat expr copy checks to end of
// typechecking and they're checked after integer fallback occurs. We accomplish
// this by contriving a situation where integer fallback allows progress to be
// made on a trait goal that infers the length of a repeat expr.

use std::marker::PhantomData;

struct NotCopy;

trait Trait<const N: usize> {}

impl Trait<2> for u32 {}
impl Trait<1> for i32 {}

fn make_goal<T: Trait<N>, const N: usize>(_: &T, _: [NotCopy; N]) {}

fn main() {
    let a = 1;
    let b = [NotCopy; _];
    //~^ ERROR: type annotations needed

    // a is of type `?y`
    // b is of type `[NotCopy; ?x]`
    // there is a goal ?y: Trait<?x>` with two candidates:
    // - `i32: Trait<1>`, ?y=i32 ?x=1 which doesnt require `NotCopy: Copy`
    // - `u32: Trait<2>` ?y=u32 ?x=2 which requires `NotCopy: Copy`
    make_goal(&a, b);

    // final repeat expr checks:
    //
    // `NotCopy; ?x`
    // - succeeds if fallback happens before repeat exprs as `i32: Trait<?x>` infers `?x=1`
    // - fails if repeat expr checks happen first as `?x` is unconstrained so cannot be
    //    structurally resolved
}