about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/librustc_mir/transform/check_consts/ops.rs3
-rw-r--r--src/test/ui/check-static-values-constraints.stderr14
-rw-r--r--src/test/ui/const-suggest-feature.rs9
-rw-r--r--src/test/ui/const-suggest-feature.stderr21
-rw-r--r--src/test/ui/consts/const-eval/assign-to-static-within-other-static-2.stderr2
-rw-r--r--src/test/ui/consts/const-eval/mod-static-with-const-fn.stderr2
-rw-r--r--src/test/ui/consts/const_let_assign3.stderr4
-rw-r--r--src/test/ui/consts/projection_qualif.stock.stderr2
-rw-r--r--src/test/ui/consts/static_mut_containing_mut_ref2.stock.stderr2
-rw-r--r--src/test/ui/error-codes/E0010-teach.stderr1
-rw-r--r--src/test/ui/error-codes/E0010.stderr2
-rw-r--r--src/test/ui/error-codes/E0017.stderr2
-rw-r--r--src/test/ui/error-codes/E0388.stderr2
-rw-r--r--src/test/ui/issues/issue-7364.stderr2
-rw-r--r--src/test/ui/static/static-mut-not-constant.stderr2
15 files changed, 70 insertions, 0 deletions
diff --git a/src/librustc_mir/transform/check_consts/ops.rs b/src/librustc_mir/transform/check_consts/ops.rs
index fe20ceb47ee..bb6e3681cc3 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 7d7ecbd1a26..6b5a739899c 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<MyOwned> = 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<isize> = 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 00000000000..89fafbbe6f0
--- /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 00000000000..6b91df6b42d
--- /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 <https://github.com/rust-lang/rust/issues/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 148b1210d39..14dcc074639 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 50cd3214507..44ae1ecf047 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 5e2a85cc03d..62fd04ea522 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 75625a4bd1b..cfa48d947c9 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 c70431886e8..cc169351bf2 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 4c9d140692a..c15ab5c655a 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<i32> = 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 48472d8acda..f49fb9c4632 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<i32> = 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 2e687c18ed3..f959ad0d008 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 52822ebdd9e..8bdfbac3681 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 1f1079555a9..efff2c24525 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<RefCell<isize>> = box RefCell::new(0);
    |                                         ^^^^^^^^^^^^^^^
+   |
+   = help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
 
 error[E0277]: `std::cell::RefCell<isize>` 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 3560be0e29e..a618b49d108 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<isize> = box 3;
    |                                ^
+   |
+   = help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
 
 error: aborting due to 2 previous errors