1 // compile-flags: -Zunleash-the-miri-inside-of-you
2 // aux-build:static_cross_crate.rs
5 #![feature(exclusive_range_pattern, half_open_range_patterns)]
7 extern crate static_cross_crate
;
9 // Sneaky: reference to a mutable static.
10 // Allowing this would be a disaster for pattern matching, we could violate exhaustiveness checking!
11 const SLICE_MUT
: &[u8; 1] = { //~ ERROR undefined behavior to use this value
12 //~| NOTE 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 //~| NOTE encountered a reference pointing to a static variable
20 unsafe { &static_cross_crate::ZERO[0] }
23 // Also test indirection that reads from other static. This causes a const_err.
24 #[warn(const_err)] //~ NOTE
25 const U8_MUT2
: &u8 = { //~ NOTE
26 unsafe { &(*static_cross_crate::ZERO_REF)[0] }
28 //~| NOTE constant accesses static
30 #[warn(const_err)] //~ NOTE
31 const U8_MUT3
: &u8 = { //~ NOTE
32 unsafe { match static_cross_crate::OPT_ZERO { Some(ref u) => u, None => panic!() }
}
34 //~| NOTE constant accesses static
37 pub fn test(x
: &[u8; 1]) -> bool
{
40 //~^ ERROR could not evaluate constant pattern
41 //~| ERROR could not evaluate constant pattern
46 pub fn test2(x
: &u8) -> bool
{
49 //~^ ERROR could not evaluate constant pattern
50 //~| ERROR could not evaluate constant pattern
55 // We need to use these *in a pattern* to trigger the failure... likely because
56 // the errors above otherwise stop compilation too early?
57 pub fn test3(x
: &u8) -> bool
{
60 //~^ ERROR could not evaluate constant pattern
61 //~| ERROR could not evaluate constant pattern
65 pub fn test4(x
: &u8) -> bool
{
68 //~^ ERROR could not evaluate constant pattern
69 //~| ERROR could not evaluate constant pattern
76 static_cross_crate
::ZERO
[0] = 1;
78 // Now the pattern is not exhaustive any more!