From e56a86162ceeb285c48132a103a6559f4d406ba7 Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Sun, 22 Dec 2019 21:42:50 +0100 Subject: [PATCH] Show `const_err` lints --- .../miri_unleashed/const_refers_to_static.rs | 8 ++-- .../const_refers_to_static.stderr | 45 +++++++++++++++++-- 2 files changed, 45 insertions(+), 8 deletions(-) diff --git a/src/test/ui/consts/miri_unleashed/const_refers_to_static.rs b/src/test/ui/consts/miri_unleashed/const_refers_to_static.rs index 58eac59ba384..55f3f1c84885 100644 --- a/src/test/ui/consts/miri_unleashed/const_refers_to_static.rs +++ b/src/test/ui/consts/miri_unleashed/const_refers_to_static.rs @@ -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 diff --git a/src/test/ui/consts/miri_unleashed/const_refers_to_static.stderr b/src/test/ui/consts/miri_unleashed/const_refers_to_static.stderr index 7a8c9d44e5a0..6ae88558d700 100644 --- a/src/test/ui/consts/miri_unleashed/const_refers_to_static.stderr +++ b/src/test/ui/consts/miri_unleashed/const_refers_to_static.stderr @@ -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 |