1 // compile-flags: -Zunleash-the-miri-inside-of-you
2 // aux-build:static_cross_crate.rs
6 #![feature(exclusive_range_pattern, half_open_range_patterns)]
8 extern crate static_cross_crate;
10 // Sneaky: reference to a mutable static.
11 // Allowing this would be a disaster for pattern matching, we could violate exhaustiveness checking!
12 const SLICE_MUT: &[u8; 1] = { //~ ERROR undefined behavior to use this value
13 //~| encountered a reference pointing to a static variable
14 unsafe { &static_cross_crate::ZERO }
17 const U8_MUT: &u8 = { //~ ERROR undefined behavior to use this value
18 //~| encountered a reference pointing to a static variable
19 unsafe { &static_cross_crate::ZERO[0] }
22 // Also test indirection that reads from other static. This causes a const_err.
24 const U8_MUT2: &u8 = {
25 unsafe { &(*static_cross_crate::ZERO_REF)[0] }
27 //~| constant accesses static
28 //~| WARN this was previously accepted by the compiler but is being phased out
31 const U8_MUT3: &u8 = {
32 unsafe { match static_cross_crate::OPT_ZERO { Some(ref u) => u, None => panic!() } }
34 //~| constant accesses static
35 //~| WARN this was previously accepted by the compiler but is being phased out
38 pub fn test(x: &[u8; 1]) -> bool {
41 //~^ ERROR could not evaluate constant pattern
42 //~| ERROR could not evaluate constant pattern
47 pub fn test2(x: &u8) -> bool {
50 //~^ ERROR could not evaluate constant pattern
51 //~| ERROR could not evaluate constant pattern
56 // We need to use these *in a pattern* to trigger the failure... likely because
57 // the errors above otherwise stop compilation too early?
58 pub fn test3(x: &u8) -> bool {
61 //~^ ERROR could not evaluate constant pattern
62 //~| ERROR could not evaluate constant pattern
66 pub fn test4(x: &u8) -> bool {
69 //~^ ERROR could not evaluate constant pattern
70 //~| ERROR could not evaluate constant pattern
77 static_cross_crate::ZERO[0] = 1;
79 // Now the pattern is not exhaustive any more!