Skip to content

Commit e56a861

Browse files
committed
Show const_err lints
1 parent 2022fac commit e56a861

File tree

2 files changed

+45
-8
lines changed

2 files changed

+45
-8
lines changed

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// compile-flags: -Zunleash-the-miri-inside-of-you
2-
#![allow(const_err)]
2+
#![warn(const_err)]
33

44
#![feature(const_raw_ptr_deref)]
55

@@ -14,19 +14,19 @@ const BOO: &usize = { //~ ERROR undefined behavior to use this value
1414

1515
const FOO: usize = {
1616
static FOO: AtomicUsize = AtomicUsize::new(0);
17-
FOO.fetch_add(1, Ordering::Relaxed) // FIXME: this should error
17+
FOO.fetch_add(1, Ordering::Relaxed) //~ WARN any use of this value will cause an error
1818
//~^ WARN skipping const checks
1919
//~| WARN skipping const checks
2020
};
2121

2222
const BAR: usize = {
2323
static FOO: AtomicUsize = AtomicUsize::new(0);
24-
unsafe { *(&FOO as *const _ as *const usize) } // FIXME: this should error
24+
unsafe { *(&FOO as *const _ as *const usize) } //~ WARN any use of this value will cause an err
2525
//~^ WARN skipping const checks
2626
};
2727

2828
static mut MUTABLE: u32 = 0;
29-
const BAD: u32 = unsafe { MUTABLE }; // FIXME: this should error
29+
const BAD: u32 = unsafe { MUTABLE }; //~ WARN any use of this value will cause an error
3030
//~^ WARN skipping const checks
3131

3232
// ok some day perhaps

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

+41-4
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,25 @@ LL | unsafe { &*(&FOO as *const _ as *const usize) }
77
warning: skipping const checks
88
--> $DIR/const_refers_to_static.rs:17:5
99
|
10-
LL | FOO.fetch_add(1, Ordering::Relaxed) // FIXME: this should error
10+
LL | FOO.fetch_add(1, Ordering::Relaxed)
1111
| ^^^
1212

1313
warning: skipping const checks
1414
--> $DIR/const_refers_to_static.rs:17:5
1515
|
16-
LL | FOO.fetch_add(1, Ordering::Relaxed) // FIXME: this should error
16+
LL | FOO.fetch_add(1, Ordering::Relaxed)
1717
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1818

1919
warning: skipping const checks
2020
--> $DIR/const_refers_to_static.rs:24:17
2121
|
22-
LL | unsafe { *(&FOO as *const _ as *const usize) } // FIXME: this should error
22+
LL | unsafe { *(&FOO as *const _ as *const usize) }
2323
| ^^^
2424

2525
warning: skipping const checks
2626
--> $DIR/const_refers_to_static.rs:29:27
2727
|
28-
LL | const BAD: u32 = unsafe { MUTABLE }; // FIXME: this should error
28+
LL | const BAD: u32 = unsafe { MUTABLE };
2929
| ^^^^^^^
3030

3131
warning: skipping const checks
@@ -46,6 +46,43 @@ LL | | };
4646
|
4747
= 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.
4848

49+
warning: any use of this value will cause an error
50+
--> $DIR/const_refers_to_static.rs:17:5
51+
|
52+
LL | / const FOO: usize = {
53+
LL | | static FOO: AtomicUsize = AtomicUsize::new(0);
54+
LL | | FOO.fetch_add(1, Ordering::Relaxed)
55+
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ calling non-const function `std::sync::atomic::AtomicUsize::fetch_add`
56+
LL | |
57+
LL | |
58+
LL | | };
59+
| |__-
60+
|
61+
note: lint level defined here
62+
--> $DIR/const_refers_to_static.rs:2:9
63+
|
64+
LL | #![warn(const_err)]
65+
| ^^^^^^^^^
66+
67+
warning: any use of this value will cause an error
68+
--> $DIR/const_refers_to_static.rs:24:14
69+
|
70+
LL | / const BAR: usize = {
71+
LL | | static FOO: AtomicUsize = AtomicUsize::new(0);
72+
LL | | unsafe { *(&FOO as *const _ as *const usize) }
73+
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constant accesses static
74+
LL | |
75+
LL | | };
76+
| |__-
77+
78+
warning: any use of this value will cause an error
79+
--> $DIR/const_refers_to_static.rs:29:27
80+
|
81+
LL | const BAD: u32 = unsafe { MUTABLE };
82+
| --------------------------^^^^^^^---
83+
| |
84+
| constant accesses static
85+
4986
error[E0080]: it is undefined behavior to use this value
5087
--> $DIR/const_refers_to_static.rs:33:1
5188
|

0 commit comments

Comments
 (0)