Skip to content

Commit 979bbf2

Browse files
committed
also test reference into static field
1 parent a089801 commit 979bbf2

File tree

2 files changed

+40
-15
lines changed

2 files changed

+40
-15
lines changed

src/test/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.rs

+16-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// compile-flags: -Zunleash-the-miri-inside-of-you
1+
// compile-flags: -Zunleash-the-miri-inside-of-you -Zdeduplicate-diagnostics
22
// aux-build:static_cross_crate.rs
33
#![allow(const_err)]
44

@@ -14,18 +14,31 @@ const SLICE_MUT: &[u8; 1] = { //~ ERROR undefined behavior to use this value
1414
//~| NOTE
1515
unsafe { &static_cross_crate::ZERO }
1616
//~^ WARN skipping const checks
17-
//~| WARN skipping const checks
17+
};
18+
19+
const SLICE_MUT2: &u8 = { //~ ERROR undefined behavior to use this value
20+
//~| NOTE encountered a reference pointing to a static variable
21+
//~| NOTE
22+
unsafe { &static_cross_crate::ZERO[0] }
23+
//~^ WARN skipping const checks
1824
};
1925

2026
pub fn test(x: &[u8; 1]) -> bool {
2127
match x {
2228
SLICE_MUT => true,
2329
//~^ ERROR could not evaluate constant pattern
24-
//~| ERROR could not evaluate constant pattern
2530
&[1..] => false,
2631
}
2732
}
2833

34+
pub fn test2(x: &u8) -> bool {
35+
match x {
36+
SLICE_MUT2 => true,
37+
//~^ ERROR could not evaluate constant pattern
38+
&(1..) => false,
39+
}
40+
}
41+
2942
fn main() {
3043
unsafe {
3144
static_cross_crate::ZERO[0] = 1;

src/test/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.stderr

+24-12
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,6 @@ warning: skipping const checks
44
LL | unsafe { &static_cross_crate::ZERO }
55
| ^^^^^^^^^^^^^^^^^^^^^^^^
66

7-
warning: skipping const checks
8-
--> $DIR/const_refers_to_static_cross_crate.rs:15:15
9-
|
10-
LL | unsafe { &static_cross_crate::ZERO }
11-
| ^^^^^^^^^^^^^^^^^^^^^^^^
12-
137
error[E0080]: it is undefined behavior to use this value
148
--> $DIR/const_refers_to_static_cross_crate.rs:12:1
159
|
@@ -18,24 +12,42 @@ LL | |
1812
LL | |
1913
LL | | unsafe { &static_cross_crate::ZERO }
2014
LL | |
21-
LL | |
2215
LL | | };
2316
| |__^ type validation failed: encountered a reference pointing to a static variable
2417
|
2518
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
2619

2720
error: could not evaluate constant pattern
28-
--> $DIR/const_refers_to_static_cross_crate.rs:22:9
21+
--> $DIR/const_refers_to_static_cross_crate.rs:28:9
2922
|
3023
LL | SLICE_MUT => true,
3124
| ^^^^^^^^^
3225

26+
warning: skipping const checks
27+
--> $DIR/const_refers_to_static_cross_crate.rs:22:15
28+
|
29+
LL | unsafe { &static_cross_crate::ZERO[0] }
30+
| ^^^^^^^^^^^^^^^^^^^^^^^^
31+
32+
error[E0080]: it is undefined behavior to use this value
33+
--> $DIR/const_refers_to_static_cross_crate.rs:19:1
34+
|
35+
LL | / const SLICE_MUT2: &u8 = {
36+
LL | |
37+
LL | |
38+
LL | | unsafe { &static_cross_crate::ZERO[0] }
39+
LL | |
40+
LL | | };
41+
| |__^ type validation failed: encountered a reference pointing to a static variable
42+
|
43+
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
44+
3345
error: could not evaluate constant pattern
34-
--> $DIR/const_refers_to_static_cross_crate.rs:22:9
46+
--> $DIR/const_refers_to_static_cross_crate.rs:36:9
3547
|
36-
LL | SLICE_MUT => true,
37-
| ^^^^^^^^^
48+
LL | SLICE_MUT2 => true,
49+
| ^^^^^^^^^^
3850

39-
error: aborting due to 3 previous errors; 2 warnings emitted
51+
error: aborting due to 4 previous errors; 2 warnings emitted
4052

4153
For more information about this error, try `rustc --explain E0080`.

0 commit comments

Comments
 (0)