• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // check-pass
2 
3 #![allow(dead_code, incomplete_features)]
4 #![feature(generic_const_exprs)]
5 
min(a: usize, b: usize) -> usize6 const fn min(a: usize, b: usize) -> usize {
7     if a < b {
8         a
9     } else {
10         b
11     }
12 }
13 
14 trait Trait1<Inner1>
15 where
16     Self: Sized,
17 {
crash_here() where Inner1: Default,18     fn crash_here()
19     where
20         Inner1: Default,
21     {
22         Inner1::default();
23     }
24 }
25 
26 struct Struct1<T>(T);
27 impl<T> Trait1<T> for Struct1<T> {}
28 
29 trait Trait2<Inner2>
30 where
31     Self: Sized,
32 {
33     type Assoc: Trait1<Inner2>;
34 
call_crash() where Inner2: Default,35     fn call_crash()
36     where
37         Inner2: Default,
38     {
39         // if Inner2 implements Default, we can call crash_here.
40         Self::Assoc::crash_here();
41     }
42 }
43 
44 struct Struct2<const SIZE1: usize, const SIZE2: usize> {}
45 /*
46 where
47     [(); min(SIZE1, SIZE2)]:,
48 {
49     elem: [i32; min(SIZE1, SIZE2)],
50 }
51 */
52 
53 impl<const SIZE1: usize, const SIZE2: usize> Trait2<[i32; min(SIZE1, SIZE2)]>
54     for Struct2<SIZE1, SIZE2>
55 {
56     type Assoc = Struct1<[i32; min(SIZE1, SIZE2)]>;
57     // dose Struct1<[i32; min(SIZE1, SIZE2)]> implement Default?
58 }
59 
main()60 fn main() {
61     pattern2();
62 
63     print_fully_name(<Struct2<1, 2> as Trait2<[i32; min(1, 2)]>>::Assoc::crash_here);
64     // <compiler_bug2::Struct1<[i32; 1]> as compiler_bug2::Trait1<[i32; 1]>>::crash_here
65 }
66 
pattern1()67 fn pattern1() {
68     // no crash
69     <Struct2<1, 2> as Trait2<[i32; min(1, 2)]>>::Assoc::crash_here();
70     <Struct2<1, 2> as Trait2<[i32; min(1, 2)]>>::call_crash();
71 }
72 
pattern2()73 fn pattern2() {
74     // crash
75     <Struct2<1, 2> as Trait2<[i32; min(1, 2)]>>::call_crash();
76 
77     // undefined reference to `compiler_bug2::Trait1::crash_here'
78 }
79 
pattern3()80 fn pattern3() {
81     // no crash
82     <Struct2<1, 2> as Trait2<[i32; min(1, 2)]>>::Assoc::crash_here();
83 }
84 
print_fully_name<T>(_: T)85 fn print_fully_name<T>(_: T) {
86     let _ = std::any::type_name::<T>();
87 }
88