File: pr-review-132289-1.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 (52 lines) | stat: -rw-r--r-- 1,106 bytes parent folder | download | duplicates (12)
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
45
46
47
48
49
50
51
52
// This is a regression test for issues that came up during review of the (closed)
// PR #132289; this single-crate test case is
// the first example from @steffahn during review.
// https://github.com/rust-lang/rust/pull/132289#issuecomment-2564492153

//@ check-pass

type A = &'static [usize; 1];
type B = &'static [usize; 100];

type DynSomething = dyn Something<Assoc = A>;

trait Super {
    type Assoc;
}
impl Super for Foo {
    type Assoc = A;
}

trait IsDynSomething {}
impl IsDynSomething for DynSomething {}

impl<T: ?Sized> Super for T
where
    T: IsDynSomething,
{
    type Assoc = B;
}

trait Something: Super {
    fn method(&self) -> Self::Assoc;
}

struct Foo;
impl Something for Foo {
    fn method(&self) -> Self::Assoc {
        &[1337]
    }
}

fn main() {
    let x = &Foo;
    let y: &DynSomething = x;

    // no surprises here
    let _arr1: A = x.method();

    // this (`_arr2`) can't ever become B either, soundly
    let _arr2: A = y.method();
    // there aren't any other arrays being defined anywhere in this
    // test case, besides the length-1 one containing [1337]
}