1
Fork 0

warn about each skipped feature gate

This commit is contained in:
Ralf Jung 2020-05-03 14:23:08 +02:00
parent 89666ab6b4
commit 99debecd4d
38 changed files with 350 additions and 352 deletions

View file

@ -253,13 +253,7 @@ impl Validator<'mir, 'tcx> {
let is_unleashable = O::IS_SUPPORTED_IN_MIRI; let is_unleashable = O::IS_SUPPORTED_IN_MIRI;
if is_unleashable && self.tcx.sess.opts.debugging_opts.unleash_the_miri_inside_of_you { if is_unleashable && self.tcx.sess.opts.debugging_opts.unleash_the_miri_inside_of_you {
// Use `def_span` to deduplicate all warnings for the same const. self.tcx.sess.miri_unleashed_feature(span, O::feature_gate());
self.tcx.sess.span_warn(self.tcx.def_span(self.def_id), "skipping const checks");
if let Some(feature) = O::feature_gate() {
// We'd like to use `delay_span_bug` here, but we cannot as that ICEs
// before codegen has the chance to emit errors. So we use a custom system instead.
self.tcx.sess.miri_unleashed_feature(feature);
}
return; return;
} }

View file

@ -27,7 +27,6 @@ use rustc_target::spec::{PanicStrategy, RelocModel, RelroLevel, Target, TargetTr
use std::cell::{self, RefCell}; use std::cell::{self, RefCell};
use std::env; use std::env;
use std::fmt::Write as _;
use std::io::Write; use std::io::Write;
use std::num::NonZeroU32; use std::num::NonZeroU32;
use std::path::PathBuf; use std::path::PathBuf;
@ -144,9 +143,11 @@ pub struct Session {
/// and immediately printing the backtrace to stderr. /// and immediately printing the backtrace to stderr.
pub ctfe_backtrace: Lock<CtfeBacktrace>, pub ctfe_backtrace: Lock<CtfeBacktrace>,
/// This tracks whether `-Zunleash-the-miri-inside-of-you` was used to get around a /// This tracks where `-Zunleash-the-miri-inside-of-you` was used to get around a
/// feature gate. If yes, this file must fail to compile. /// const check, optionally with the relevant feature gate. We use this to
miri_unleashed_features: Lock<FxHashSet<Symbol>>, /// warn about unleashing, but with a single diagnostic instead of dozens that
/// drown everything else in noise.
miri_unleashed_features: Lock<Vec<(Span, Option<Symbol>)>>,
/// Base directory containing the `src/` for the Rust standard library, and /// Base directory containing the `src/` for the Rust standard library, and
/// potentially `rustc` as well, if we can can find it. Right now it's always /// potentially `rustc` as well, if we can can find it. Right now it's always
@ -195,29 +196,34 @@ impl From<&'static lint::Lint> for DiagnosticMessageId {
} }
impl Session { impl Session {
pub fn miri_unleashed_feature(&self, s: Symbol) { pub fn miri_unleashed_feature(&self, span: Span, feature_gate: Option<Symbol>) {
self.miri_unleashed_features.lock().insert(s); self.miri_unleashed_features.lock().push((span, feature_gate));
} }
fn check_miri_unleashed_features(&self) { fn check_miri_unleashed_features(&self) {
if !self.has_errors_or_delayed_span_bugs() { let unleashed_features = self.miri_unleashed_features.lock();
let unleashed_features = self.miri_unleashed_features.lock(); if !unleashed_features.is_empty() {
if !unleashed_features.is_empty() { let mut must_err = false;
// Join the strings (itertools has it but libstd does not...) // Create a diagnostic pointing at where things got unleashed.
let mut list = String::new(); let mut diag = self.struct_warn("skipping const checks");
for feature in unleashed_features.iter() { for &(span, feature_gate) in unleashed_features.iter() {
if !list.is_empty() { // FIXME: `span_label` doesn't do anything, so we use "help" as a hack.
list.push_str(", "); if let Some(feature_gate) = feature_gate {
} diag.span_help(span, &format!("skipping check for `{}` feature", feature_gate));
write!(&mut list, "{}", feature).unwrap(); // The unleash flag must *not* be used to just "hack around" feature gates.
must_err = true;
} else {
diag.span_help(span, "skipping check that does not even have a feature gate");
} }
}
diag.emit();
// If we should err, make sure we did.
if must_err && !self.has_errors() {
// We have skipped a feature gate, and not run into other errors... reject. // We have skipped a feature gate, and not run into other errors... reject.
self.err(&format!( self.err(
"`-Zunleash-the-miri-inside-of-you` may not be used to circumvent feature \ "`-Zunleash-the-miri-inside-of-you` may not be used to circumvent feature \
gates, except when testing error paths in the CTFE engine.\n\ gates, except when testing error paths in the CTFE engine"
The following feature flags are missing from this crate: {}", );
list,
));
} }
} }
} }

View file

@ -8,15 +8,15 @@ const fn double_const(x: usize) -> usize { x * 2 }
const X: fn(usize) -> usize = double; const X: fn(usize) -> usize = double;
const X_CONST: fn(usize) -> usize = double_const; const X_CONST: fn(usize) -> usize = double_const;
const fn bar(x: usize) -> usize { //~ WARNING skipping const checks const fn bar(x: usize) -> usize {
X(x) X(x)
} }
const fn bar_const(x: usize) -> usize { //~ WARNING skipping const checks const fn bar_const(x: usize) -> usize {
X_CONST(x) X_CONST(x)
} }
const fn foo(x: fn(usize) -> usize, y: usize) -> usize { //~ WARNING skipping const checks const fn foo(x: fn(usize) -> usize, y: usize) -> usize {
x(y) x(y)
} }

View file

@ -1,26 +1,20 @@
warning: skipping const checks warning: skipping const checks
--> $DIR/const_fn_ptr.rs:11:1
| |
LL | / const fn bar(x: usize) -> usize { help: skipping check that does not even have a feature gate
LL | | X(x) --> $DIR/const_fn_ptr.rs:12:5
LL | | }
| |_^
warning: skipping const checks
--> $DIR/const_fn_ptr.rs:15:1
| |
LL | / const fn bar_const(x: usize) -> usize { LL | X(x)
LL | | X_CONST(x) | ^^^^
LL | | } help: skipping check that does not even have a feature gate
| |_^ --> $DIR/const_fn_ptr.rs:16:5
warning: skipping const checks
--> $DIR/const_fn_ptr.rs:19:1
| |
LL | / const fn foo(x: fn(usize) -> usize, y: usize) -> usize { LL | X_CONST(x)
LL | | x(y) | ^^^^^^^^^^
LL | | } help: skipping check that does not even have a feature gate
| |_^ --> $DIR/const_fn_ptr.rs:20:5
|
LL | x(y)
| ^^^^
warning: 3 warnings emitted warning: 1 warning emitted

View file

@ -6,7 +6,7 @@
fn double(x: usize) -> usize { x * 2 } fn double(x: usize) -> usize { x * 2 }
const X: fn(usize) -> usize = double; const X: fn(usize) -> usize = double;
const fn bar(x: usize) -> usize { //~ WARNING skipping const checks const fn bar(x: usize) -> usize {
X(x) // FIXME: this should error someday X(x) // FIXME: this should error someday
} }

View file

@ -1,10 +1,10 @@
warning: skipping const checks warning: skipping const checks
--> $DIR/const_fn_ptr_fail.rs:9:1
| |
LL | / const fn bar(x: usize) -> usize { help: skipping check that does not even have a feature gate
LL | | X(x) // FIXME: this should error someday --> $DIR/const_fn_ptr_fail.rs:10:5
LL | | } |
| |_^ LL | X(x) // FIXME: this should error someday
| ^^^^
warning: 1 warning emitted warning: 1 warning emitted

View file

@ -9,7 +9,7 @@ fn double(x: usize) -> usize {
} }
const X: fn(usize) -> usize = double; const X: fn(usize) -> usize = double;
const fn bar(x: fn(usize) -> usize, y: usize) -> usize { //~ WARN skipping const checks const fn bar(x: fn(usize) -> usize, y: usize) -> usize {
x(y) x(y)
} }

View file

@ -1,11 +1,3 @@
warning: skipping const checks
--> $DIR/const_fn_ptr_fail2.rs:12:1
|
LL | / const fn bar(x: fn(usize) -> usize, y: usize) -> usize {
LL | | x(y)
LL | | }
| |_^
error[E0080]: evaluation of constant expression failed error[E0080]: evaluation of constant expression failed
--> $DIR/const_fn_ptr_fail2.rs:20:5 --> $DIR/const_fn_ptr_fail2.rs:20:5
| |
@ -26,6 +18,14 @@ LL | assert_eq!(Z, 4);
| |
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
warning: skipping const checks
|
help: skipping check that does not even have a feature gate
--> $DIR/const_fn_ptr_fail2.rs:13:5
|
LL | x(y)
| ^^^^
error: aborting due to 2 previous errors; 1 warning emitted error: aborting due to 2 previous errors; 1 warning emitted
For more information about this error, try `rustc --explain E0080`. For more information about this error, try `rustc --explain E0080`.

View file

@ -3,8 +3,9 @@
#![allow(dead_code)] #![allow(dead_code)]
const TEST: &u8 = &MY_STATIC; const TEST: &u8 = &MY_STATIC;
//~^ skipping const checks //~^ ERROR it is undefined behavior to use this value
//~| it is undefined behavior to use this value //~| NOTE encountered a reference pointing to a static variable
//~| NOTE
static MY_STATIC: u8 = 4; static MY_STATIC: u8 = 4;

View file

@ -1,9 +1,3 @@
warning: skipping const checks
--> $DIR/const-points-to-static.rs:5:1
|
LL | const TEST: &u8 = &MY_STATIC;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/const-points-to-static.rs:5:1 --> $DIR/const-points-to-static.rs:5:1
| |
@ -12,6 +6,14 @@ LL | const TEST: &u8 = &MY_STATIC;
| |
= 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. = 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: skipping const checks
|
help: skipping check that does not even have a feature gate
--> $DIR/const-points-to-static.rs:5:20
|
LL | const TEST: &u8 = &MY_STATIC;
| ^^^^^^^^^
error: aborting due to previous error; 1 warning emitted error: aborting due to previous error; 1 warning emitted
For more information about this error, try `rustc --explain E0080`. For more information about this error, try `rustc --explain E0080`.

View file

@ -3,7 +3,6 @@
#![allow(dead_code)] #![allow(dead_code)]
const TEST: u8 = MY_STATIC; //~ ERROR any use of this value will cause an error const TEST: u8 = MY_STATIC; //~ ERROR any use of this value will cause an error
//~^ skipping const checks
static MY_STATIC: u8 = 4; static MY_STATIC: u8 = 4;

View file

@ -1,9 +1,3 @@
warning: skipping const checks
--> $DIR/const-prop-read-static-in-const.rs:5:1
|
LL | const TEST: u8 = MY_STATIC;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: any use of this value will cause an error error: any use of this value will cause an error
--> $DIR/const-prop-read-static-in-const.rs:5:18 --> $DIR/const-prop-read-static-in-const.rs:5:18
| |
@ -14,5 +8,13 @@ LL | const TEST: u8 = MY_STATIC;
| |
= note: `#[deny(const_err)]` on by default = note: `#[deny(const_err)]` on by default
warning: skipping const checks
|
help: skipping check that does not even have a feature gate
--> $DIR/const-prop-read-static-in-const.rs:5:18
|
LL | const TEST: u8 = MY_STATIC;
| ^^^^^^^^^
error: aborting due to previous error; 1 warning emitted error: aborting due to previous error; 1 warning emitted

View file

@ -7,7 +7,6 @@
const extern "C" fn c_fn() {} const extern "C" fn c_fn() {}
const fn call_rust_fn(my_fn: extern "Rust" fn()) { const fn call_rust_fn(my_fn: extern "Rust" fn()) {
//~^ WARN skipping const checks
my_fn(); my_fn();
//~^ ERROR could not evaluate static initializer //~^ ERROR could not evaluate static initializer
//~| NOTE calling a function with ABI C using caller ABI Rust //~| NOTE calling a function with ABI C using caller ABI Rust
@ -15,7 +14,6 @@ const fn call_rust_fn(my_fn: extern "Rust" fn()) {
} }
static VAL: () = call_rust_fn(unsafe { std::mem::transmute(c_fn as extern "C" fn()) }); static VAL: () = call_rust_fn(unsafe { std::mem::transmute(c_fn as extern "C" fn()) });
//~^ WARN skipping const checks //~^ NOTE inside `VAL`
//~| NOTE inside `VAL`
fn main() {} fn main() {}

View file

@ -1,33 +1,28 @@
warning: skipping const checks
--> $DIR/abi-mismatch.rs:9:1
|
LL | / const fn call_rust_fn(my_fn: extern "Rust" fn()) {
LL | |
LL | | my_fn();
LL | |
LL | |
LL | |
LL | | }
| |_^
warning: skipping const checks
--> $DIR/abi-mismatch.rs:17:1
|
LL | static VAL: () = call_rust_fn(unsafe { std::mem::transmute(c_fn as extern "C" fn()) });
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: could not evaluate static initializer error[E0080]: could not evaluate static initializer
--> $DIR/abi-mismatch.rs:11:5 --> $DIR/abi-mismatch.rs:10:5
| |
LL | my_fn(); LL | my_fn();
| ^^^^^^^ | ^^^^^^^
| | | |
| calling a function with ABI C using caller ABI Rust | calling a function with ABI C using caller ABI Rust
| inside `call_rust_fn` at $DIR/abi-mismatch.rs:11:5 | inside `call_rust_fn` at $DIR/abi-mismatch.rs:10:5
... ...
LL | static VAL: () = call_rust_fn(unsafe { std::mem::transmute(c_fn as extern "C" fn()) }); LL | static VAL: () = call_rust_fn(unsafe { std::mem::transmute(c_fn as extern "C" fn()) });
| --------------------------------------------------------------------- inside `VAL` at $DIR/abi-mismatch.rs:17:18 | --------------------------------------------------------------------- inside `VAL` at $DIR/abi-mismatch.rs:16:18
error: aborting due to previous error; 2 warnings emitted warning: skipping const checks
|
help: skipping check that does not even have a feature gate
--> $DIR/abi-mismatch.rs:10:5
|
LL | my_fn();
| ^^^^^^^
help: skipping check that does not even have a feature gate
--> $DIR/abi-mismatch.rs:16:40
|
LL | static VAL: () = call_rust_fn(unsafe { std::mem::transmute(c_fn as extern "C" fn()) });
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to previous error; 1 warning emitted
For more information about this error, try `rustc --explain E0080`. For more information about this error, try `rustc --explain E0080`.

View file

@ -11,7 +11,7 @@ trait Foo<T> {
} }
trait Bar<T, U: Foo<T>> { trait Bar<T, U: Foo<T>> {
const F: u32 = (U::X, 42).1; //~ WARN skipping const checks const F: u32 = (U::X, 42).1;
} }
impl Foo<u32> for () { impl Foo<u32> for () {

View file

@ -1,15 +1,17 @@
warning: skipping const checks
--> $DIR/assoc_const.rs:14:5
|
LL | const F: u32 = (U::X, 42).1;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: erroneous constant used error[E0080]: erroneous constant used
--> $DIR/assoc_const.rs:31:13 --> $DIR/assoc_const.rs:31:13
| |
LL | let y = <String as Bar<Vec<u32>, String>>::F; LL | let y = <String as Bar<Vec<u32>, String>>::F;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ referenced constant has errors | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ referenced constant has errors
warning: skipping const checks
|
help: skipping check that does not even have a feature gate
--> $DIR/assoc_const.rs:14:20
|
LL | const F: u32 = (U::X, 42).1;
| ^^^^^^^^^^
error: aborting due to previous error; 1 warning emitted error: aborting due to previous error; 1 warning emitted
For more information about this error, try `rustc --explain E0080`. For more information about this error, try `rustc --explain E0080`.

View file

@ -6,7 +6,7 @@ use std::mem::ManuallyDrop;
fn main() {} fn main() {}
static TEST_BAD: &mut i32 = { //~ WARN skipping const checks static TEST_BAD: &mut i32 = {
&mut *(box 0) &mut *(box 0)
//~^ ERROR could not evaluate static initializer //~^ ERROR could not evaluate static initializer
//~| NOTE heap allocations //~| NOTE heap allocations

View file

@ -1,19 +1,32 @@
warning: skipping const checks
--> $DIR/box.rs:9:1
|
LL | / static TEST_BAD: &mut i32 = {
LL | | &mut *(box 0)
LL | |
LL | |
LL | | };
| |__^
error[E0080]: could not evaluate static initializer error[E0080]: could not evaluate static initializer
--> $DIR/box.rs:10:11 --> $DIR/box.rs:10:11
| |
LL | &mut *(box 0) LL | &mut *(box 0)
| ^^^^^^^ "heap allocations via `box` keyword" needs an rfc before being allowed inside constants | ^^^^^^^ "heap allocations via `box` keyword" needs an rfc before being allowed inside constants
warning: skipping const checks
|
help: skipping check that does not even have a feature gate
--> $DIR/box.rs:10:11
|
LL | &mut *(box 0)
| ^^^^^^^
help: skipping check for `const_mut_refs` feature
--> $DIR/box.rs:10:16
|
LL | &mut *(box 0)
| ^
help: skipping check for `const_mut_refs` feature
--> $DIR/box.rs:10:5
|
LL | &mut *(box 0)
| ^^^^^^^^^^^^^
help: skipping check for `const_mut_refs` feature
--> $DIR/box.rs:10:5
|
LL | &mut *(box 0)
| ^^^^^^^^^^^^^
error: aborting due to previous error; 1 warning emitted error: aborting due to previous error; 1 warning emitted
For more information about this error, try `rustc --explain E0080`. For more information about this error, try `rustc --explain E0080`.

View file

@ -9,20 +9,17 @@ use std::sync::atomic::Ordering;
// when *using* the const. // when *using* the const.
const MUTATE_INTERIOR_MUT: usize = { const MUTATE_INTERIOR_MUT: usize = {
//~^ WARN skipping const checks
static FOO: AtomicUsize = AtomicUsize::new(0); static FOO: AtomicUsize = AtomicUsize::new(0);
FOO.fetch_add(1, Ordering::Relaxed) FOO.fetch_add(1, Ordering::Relaxed)
}; };
const READ_INTERIOR_MUT: usize = { const READ_INTERIOR_MUT: usize = {
//~^ WARN skipping const checks
static FOO: AtomicUsize = AtomicUsize::new(0); static FOO: AtomicUsize = AtomicUsize::new(0);
unsafe { *(&FOO as *const _ as *const usize) } unsafe { *(&FOO as *const _ as *const usize) }
}; };
static mut MUTABLE: u32 = 0; static mut MUTABLE: u32 = 0;
const READ_MUT: u32 = unsafe { MUTABLE }; const READ_MUT: u32 = unsafe { MUTABLE };
//~^ WARN skipping const checks
fn main() { fn main() {
MUTATE_INTERIOR_MUT; MUTATE_INTERIOR_MUT;

View file

@ -1,47 +1,54 @@
warning: skipping const checks
--> $DIR/const_refers_to_static.rs:11:1
|
LL | / const MUTATE_INTERIOR_MUT: usize = {
LL | |
LL | | static FOO: AtomicUsize = AtomicUsize::new(0);
LL | | FOO.fetch_add(1, Ordering::Relaxed)
LL | | };
| |__^
warning: skipping const checks
--> $DIR/const_refers_to_static.rs:17:1
|
LL | / const READ_INTERIOR_MUT: usize = {
LL | |
LL | | static FOO: AtomicUsize = AtomicUsize::new(0);
LL | | unsafe { *(&FOO as *const _ as *const usize) }
LL | | };
| |__^
warning: skipping const checks
--> $DIR/const_refers_to_static.rs:24:1
|
LL | const READ_MUT: u32 = unsafe { MUTABLE };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: erroneous constant used error[E0080]: erroneous constant used
--> $DIR/const_refers_to_static.rs:28:5 --> $DIR/const_refers_to_static.rs:25:5
| |
LL | MUTATE_INTERIOR_MUT; LL | MUTATE_INTERIOR_MUT;
| ^^^^^^^^^^^^^^^^^^^ referenced constant has errors | ^^^^^^^^^^^^^^^^^^^ referenced constant has errors
error[E0080]: erroneous constant used error[E0080]: erroneous constant used
--> $DIR/const_refers_to_static.rs:30:5 --> $DIR/const_refers_to_static.rs:27:5
| |
LL | READ_INTERIOR_MUT; LL | READ_INTERIOR_MUT;
| ^^^^^^^^^^^^^^^^^ referenced constant has errors | ^^^^^^^^^^^^^^^^^ referenced constant has errors
error[E0080]: erroneous constant used error[E0080]: erroneous constant used
--> $DIR/const_refers_to_static.rs:32:5 --> $DIR/const_refers_to_static.rs:29:5
| |
LL | READ_MUT; LL | READ_MUT;
| ^^^^^^^^ referenced constant has errors | ^^^^^^^^ referenced constant has errors
error: aborting due to 3 previous errors; 3 warnings emitted warning: skipping const checks
|
help: skipping check that does not even have a feature gate
--> $DIR/const_refers_to_static.rs:13:5
|
LL | FOO.fetch_add(1, Ordering::Relaxed)
| ^^^
help: skipping check that does not even have a feature gate
--> $DIR/const_refers_to_static.rs:13:5
|
LL | FOO.fetch_add(1, Ordering::Relaxed)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: skipping check that does not even have a feature gate
--> $DIR/const_refers_to_static.rs:18:17
|
LL | unsafe { *(&FOO as *const _ as *const usize) }
| ^^^
help: skipping check for `const_raw_ptr_deref` feature
--> $DIR/const_refers_to_static.rs:18:14
|
LL | unsafe { *(&FOO as *const _ as *const usize) }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: skipping check that does not even have a feature gate
--> $DIR/const_refers_to_static.rs:22:32
|
LL | const READ_MUT: u32 = unsafe { MUTABLE };
| ^^^^^^^
help: skipping check that does not even have a feature gate
--> $DIR/const_refers_to_static.rs:22:32
|
LL | const READ_MUT: u32 = unsafe { MUTABLE };
| ^^^^^^^
error: aborting due to 3 previous errors; 1 warning emitted
For more information about this error, try `rustc --explain E0080`. For more information about this error, try `rustc --explain E0080`.

View file

@ -8,7 +8,6 @@ use std::sync::atomic::Ordering;
// so they cause an immediate error when *defining* the const. // so they cause an immediate error when *defining* the const.
const REF_INTERIOR_MUT: &usize = { //~ ERROR undefined behavior to use this value const REF_INTERIOR_MUT: &usize = { //~ ERROR undefined behavior to use this value
//~^ WARN skipping const checks
//~| NOTE encountered a reference pointing to a static variable //~| NOTE encountered a reference pointing to a static variable
//~| NOTE //~| NOTE
static FOO: AtomicUsize = AtomicUsize::new(0); static FOO: AtomicUsize = AtomicUsize::new(0);
@ -17,7 +16,6 @@ const REF_INTERIOR_MUT: &usize = { //~ ERROR undefined behavior to use this valu
// ok some day perhaps // ok some day perhaps
const READ_IMMUT: &usize = { //~ ERROR it is undefined behavior to use this value const READ_IMMUT: &usize = { //~ ERROR it is undefined behavior to use this value
//~^ WARN skipping const checks
//~| NOTE encountered a reference pointing to a static variable //~| NOTE encountered a reference pointing to a static variable
//~| NOTE //~| NOTE
static FOO: usize = 0; static FOO: usize = 0;

View file

@ -1,34 +1,9 @@
warning: skipping const checks
--> $DIR/const_refers_to_static2.rs:10:1
|
LL | / const REF_INTERIOR_MUT: &usize = {
LL | |
LL | |
LL | |
LL | | static FOO: AtomicUsize = AtomicUsize::new(0);
LL | | unsafe { &*(&FOO as *const _ as *const usize) }
LL | | };
| |__^
warning: skipping const checks
--> $DIR/const_refers_to_static2.rs:19:1
|
LL | / const READ_IMMUT: &usize = {
LL | |
LL | |
LL | |
LL | | static FOO: usize = 0;
LL | | &FOO
LL | | };
| |__^
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/const_refers_to_static2.rs:10:1 --> $DIR/const_refers_to_static2.rs:10:1
| |
LL | / const REF_INTERIOR_MUT: &usize = { LL | / const REF_INTERIOR_MUT: &usize = {
LL | | LL | |
LL | | LL | |
LL | |
LL | | static FOO: AtomicUsize = AtomicUsize::new(0); LL | | static FOO: AtomicUsize = AtomicUsize::new(0);
LL | | unsafe { &*(&FOO as *const _ as *const usize) } LL | | unsafe { &*(&FOO as *const _ as *const usize) }
LL | | }; LL | | };
@ -37,12 +12,11 @@ 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. = 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.
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/const_refers_to_static2.rs:19:1 --> $DIR/const_refers_to_static2.rs:18:1
| |
LL | / const READ_IMMUT: &usize = { LL | / const READ_IMMUT: &usize = {
LL | | LL | |
LL | | LL | |
LL | |
LL | | static FOO: usize = 0; LL | | static FOO: usize = 0;
LL | | &FOO LL | | &FOO
LL | | }; LL | | };
@ -50,6 +24,24 @@ 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. = 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.
error: aborting due to 2 previous errors; 2 warnings emitted warning: skipping const checks
|
help: skipping check that does not even have a feature gate
--> $DIR/const_refers_to_static2.rs:14:18
|
LL | unsafe { &*(&FOO as *const _ as *const usize) }
| ^^^
help: skipping check for `const_raw_ptr_deref` feature
--> $DIR/const_refers_to_static2.rs:14:14
|
LL | unsafe { &*(&FOO as *const _ as *const usize) }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: skipping check that does not even have a feature gate
--> $DIR/const_refers_to_static2.rs:22:6
|
LL | &FOO
| ^^^
error: aborting due to 2 previous errors; 1 warning emitted
For more information about this error, try `rustc --explain E0080`. For more information about this error, try `rustc --explain E0080`.

View file

@ -9,14 +9,12 @@ extern crate static_cross_crate;
// Sneaky: reference to a mutable static. // Sneaky: reference to a mutable static.
// Allowing this would be a disaster for pattern matching, we could violate exhaustiveness checking! // Allowing this would be a disaster for pattern matching, we could violate exhaustiveness checking!
const SLICE_MUT: &[u8; 1] = { //~ ERROR undefined behavior to use this value const SLICE_MUT: &[u8; 1] = { //~ ERROR undefined behavior to use this value
//~^ WARN skipping const checks
//~| NOTE encountered a reference pointing to a static variable //~| NOTE encountered a reference pointing to a static variable
//~| NOTE //~| NOTE
unsafe { &static_cross_crate::ZERO } unsafe { &static_cross_crate::ZERO }
}; };
const U8_MUT: &u8 = { //~ ERROR undefined behavior to use this value const U8_MUT: &u8 = { //~ ERROR undefined behavior to use this value
//~^ WARN skipping const checks
//~| NOTE encountered a reference pointing to a static variable //~| NOTE encountered a reference pointing to a static variable
//~| NOTE //~| NOTE
unsafe { &static_cross_crate::ZERO[0] } unsafe { &static_cross_crate::ZERO[0] }
@ -25,14 +23,12 @@ const U8_MUT: &u8 = { //~ ERROR undefined behavior to use this value
// Also test indirection that reads from other static. This causes a const_err. // Also test indirection that reads from other static. This causes a const_err.
#[warn(const_err)] //~ NOTE #[warn(const_err)] //~ NOTE
const U8_MUT2: &u8 = { //~ NOTE const U8_MUT2: &u8 = { //~ NOTE
//~^ WARN skipping const checks
unsafe { &(*static_cross_crate::ZERO_REF)[0] } unsafe { &(*static_cross_crate::ZERO_REF)[0] }
//~^ WARN [const_err] //~^ WARN [const_err]
//~| NOTE constant accesses static //~| NOTE constant accesses static
}; };
#[warn(const_err)] //~ NOTE #[warn(const_err)] //~ NOTE
const U8_MUT3: &u8 = { //~ NOTE const U8_MUT3: &u8 = { //~ NOTE
//~^ WARN skipping const checks
unsafe { match static_cross_crate::OPT_ZERO { Some(ref u) => u, None => panic!() } } unsafe { match static_cross_crate::OPT_ZERO { Some(ref u) => u, None => panic!() } }
//~^ WARN [const_err] //~^ WARN [const_err]
//~| NOTE constant accesses static //~| NOTE constant accesses static

View file

@ -1,21 +1,9 @@
warning: skipping const checks
--> $DIR/const_refers_to_static_cross_crate.rs:11:1
|
LL | / const SLICE_MUT: &[u8; 1] = {
LL | |
LL | |
LL | |
LL | | unsafe { &static_cross_crate::ZERO }
LL | | };
| |__^
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/const_refers_to_static_cross_crate.rs:11:1 --> $DIR/const_refers_to_static_cross_crate.rs:11:1
| |
LL | / const SLICE_MUT: &[u8; 1] = { LL | / const SLICE_MUT: &[u8; 1] = {
LL | | LL | |
LL | | LL | |
LL | |
LL | | unsafe { &static_cross_crate::ZERO } LL | | unsafe { &static_cross_crate::ZERO }
LL | | }; LL | | };
| |__^ type validation failed: encountered a reference pointing to a static variable | |__^ type validation failed: encountered a reference pointing to a static variable
@ -23,29 +11,17 @@ 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. = 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.
error: could not evaluate constant pattern error: could not evaluate constant pattern
--> $DIR/const_refers_to_static_cross_crate.rs:43:9 --> $DIR/const_refers_to_static_cross_crate.rs:39:9
| |
LL | SLICE_MUT => true, LL | SLICE_MUT => true,
| ^^^^^^^^^ | ^^^^^^^^^
warning: skipping const checks
--> $DIR/const_refers_to_static_cross_crate.rs:18:1
|
LL | / const U8_MUT: &u8 = {
LL | |
LL | |
LL | |
LL | | unsafe { &static_cross_crate::ZERO[0] }
LL | | };
| |__^
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/const_refers_to_static_cross_crate.rs:18:1 --> $DIR/const_refers_to_static_cross_crate.rs:17:1
| |
LL | / const U8_MUT: &u8 = { LL | / const U8_MUT: &u8 = {
LL | | LL | |
LL | | LL | |
LL | |
LL | | unsafe { &static_cross_crate::ZERO[0] } LL | | unsafe { &static_cross_crate::ZERO[0] }
LL | | }; LL | | };
| |__^ type validation failed: encountered a reference pointing to a static variable | |__^ type validation failed: encountered a reference pointing to a static variable
@ -53,27 +29,15 @@ 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. = 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.
error: could not evaluate constant pattern error: could not evaluate constant pattern
--> $DIR/const_refers_to_static_cross_crate.rs:51:9 --> $DIR/const_refers_to_static_cross_crate.rs:47:9
| |
LL | U8_MUT => true, LL | U8_MUT => true,
| ^^^^^^ | ^^^^^^
warning: skipping const checks
--> $DIR/const_refers_to_static_cross_crate.rs:27:1
|
LL | / const U8_MUT2: &u8 = {
LL | |
LL | | unsafe { &(*static_cross_crate::ZERO_REF)[0] }
LL | |
LL | |
LL | | };
| |__^
warning: any use of this value will cause an error warning: any use of this value will cause an error
--> $DIR/const_refers_to_static_cross_crate.rs:29:14 --> $DIR/const_refers_to_static_cross_crate.rs:26:14
| |
LL | / const U8_MUT2: &u8 = { LL | / const U8_MUT2: &u8 = {
LL | |
LL | | unsafe { &(*static_cross_crate::ZERO_REF)[0] } LL | | unsafe { &(*static_cross_crate::ZERO_REF)[0] }
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constant accesses static | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constant accesses static
LL | | LL | |
@ -82,33 +46,21 @@ LL | | };
| |__- | |__-
| |
note: the lint level is defined here note: the lint level is defined here
--> $DIR/const_refers_to_static_cross_crate.rs:26:8 --> $DIR/const_refers_to_static_cross_crate.rs:24:8
| |
LL | #[warn(const_err)] LL | #[warn(const_err)]
| ^^^^^^^^^ | ^^^^^^^^^
error: could not evaluate constant pattern error: could not evaluate constant pattern
--> $DIR/const_refers_to_static_cross_crate.rs:61:9 --> $DIR/const_refers_to_static_cross_crate.rs:57:9
| |
LL | U8_MUT2 => true, LL | U8_MUT2 => true,
| ^^^^^^^ | ^^^^^^^
warning: skipping const checks
--> $DIR/const_refers_to_static_cross_crate.rs:34:1
|
LL | / const U8_MUT3: &u8 = {
LL | |
LL | | unsafe { match static_cross_crate::OPT_ZERO { Some(ref u) => u, None => panic!() } }
LL | |
LL | |
LL | | };
| |__^
warning: any use of this value will cause an error warning: any use of this value will cause an error
--> $DIR/const_refers_to_static_cross_crate.rs:36:51 --> $DIR/const_refers_to_static_cross_crate.rs:32:51
| |
LL | / const U8_MUT3: &u8 = { LL | / const U8_MUT3: &u8 = {
LL | |
LL | | unsafe { match static_cross_crate::OPT_ZERO { Some(ref u) => u, None => panic!() } } LL | | unsafe { match static_cross_crate::OPT_ZERO { Some(ref u) => u, None => panic!() } }
| | ^^^^^^^^^^^ constant accesses static | | ^^^^^^^^^^^ constant accesses static
LL | | LL | |
@ -117,17 +69,76 @@ LL | | };
| |__- | |__-
| |
note: the lint level is defined here note: the lint level is defined here
--> $DIR/const_refers_to_static_cross_crate.rs:33:8 --> $DIR/const_refers_to_static_cross_crate.rs:30:8
| |
LL | #[warn(const_err)] LL | #[warn(const_err)]
| ^^^^^^^^^ | ^^^^^^^^^
error: could not evaluate constant pattern error: could not evaluate constant pattern
--> $DIR/const_refers_to_static_cross_crate.rs:68:9 --> $DIR/const_refers_to_static_cross_crate.rs:64:9
| |
LL | U8_MUT3 => true, LL | U8_MUT3 => true,
| ^^^^^^^ | ^^^^^^^
error: aborting due to 6 previous errors; 6 warnings emitted warning: skipping const checks
|
help: skipping check that does not even have a feature gate
--> $DIR/const_refers_to_static_cross_crate.rs:14:15
|
LL | unsafe { &static_cross_crate::ZERO }
| ^^^^^^^^^^^^^^^^^^^^^^^^
help: skipping check that does not even have a feature gate
--> $DIR/const_refers_to_static_cross_crate.rs:14:15
|
LL | unsafe { &static_cross_crate::ZERO }
| ^^^^^^^^^^^^^^^^^^^^^^^^
help: skipping check that does not even have a feature gate
--> $DIR/const_refers_to_static_cross_crate.rs:20:15
|
LL | unsafe { &static_cross_crate::ZERO[0] }
| ^^^^^^^^^^^^^^^^^^^^^^^^
help: skipping check that does not even have a feature gate
--> $DIR/const_refers_to_static_cross_crate.rs:20:15
|
LL | unsafe { &static_cross_crate::ZERO[0] }
| ^^^^^^^^^^^^^^^^^^^^^^^^
help: skipping check that does not even have a feature gate
--> $DIR/const_refers_to_static_cross_crate.rs:20:15
|
LL | unsafe { &static_cross_crate::ZERO[0] }
| ^^^^^^^^^^^^^^^^^^^^^^^^
help: skipping check that does not even have a feature gate
--> $DIR/const_refers_to_static_cross_crate.rs:26:17
|
LL | unsafe { &(*static_cross_crate::ZERO_REF)[0] }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: skipping check that does not even have a feature gate
--> $DIR/const_refers_to_static_cross_crate.rs:32:20
|
LL | unsafe { match static_cross_crate::OPT_ZERO { Some(ref u) => u, None => panic!() } }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: skipping check that does not even have a feature gate
--> $DIR/const_refers_to_static_cross_crate.rs:32:20
|
LL | unsafe { match static_cross_crate::OPT_ZERO { Some(ref u) => u, None => panic!() } }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: skipping check that does not even have a feature gate
--> $DIR/const_refers_to_static_cross_crate.rs:32:20
|
LL | unsafe { match static_cross_crate::OPT_ZERO { Some(ref u) => u, None => panic!() } }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: skipping check for `const_panic` feature
--> $DIR/const_refers_to_static_cross_crate.rs:32:77
|
LL | unsafe { match static_cross_crate::OPT_ZERO { Some(ref u) => u, None => panic!() } }
| ^^^^^^^^
help: skipping check that does not even have a feature gate
--> $DIR/const_refers_to_static_cross_crate.rs:32:20
|
LL | unsafe { match static_cross_crate::OPT_ZERO { Some(ref u) => u, None => panic!() } }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: this warning originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to 6 previous errors; 3 warnings emitted
For more information about this error, try `rustc --explain E0080`. For more information about this error, try `rustc --explain E0080`.

View file

@ -13,6 +13,6 @@ static TEST_OK: () = {
// Make sure we catch executing bad drop functions. // Make sure we catch executing bad drop functions.
// The actual error is tested by the error-pattern above. // The actual error is tested by the error-pattern above.
static TEST_BAD: () = { //~ WARN skipping const checks static TEST_BAD: () = {
let _v: Vec<i32> = Vec::new(); let _v: Vec<i32> = Vec::new();
}; };

View file

@ -1,11 +1,3 @@
warning: skipping const checks
--> $DIR/drop.rs:16:1
|
LL | / static TEST_BAD: () = {
LL | | let _v: Vec<i32> = Vec::new();
LL | | };
| |__^
error[E0080]: could not evaluate static initializer error[E0080]: could not evaluate static initializer
--> $SRC_DIR/libcore/ptr/mod.rs:LL:COL --> $SRC_DIR/libcore/ptr/mod.rs:LL:COL
| |
@ -24,6 +16,14 @@ LL | | }
LL | }; LL | };
| - inside `TEST_BAD` at $DIR/drop.rs:18:1 | - inside `TEST_BAD` at $DIR/drop.rs:18:1
warning: skipping const checks
|
help: skipping check that does not even have a feature gate
--> $DIR/drop.rs:17:9
|
LL | let _v: Vec<i32> = Vec::new();
| ^^
error: aborting due to previous error; 1 warning emitted error: aborting due to previous error; 1 warning emitted
For more information about this error, try `rustc --explain E0080`. For more information about this error, try `rustc --explain E0080`.

View file

@ -6,9 +6,10 @@
fn main() {} fn main() {}
// Make sure we catch executing inline assembly. // Make sure we catch executing inline assembly.
static TEST_BAD: () = { //~ WARN skipping const checks static TEST_BAD: () = {
unsafe { llvm_asm!("xor %eax, %eax" ::: "eax"); } unsafe { llvm_asm!("xor %eax, %eax" ::: "eax"); }
//~^ ERROR could not evaluate static initializer //~^ ERROR could not evaluate static initializer
//~| NOTE inline assembly is not supported //~| NOTE inline assembly is not supported
//~| NOTE in this expansion of llvm_asm! //~| NOTE in this expansion of llvm_asm!
//~| NOTE in this expansion of llvm_asm!
}; };

View file

@ -1,14 +1,3 @@
warning: skipping const checks
--> $DIR/inline_asm.rs:9:1
|
LL | / static TEST_BAD: () = {
LL | | unsafe { llvm_asm!("xor %eax, %eax" ::: "eax"); }
LL | |
LL | |
LL | |
LL | | };
| |__^
error[E0080]: could not evaluate static initializer error[E0080]: could not evaluate static initializer
--> $DIR/inline_asm.rs:10:14 --> $DIR/inline_asm.rs:10:14
| |
@ -17,6 +6,15 @@ LL | unsafe { llvm_asm!("xor %eax, %eax" ::: "eax"); }
| |
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
warning: skipping const checks
|
help: skipping check that does not even have a feature gate
--> $DIR/inline_asm.rs:10:14
|
LL | unsafe { llvm_asm!("xor %eax, %eax" ::: "eax"); }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: this warning originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to previous error; 1 warning emitted error: aborting due to previous error; 1 warning emitted
For more information about this error, try `rustc --explain E0080`. For more information about this error, try `rustc --explain E0080`.

View file

@ -11,10 +11,8 @@ use std::cell::UnsafeCell;
// make sure we do not just intern this as mutable // make sure we do not just intern this as mutable
const MUTABLE_BEHIND_RAW: *mut i32 = &UnsafeCell::new(42) as *const _ as *mut _; const MUTABLE_BEHIND_RAW: *mut i32 = &UnsafeCell::new(42) as *const _ as *mut _;
//~^ WARN: skipping const checks
const MUTATING_BEHIND_RAW: () = { //~ NOTE const MUTATING_BEHIND_RAW: () = { //~ NOTE
//~^ WARN skipping const checks
// Test that `MUTABLE_BEHIND_RAW` is actually immutable, by doing this at const time. // Test that `MUTABLE_BEHIND_RAW` is actually immutable, by doing this at const time.
unsafe { unsafe {
*MUTABLE_BEHIND_RAW = 99 //~ ERROR any use of this value will cause an error *MUTABLE_BEHIND_RAW = 99 //~ ERROR any use of this value will cause an error

View file

@ -1,26 +1,7 @@
warning: skipping const checks
--> $DIR/mutable_const.rs:13:1
|
LL | const MUTABLE_BEHIND_RAW: *mut i32 = &UnsafeCell::new(42) as *const _ as *mut _;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
warning: skipping const checks
--> $DIR/mutable_const.rs:16:1
|
LL | / const MUTATING_BEHIND_RAW: () = {
LL | |
LL | | // Test that `MUTABLE_BEHIND_RAW` is actually immutable, by doing this at const time.
LL | | unsafe {
... |
LL | | }
LL | | };
| |__^
error: any use of this value will cause an error error: any use of this value will cause an error
--> $DIR/mutable_const.rs:20:9 --> $DIR/mutable_const.rs:18:9
| |
LL | / const MUTATING_BEHIND_RAW: () = { LL | / const MUTATING_BEHIND_RAW: () = {
LL | |
LL | | // Test that `MUTABLE_BEHIND_RAW` is actually immutable, by doing this at const time. LL | | // Test that `MUTABLE_BEHIND_RAW` is actually immutable, by doing this at const time.
LL | | unsafe { LL | | unsafe {
LL | | *MUTABLE_BEHIND_RAW = 99 LL | | *MUTABLE_BEHIND_RAW = 99
@ -36,5 +17,23 @@ note: the lint level is defined here
LL | #![deny(const_err)] // The `allow` variant is tested by `mutable_const2`. LL | #![deny(const_err)] // The `allow` variant is tested by `mutable_const2`.
| ^^^^^^^^^ | ^^^^^^^^^
error: aborting due to previous error; 2 warnings emitted warning: skipping const checks
|
help: skipping check that does not even have a feature gate
--> $DIR/mutable_const.rs:13:38
|
LL | const MUTABLE_BEHIND_RAW: *mut i32 = &UnsafeCell::new(42) as *const _ as *mut _;
| ^^^^^^^^^^^^^^^^^^^^
help: skipping check for `const_raw_ptr_deref` feature
--> $DIR/mutable_const.rs:18:9
|
LL | *MUTABLE_BEHIND_RAW = 99
| ^^^^^^^^^^^^^^^^^^^^^^^^
help: skipping check for `const_mut_refs` feature
--> $DIR/mutable_const.rs:18:9
|
LL | *MUTABLE_BEHIND_RAW = 99
| ^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to previous error; 1 warning emitted

View file

@ -11,7 +11,6 @@ use std::cell::UnsafeCell;
// make sure we do not just intern this as mutable // make sure we do not just intern this as mutable
const MUTABLE_BEHIND_RAW: *mut i32 = &UnsafeCell::new(42) as *const _ as *mut _; const MUTABLE_BEHIND_RAW: *mut i32 = &UnsafeCell::new(42) as *const _ as *mut _;
//~^ WARN: skipping const checks //~^ ERROR: mutable allocation in constant
//~| ERROR: mutable allocation in constant
fn main() {} fn main() {}

View file

@ -1,8 +1,10 @@
warning: skipping const checks warning: skipping const checks
--> $DIR/mutable_const2.rs:13:1 |
help: skipping check that does not even have a feature gate
--> $DIR/mutable_const2.rs:13:38
| |
LL | const MUTABLE_BEHIND_RAW: *mut i32 = &UnsafeCell::new(42) as *const _ as *mut _; LL | const MUTABLE_BEHIND_RAW: *mut i32 = &UnsafeCell::new(42) as *const _ as *mut _;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^
warning: 1 warning emitted warning: 1 warning emitted

View file

@ -7,18 +7,15 @@ use std::cell::UnsafeCell;
// this is fine because is not possible to mutate through an immutable reference. // this is fine because is not possible to mutate through an immutable reference.
static FOO: &&mut u32 = &&mut 42; static FOO: &&mut u32 = &&mut 42;
//~^ WARN skipping const checks
// this is fine because accessing an immutable static `BAR` is equivalent to accessing `*&BAR` // this is fine because accessing an immutable static `BAR` is equivalent to accessing `*&BAR`
// which puts the mutable reference behind an immutable one. // which puts the mutable reference behind an immutable one.
static BAR: &mut () = &mut (); static BAR: &mut () = &mut ();
//~^ WARN skipping const checks
struct Foo<T>(T); struct Foo<T>(T);
// this is fine for the same reason as `BAR`. // this is fine for the same reason as `BAR`.
static BOO: &mut Foo<()> = &mut Foo(()); static BOO: &mut Foo<()> = &mut Foo(());
//~^ WARN skipping const checks
struct Meh { struct Meh {
x: &'static UnsafeCell<i32>, x: &'static UnsafeCell<i32>,
@ -26,13 +23,12 @@ struct Meh {
unsafe impl Sync for Meh {} unsafe impl Sync for Meh {}
static MEH: Meh = Meh { //~ WARN skipping const checks static MEH: Meh = Meh {
x: &UnsafeCell::new(42), x: &UnsafeCell::new(42),
}; };
// this is fine for the same reason as `BAR`. // this is fine for the same reason as `BAR`.
static OH_YES: &mut i32 = &mut 42; static OH_YES: &mut i32 = &mut 42;
//~^ WARN skipping const checks
fn main() { fn main() {
unsafe { unsafe {

View file

@ -1,41 +1,37 @@
warning: skipping const checks
--> $DIR/mutable_references.rs:9:1
|
LL | static FOO: &&mut u32 = &&mut 42;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
warning: skipping const checks
--> $DIR/mutable_references.rs:14:1
|
LL | static BAR: &mut () = &mut ();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
warning: skipping const checks
--> $DIR/mutable_references.rs:20:1
|
LL | static BOO: &mut Foo<()> = &mut Foo(());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
warning: skipping const checks
--> $DIR/mutable_references.rs:29:1
|
LL | / static MEH: Meh = Meh {
LL | | x: &UnsafeCell::new(42),
LL | | };
| |__^
warning: skipping const checks
--> $DIR/mutable_references.rs:34:1
|
LL | static OH_YES: &mut i32 = &mut 42;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0594]: cannot assign to `*OH_YES`, as `OH_YES` is an immutable static item error[E0594]: cannot assign to `*OH_YES`, as `OH_YES` is an immutable static item
--> $DIR/mutable_references.rs:41:5 --> $DIR/mutable_references.rs:37:5
| |
LL | *OH_YES = 99; LL | *OH_YES = 99;
| ^^^^^^^^^^^^ cannot assign | ^^^^^^^^^^^^ cannot assign
error: aborting due to previous error; 5 warnings emitted warning: skipping const checks
|
help: skipping check for `const_mut_refs` feature
--> $DIR/mutable_references.rs:9:26
|
LL | static FOO: &&mut u32 = &&mut 42;
| ^^^^^^^
help: skipping check for `const_mut_refs` feature
--> $DIR/mutable_references.rs:13:23
|
LL | static BAR: &mut () = &mut ();
| ^^^^^^^
help: skipping check for `const_mut_refs` feature
--> $DIR/mutable_references.rs:18:28
|
LL | static BOO: &mut Foo<()> = &mut Foo(());
| ^^^^^^^^^^^^
help: skipping check that does not even have a feature gate
--> $DIR/mutable_references.rs:27:8
|
LL | x: &UnsafeCell::new(42),
| ^^^^^^^^^^^^^^^^^^^^
help: skipping check for `const_mut_refs` feature
--> $DIR/mutable_references.rs:31:27
|
LL | static OH_YES: &mut i32 = &mut 42;
| ^^^^^^^
error: aborting due to previous error; 1 warning emitted
For more information about this error, try `rustc --explain E0594`. For more information about this error, try `rustc --explain E0594`.

View file

@ -18,7 +18,7 @@ struct Meh {
unsafe impl Sync for Meh {} unsafe impl Sync for Meh {}
// the following will never be ok! // the following will never be ok!
const MUH: Meh = Meh { //~ WARN skipping const checks const MUH: Meh = Meh {
x: &UnsafeCell::new(42), x: &UnsafeCell::new(42),
}; };

View file

@ -1,11 +1,3 @@
warning: skipping const checks
--> $DIR/mutable_references_ice.rs:21:1
|
LL | / const MUH: Meh = Meh {
LL | | x: &UnsafeCell::new(42),
LL | | };
| |__^
thread 'rustc' panicked at 'assertion failed: `(left != right)` thread 'rustc' panicked at 'assertion failed: `(left != right)`
left: `Const`, left: `Const`,
right: `Const`: UnsafeCells are not allowed behind references in constants. This should have been prevented statically by const qualification. If this were allowed one would be able to change a constant at one use site and other use sites could observe that mutation.', src/librustc_mir/interpret/intern.rs:LL:CC right: `Const`: UnsafeCells are not allowed behind references in constants. This should have been prevented statically by const qualification. If this were allowed one would be able to change a constant at one use site and other use sites could observe that mutation.', src/librustc_mir/interpret/intern.rs:LL:CC
@ -21,5 +13,13 @@ note: rustc VERSION running on TARGET
note: compiler flags: FLAGS note: compiler flags: FLAGS
warning: skipping const checks
|
help: skipping check that does not even have a feature gate
--> $DIR/mutable_references_ice.rs:22:8
|
LL | x: &UnsafeCell::new(42),
| ^^^^^^^^^^^^^^^^^^^^
warning: 1 warning emitted warning: 1 warning emitted

View file

@ -6,7 +6,7 @@
fn foo() {} fn foo() {}
static C: () = foo(); //~ WARN: skipping const checks static C: () = foo();
//~^ ERROR could not evaluate static initializer //~^ ERROR could not evaluate static initializer
//~| NOTE calling non-const function `foo` //~| NOTE calling non-const function `foo`

View file

@ -1,15 +1,17 @@
warning: skipping const checks
--> $DIR/non_const_fn.rs:9:1
|
LL | static C: () = foo();
| ^^^^^^^^^^^^^^^^^^^^^
error[E0080]: could not evaluate static initializer error[E0080]: could not evaluate static initializer
--> $DIR/non_const_fn.rs:9:16 --> $DIR/non_const_fn.rs:9:16
| |
LL | static C: () = foo(); LL | static C: () = foo();
| ^^^^^ calling non-const function `foo` | ^^^^^ calling non-const function `foo`
warning: skipping const checks
|
help: skipping check that does not even have a feature gate
--> $DIR/non_const_fn.rs:9:16
|
LL | static C: () = foo();
| ^^^^^
error: aborting due to previous error; 1 warning emitted error: aborting due to previous error; 1 warning emitted
For more information about this error, try `rustc --explain E0080`. For more information about this error, try `rustc --explain E0080`.