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