]> git.lizzy.rs Git - rust.git/blob - src/test/ui/consts/miri_unleashed/assoc_const.rs
Rollup merge of #64603 - gilescope:unused-lifetime-warning, r=matthewjasper
[rust.git] / src / test / ui / consts / miri_unleashed / assoc_const.rs
1 // compile-flags: -Zunleash-the-miri-inside-of-you
2 #![allow(const_err)]
3
4 // a test demonstrating why we do need to run static const qualification on associated constants
5 // instead of just checking the final constant
6
7 trait Foo<T> {
8     const X: T;
9 }
10
11 trait Bar<T, U: Foo<T>> {
12     const F: u32 = (U::X, 42).1; //~ WARN skipping const checks
13 }
14
15 impl Foo<u32> for () {
16     const X: u32 = 42;
17 }
18 impl Foo<Vec<u32>> for String {
19     const X: Vec<u32> = Vec::new();
20 }
21
22 impl Bar<u32, ()> for () {}
23 impl Bar<Vec<u32>, String> for String {}
24
25 fn main() {
26     // this is fine, but would have been forbidden by the static checks on `F`
27     let x = <() as Bar<u32, ()>>::F;
28     // this test only causes errors due to the line below, so post-monomorphization
29     let y = <String as Bar<Vec<u32>, String>>::F; //~ ERROR erroneous constant
30 }