diff --git a/src/librustc_mir/const_eval.rs b/src/librustc_mir/const_eval.rs index 3ea76fab6dd3..4fa4e87e0ffb 100644 --- a/src/librustc_mir/const_eval.rs +++ b/src/librustc_mir/const_eval.rs @@ -182,6 +182,7 @@ fn eval_body_using_ecx<'mir, 'tcx>( #[derive(Clone, Debug)] pub enum ConstEvalError { NeedsRfc(String), + ConstAccessesStatic, } impl<'tcx> Into> for ConstEvalError { @@ -201,6 +202,7 @@ impl fmt::Display for ConstEvalError { msg ) } + ConstAccessesStatic => write!(f, "constant accesses static"), } } } @@ -210,6 +212,7 @@ impl Error for ConstEvalError { use self::ConstEvalError::*; match *self { NeedsRfc(_) => "this feature needs an rfc before being allowed inside constants", + ConstAccessesStatic => "constant accesses static", } } @@ -547,9 +550,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir, if memory_extra.can_access_statics { Ok(()) } else { - Err(ConstEvalError::NeedsRfc( - "constants accessing static items".to_string(), - ).into()) + Err(ConstEvalError::ConstAccessesStatic.into()) } } } diff --git a/src/test/ui/consts/const-points-to-static.stderr b/src/test/ui/consts/const-points-to-static.stderr index 5ebd643b39db..8949358e2933 100644 --- a/src/test/ui/consts/const-points-to-static.stderr +++ b/src/test/ui/consts/const-points-to-static.stderr @@ -8,7 +8,7 @@ error[E0080]: it is undefined behavior to use this value --> $DIR/const-points-to-static.rs:5:1 | LL | const TEST: &u8 = &MY_STATIC; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ "constants accessing static items" needs an rfc before being allowed inside constants + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constant accesses 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. diff --git a/src/test/ui/consts/const-prop-read-static-in-const.stderr b/src/test/ui/consts/const-prop-read-static-in-const.stderr index 993cf455aba3..bfaa0f934ade 100644 --- a/src/test/ui/consts/const-prop-read-static-in-const.stderr +++ b/src/test/ui/consts/const-prop-read-static-in-const.stderr @@ -10,7 +10,7 @@ error: any use of this value will cause an error LL | const TEST: u8 = MY_STATIC; | -----------------^^^^^^^^^- | | - | "constants accessing static items" needs an rfc before being allowed inside constants + | constant accesses static | = note: `#[deny(const_err)]` on by default 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 044a5232e5a2..7a8c9d44e5a0 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 @@ -42,7 +42,7 @@ LL | | static FOO: AtomicUsize = AtomicUsize::new(0); LL | | unsafe { &*(&FOO as *const _ as *const usize) } LL | | LL | | }; - | |__^ "constants accessing static items" needs an rfc before being allowed inside constants + | |__^ constant accesses 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. @@ -54,7 +54,7 @@ LL | | static FOO: usize = 0; LL | | &FOO LL | | LL | | }; - | |__^ "constants accessing static items" needs an rfc before being allowed inside constants + | |__^ constant accesses 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. diff --git a/src/test/ui/issues/issue-52060.stderr b/src/test/ui/issues/issue-52060.stderr index 0b54b31abec9..c69145c1fe83 100644 --- a/src/test/ui/issues/issue-52060.stderr +++ b/src/test/ui/issues/issue-52060.stderr @@ -8,7 +8,7 @@ error[E0080]: evaluation of constant value failed --> $DIR/issue-52060.rs:4:26 | LL | static B: [u32; 1] = [0; A.len()]; - | ^ "constants accessing static items" needs an rfc before being allowed inside constants + | ^ constant accesses static error: aborting due to 2 previous errors