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
29 //~| WARN this was previously accepted by the compiler but is being phased out
32 #[warn(const_err)] //~ NOTE
33 const U8_MUT3
: &u8 = { //~ NOTE
34 unsafe { match static_cross_crate::OPT_ZERO { Some(ref u) => u, None => panic!() }
}
36 //~| NOTE constant accesses static
37 //~| NOTE in this expansion of panic!
38 //~| WARN this was previously accepted by the compiler but is being phased out
42 pub fn test(x
: &[u8; 1]) -> bool
{
45 //~^ ERROR could not evaluate constant pattern
46 //~| ERROR could not evaluate constant pattern
51 pub fn test2(x
: &u8) -> bool
{
54 //~^ ERROR could not evaluate constant pattern
55 //~| ERROR could not evaluate constant pattern
60 // We need to use these *in a pattern* to trigger the failure... likely because
61 // the errors above otherwise stop compilation too early?
62 pub fn test3(x
: &u8) -> bool
{
65 //~^ ERROR could not evaluate constant pattern
66 //~| ERROR could not evaluate constant pattern
70 pub fn test4(x
: &u8) -> bool
{
73 //~^ ERROR could not evaluate constant pattern
74 //~| ERROR could not evaluate constant pattern
81 static_cross_crate
::ZERO
[0] = 1;
83 // Now the pattern is not exhaustive any more!