diff --git a/src/librustc_mir/transform/check_consts/ops.rs b/src/librustc_mir/transform/check_consts/ops.rs index fe20ceb47ee37..bb6e3681cc3c1 100644 --- a/src/librustc_mir/transform/check_consts/ops.rs +++ b/src/librustc_mir/transform/check_consts/ops.rs @@ -39,6 +39,9 @@ pub trait NonConstOp: std::fmt::Debug { "{} contains unimplemented expression type", ccx.const_kind() ); + if let Some(feat) = Self::feature_gate() { + err.help(&format!("add `#![feature({})]` to the crate attributes to enable", feat)); + } if ccx.tcx.sess.teach(&err.get_code().unwrap()) { err.note( "A function call isn't allowed in the const's initialization expression \ diff --git a/src/test/ui/check-static-values-constraints.stderr b/src/test/ui/check-static-values-constraints.stderr index 7d7ecbd1a26a5..6b5a739899cac 100644 --- a/src/test/ui/check-static-values-constraints.stderr +++ b/src/test/ui/check-static-values-constraints.stderr @@ -18,6 +18,8 @@ error[E0019]: static contains unimplemented expression type | LL | static STATIC11: Box = box MyOwned; | ^^^^^^^ + | + = help: add `#![feature(const_mut_refs)]` to the crate attributes to enable error[E0015]: calls in statics are limited to constant functions, tuple structs and tuple variants --> $DIR/check-static-values-constraints.rs:90:32 @@ -36,6 +38,8 @@ error[E0019]: static contains unimplemented expression type | LL | box MyOwned, | ^^^^^^^ + | + = help: add `#![feature(const_mut_refs)]` to the crate attributes to enable error[E0010]: allocations are not allowed in statics --> $DIR/check-static-values-constraints.rs:97:5 @@ -48,6 +52,8 @@ error[E0019]: static contains unimplemented expression type | LL | box MyOwned, | ^^^^^^^ + | + = help: add `#![feature(const_mut_refs)]` to the crate attributes to enable error[E0010]: allocations are not allowed in statics --> $DIR/check-static-values-constraints.rs:102:6 @@ -60,6 +66,8 @@ error[E0019]: static contains unimplemented expression type | LL | &box MyOwned, | ^^^^^^^ + | + = help: add `#![feature(const_mut_refs)]` to the crate attributes to enable error[E0010]: allocations are not allowed in statics --> $DIR/check-static-values-constraints.rs:104:6 @@ -72,6 +80,8 @@ error[E0019]: static contains unimplemented expression type | LL | &box MyOwned, | ^^^^^^^ + | + = help: add `#![feature(const_mut_refs)]` to the crate attributes to enable error[E0010]: allocations are not allowed in statics --> $DIR/check-static-values-constraints.rs:111:5 @@ -84,6 +94,8 @@ error[E0019]: static contains unimplemented expression type | LL | box 3; | ^ + | + = help: add `#![feature(const_mut_refs)]` to the crate attributes to enable error[E0507]: cannot move out of static item `x` --> $DIR/check-static-values-constraints.rs:116:45 @@ -105,6 +117,8 @@ error[E0019]: static contains unimplemented expression type | LL | let y = { static x: Box = box 3; x }; | ^ + | + = help: add `#![feature(const_mut_refs)]` to the crate attributes to enable error: aborting due to 17 previous errors diff --git a/src/test/ui/const-suggest-feature.rs b/src/test/ui/const-suggest-feature.rs new file mode 100644 index 0000000000000..89fafbbe6f044 --- /dev/null +++ b/src/test/ui/const-suggest-feature.rs @@ -0,0 +1,9 @@ +const WRITE: () = unsafe { + *std::ptr::null_mut() = 0; + //~^ ERROR dereferencing raw pointers in constants is unstable + //~| HELP add `#![feature(const_raw_ptr_deref)]` to the crate attributes to enable + //~| ERROR constant contains unimplemented expression type + //~| HELP add `#![feature(const_mut_refs)]` to the crate attributes to enable +}; + +fn main() {} diff --git a/src/test/ui/const-suggest-feature.stderr b/src/test/ui/const-suggest-feature.stderr new file mode 100644 index 0000000000000..6b91df6b42d91 --- /dev/null +++ b/src/test/ui/const-suggest-feature.stderr @@ -0,0 +1,21 @@ +error[E0658]: dereferencing raw pointers in constants is unstable + --> $DIR/const-suggest-feature.rs:2:5 + | +LL | *std::ptr::null_mut() = 0; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: see issue #51911 for more information + = help: add `#![feature(const_raw_ptr_deref)]` to the crate attributes to enable + +error[E0019]: constant contains unimplemented expression type + --> $DIR/const-suggest-feature.rs:2:5 + | +LL | *std::ptr::null_mut() = 0; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: add `#![feature(const_mut_refs)]` to the crate attributes to enable + +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0019, E0658. +For more information about an error, try `rustc --explain E0019`. diff --git a/src/test/ui/consts/const-eval/assign-to-static-within-other-static-2.stderr b/src/test/ui/consts/const-eval/assign-to-static-within-other-static-2.stderr index 148b1210d39e1..14dcc074639e5 100644 --- a/src/test/ui/consts/const-eval/assign-to-static-within-other-static-2.stderr +++ b/src/test/ui/consts/const-eval/assign-to-static-within-other-static-2.stderr @@ -3,6 +3,8 @@ error[E0019]: static contains unimplemented expression type | LL | *FOO.0.get() = 5; | ^^^^^^^^^^^^^^^^ + | + = help: add `#![feature(const_mut_refs)]` to the crate attributes to enable error: aborting due to previous error diff --git a/src/test/ui/consts/const-eval/mod-static-with-const-fn.stderr b/src/test/ui/consts/const-eval/mod-static-with-const-fn.stderr index 50cd3214507a3..44ae1ecf04718 100644 --- a/src/test/ui/consts/const-eval/mod-static-with-const-fn.stderr +++ b/src/test/ui/consts/const-eval/mod-static-with-const-fn.stderr @@ -3,6 +3,8 @@ error[E0019]: static contains unimplemented expression type | LL | *FOO.0.get() = 5; | ^^^^^^^^^^^^^^^^ + | + = help: add `#![feature(const_mut_refs)]` to the crate attributes to enable error[E0015]: calls in statics are limited to constant functions, tuple structs and tuple variants --> $DIR/mod-static-with-const-fn.rs:21:5 diff --git a/src/test/ui/consts/const_let_assign3.stderr b/src/test/ui/consts/const_let_assign3.stderr index 5e2a85cc03d9f..62fd04ea522c3 100644 --- a/src/test/ui/consts/const_let_assign3.stderr +++ b/src/test/ui/consts/const_let_assign3.stderr @@ -3,6 +3,8 @@ error[E0019]: constant function contains unimplemented expression type | LL | self.state = x; | ^^^^^^^^^^^^^^ + | + = help: add `#![feature(const_mut_refs)]` to the crate attributes to enable error[E0658]: references in constants may only refer to immutable values --> $DIR/const_let_assign3.rs:16:5 @@ -27,6 +29,8 @@ error[E0019]: constant contains unimplemented expression type | LL | *y = 42; | ^^^^^^^ + | + = help: add `#![feature(const_mut_refs)]` to the crate attributes to enable error: aborting due to 4 previous errors diff --git a/src/test/ui/consts/projection_qualif.stock.stderr b/src/test/ui/consts/projection_qualif.stock.stderr index 75625a4bd1bc3..cfa48d947c992 100644 --- a/src/test/ui/consts/projection_qualif.stock.stderr +++ b/src/test/ui/consts/projection_qualif.stock.stderr @@ -21,6 +21,8 @@ error[E0019]: constant contains unimplemented expression type | LL | unsafe { *b = 5; } | ^^^^^^ + | + = help: add `#![feature(const_mut_refs)]` to the crate attributes to enable error: aborting due to 3 previous errors diff --git a/src/test/ui/consts/static_mut_containing_mut_ref2.stock.stderr b/src/test/ui/consts/static_mut_containing_mut_ref2.stock.stderr index c70431886e868..cc169351bf268 100644 --- a/src/test/ui/consts/static_mut_containing_mut_ref2.stock.stderr +++ b/src/test/ui/consts/static_mut_containing_mut_ref2.stock.stderr @@ -12,6 +12,8 @@ error[E0019]: static contains unimplemented expression type | LL | pub static mut STDERR_BUFFER: () = unsafe { *(&mut STDERR_BUFFER_SPACE) = 42; }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: add `#![feature(const_mut_refs)]` to the crate attributes to enable error: aborting due to 2 previous errors diff --git a/src/test/ui/error-codes/E0010-teach.stderr b/src/test/ui/error-codes/E0010-teach.stderr index 4c9d140692ad0..c15ab5c655a46 100644 --- a/src/test/ui/error-codes/E0010-teach.stderr +++ b/src/test/ui/error-codes/E0010-teach.stderr @@ -12,6 +12,7 @@ error[E0019]: constant contains unimplemented expression type LL | const CON : Box = box 0; | ^ | + = help: add `#![feature(const_mut_refs)]` to the crate attributes to enable = note: A function call isn't allowed in the const's initialization expression because the expression's value must be known at compile-time. = note: Remember: you can't use a function call inside a const's initialization expression! However, you can use it anywhere else. diff --git a/src/test/ui/error-codes/E0010.stderr b/src/test/ui/error-codes/E0010.stderr index 48472d8acda38..f49fb9c46326b 100644 --- a/src/test/ui/error-codes/E0010.stderr +++ b/src/test/ui/error-codes/E0010.stderr @@ -9,6 +9,8 @@ error[E0019]: constant contains unimplemented expression type | LL | const CON : Box = box 0; | ^ + | + = help: add `#![feature(const_mut_refs)]` to the crate attributes to enable error: aborting due to 2 previous errors diff --git a/src/test/ui/error-codes/E0017.stderr b/src/test/ui/error-codes/E0017.stderr index 2e687c18ed3ff..f959ad0d00887 100644 --- a/src/test/ui/error-codes/E0017.stderr +++ b/src/test/ui/error-codes/E0017.stderr @@ -12,6 +12,8 @@ error[E0019]: static contains unimplemented expression type | LL | static STATIC_REF: &'static mut i32 = &mut X; | ^^^^^^ + | + = help: add `#![feature(const_mut_refs)]` to the crate attributes to enable error[E0658]: references in statics may only refer to immutable values --> $DIR/E0017.rs:6:39 diff --git a/src/test/ui/error-codes/E0388.stderr b/src/test/ui/error-codes/E0388.stderr index 52822ebdd9e67..8bdfbac36816b 100644 --- a/src/test/ui/error-codes/E0388.stderr +++ b/src/test/ui/error-codes/E0388.stderr @@ -12,6 +12,8 @@ error[E0019]: static contains unimplemented expression type | LL | static STATIC_REF: &'static mut i32 = &mut X; | ^^^^^^ + | + = help: add `#![feature(const_mut_refs)]` to the crate attributes to enable error[E0658]: references in statics may only refer to immutable values --> $DIR/E0388.rs:5:39 diff --git a/src/test/ui/issues/issue-7364.stderr b/src/test/ui/issues/issue-7364.stderr index 1f1079555a91f..efff2c24525e8 100644 --- a/src/test/ui/issues/issue-7364.stderr +++ b/src/test/ui/issues/issue-7364.stderr @@ -9,6 +9,8 @@ error[E0019]: static contains unimplemented expression type | LL | static boxed: Box> = box RefCell::new(0); | ^^^^^^^^^^^^^^^ + | + = help: add `#![feature(const_mut_refs)]` to the crate attributes to enable error[E0277]: `std::cell::RefCell` cannot be shared between threads safely --> $DIR/issue-7364.rs:6:1 diff --git a/src/test/ui/static/static-mut-not-constant.stderr b/src/test/ui/static/static-mut-not-constant.stderr index 3560be0e29e43..a618b49d1089e 100644 --- a/src/test/ui/static/static-mut-not-constant.stderr +++ b/src/test/ui/static/static-mut-not-constant.stderr @@ -9,6 +9,8 @@ error[E0019]: static contains unimplemented expression type | LL | static mut a: Box = box 3; | ^ + | + = help: add `#![feature(const_mut_refs)]` to the crate attributes to enable error: aborting due to 2 previous errors