Show `const_err` lints
This commit is contained in:
parent
2022fac4df
commit
e56a86162c
|
@ -1,5 +1,5 @@
|
|||
// compile-flags: -Zunleash-the-miri-inside-of-you
|
||||
#![allow(const_err)]
|
||||
#![warn(const_err)]
|
||||
|
||||
#![feature(const_raw_ptr_deref)]
|
||||
|
||||
|
@ -14,19 +14,19 @@ const BOO: &usize = { //~ ERROR undefined behavior to use this value
|
|||
|
||||
const FOO: usize = {
|
||||
static FOO: AtomicUsize = AtomicUsize::new(0);
|
||||
FOO.fetch_add(1, Ordering::Relaxed) // FIXME: this should error
|
||||
FOO.fetch_add(1, Ordering::Relaxed) //~ WARN any use of this value will cause an error
|
||||
//~^ WARN skipping const checks
|
||||
//~| WARN skipping const checks
|
||||
};
|
||||
|
||||
const BAR: usize = {
|
||||
static FOO: AtomicUsize = AtomicUsize::new(0);
|
||||
unsafe { *(&FOO as *const _ as *const usize) } // FIXME: this should error
|
||||
unsafe { *(&FOO as *const _ as *const usize) } //~ WARN any use of this value will cause an err
|
||||
//~^ WARN skipping const checks
|
||||
};
|
||||
|
||||
static mut MUTABLE: u32 = 0;
|
||||
const BAD: u32 = unsafe { MUTABLE }; // FIXME: this should error
|
||||
const BAD: u32 = unsafe { MUTABLE }; //~ WARN any use of this value will cause an error
|
||||
//~^ WARN skipping const checks
|
||||
|
||||
// ok some day perhaps
|
||||
|
|
|
@ -7,25 +7,25 @@ LL | unsafe { &*(&FOO as *const _ as *const usize) }
|
|||
warning: skipping const checks
|
||||
--> $DIR/const_refers_to_static.rs:17:5
|
||||
|
|
||||
LL | FOO.fetch_add(1, Ordering::Relaxed) // FIXME: this should error
|
||||
LL | FOO.fetch_add(1, Ordering::Relaxed)
|
||||
| ^^^
|
||||
|
||||
warning: skipping const checks
|
||||
--> $DIR/const_refers_to_static.rs:17:5
|
||||
|
|
||||
LL | FOO.fetch_add(1, Ordering::Relaxed) // FIXME: this should error
|
||||
LL | FOO.fetch_add(1, Ordering::Relaxed)
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
warning: skipping const checks
|
||||
--> $DIR/const_refers_to_static.rs:24:17
|
||||
|
|
||||
LL | unsafe { *(&FOO as *const _ as *const usize) } // FIXME: this should error
|
||||
LL | unsafe { *(&FOO as *const _ as *const usize) }
|
||||
| ^^^
|
||||
|
||||
warning: skipping const checks
|
||||
--> $DIR/const_refers_to_static.rs:29:27
|
||||
|
|
||||
LL | const BAD: u32 = unsafe { MUTABLE }; // FIXME: this should error
|
||||
LL | const BAD: u32 = unsafe { MUTABLE };
|
||||
| ^^^^^^^
|
||||
|
||||
warning: skipping const checks
|
||||
|
@ -46,6 +46,43 @@ LL | | };
|
|||
|
|
||||
= 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.
|
||||
|
||||
warning: any use of this value will cause an error
|
||||
--> $DIR/const_refers_to_static.rs:17:5
|
||||
|
|
||||
LL | / const FOO: usize = {
|
||||
LL | | static FOO: AtomicUsize = AtomicUsize::new(0);
|
||||
LL | | FOO.fetch_add(1, Ordering::Relaxed)
|
||||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ calling non-const function `std::sync::atomic::AtomicUsize::fetch_add`
|
||||
LL | |
|
||||
LL | |
|
||||
LL | | };
|
||||
| |__-
|
||||
|
|
||||
note: lint level defined here
|
||||
--> $DIR/const_refers_to_static.rs:2:9
|
||||
|
|
||||
LL | #![warn(const_err)]
|
||||
| ^^^^^^^^^
|
||||
|
||||
warning: any use of this value will cause an error
|
||||
--> $DIR/const_refers_to_static.rs:24:14
|
||||
|
|
||||
LL | / const BAR: usize = {
|
||||
LL | | static FOO: AtomicUsize = AtomicUsize::new(0);
|
||||
LL | | unsafe { *(&FOO as *const _ as *const usize) }
|
||||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constant accesses static
|
||||
LL | |
|
||||
LL | | };
|
||||
| |__-
|
||||
|
||||
warning: any use of this value will cause an error
|
||||
--> $DIR/const_refers_to_static.rs:29:27
|
||||
|
|
||||
LL | const BAD: u32 = unsafe { MUTABLE };
|
||||
| --------------------------^^^^^^^---
|
||||
| |
|
||||
| constant accesses static
|
||||
|
||||
error[E0080]: it is undefined behavior to use this value
|
||||
--> $DIR/const_refers_to_static.rs:33:1
|
||||
|
|
||||
|
|
Loading…
Reference in New Issue