about summary refs log tree commit diff
diff options
context:
space:
mode:
authorvarkor <github@varkor.com>2020-01-10 13:31:36 +0000
committervarkor <github@varkor.com>2020-01-10 13:31:36 +0000
commit8ca55641fd80ac51971997f903358fa579209d71 (patch)
treece15e75d3207f2c927ff1d14b699ad757951ca08
parent2d8d559bbecf6272eb41f8a800e319238aa9d621 (diff)
downloadrust-8ca55641fd80ac51971997f903358fa579209d71.tar.gz
rust-8ca55641fd80ac51971997f903358fa579209d71.zip
Clarify suggestion for E0013
-rw-r--r--src/librustc_mir/transform/check_consts/ops.rs12
-rw-r--r--src/test/ui/consts/const-fn-not-safe-for-const.stderr8
-rw-r--r--src/test/ui/issues/issue-17718-const-bad-values.stderr8
-rw-r--r--src/test/ui/issues/issue-17718-references.stderr12
-rw-r--r--src/test/ui/issues/issue-18118-2.rs3
-rw-r--r--src/test/ui/issues/issue-18118-2.stderr4
-rw-r--r--src/test/ui/issues/issue-52060.stderr4
7 files changed, 35 insertions, 16 deletions
diff --git a/src/librustc_mir/transform/check_consts/ops.rs b/src/librustc_mir/transform/check_consts/ops.rs
index abef008a8ec..e4188092827 100644
--- a/src/librustc_mir/transform/check_consts/ops.rs
+++ b/src/librustc_mir/transform/check_consts/ops.rs
@@ -350,16 +350,18 @@ impl NonConstOp for StaticAccess {
             item.tcx.sess,
             span,
             E0013,
-            "{}s cannot refer to statics, use \
-                                        a constant instead",
+            "{}s cannot refer to statics",
             item.const_kind()
         );
+        err.help(
+            "consider extracting the value of the `static` to a `const`, and referring to that",
+        );
         if item.tcx.sess.teach(&err.get_code().unwrap()) {
             err.note(
-                "Static and const variables can refer to other const variables. \
-                    But a const variable cannot refer to a static variable.",
+                "`static` and `const` variables can refer to other `const` variables. \
+                    A `const` variable, however, cannot refer to a `static` variable.",
             );
-            err.help("To fix this, the value can be extracted as a const and then used.");
+            err.help("To fix this, the value can be extracted to a `const` and then used.");
         }
         err.emit();
     }
diff --git a/src/test/ui/consts/const-fn-not-safe-for-const.stderr b/src/test/ui/consts/const-fn-not-safe-for-const.stderr
index 2d4175ea8eb..df793d7dd7e 100644
--- a/src/test/ui/consts/const-fn-not-safe-for-const.stderr
+++ b/src/test/ui/consts/const-fn-not-safe-for-const.stderr
@@ -4,17 +4,21 @@ error[E0015]: calls in constant functions are limited to constant functions, tup
 LL |     random()
    |     ^^^^^^^^
 
-error[E0013]: constant functions cannot refer to statics, use a constant instead
+error[E0013]: constant functions cannot refer to statics
   --> $DIR/const-fn-not-safe-for-const.rs:20:5
    |
 LL |     Y
    |     ^
+   |
+   = help: consider extracting the value of the `static` to a `const`, and referring to that
 
-error[E0013]: constant functions cannot refer to statics, use a constant instead
+error[E0013]: constant functions cannot refer to statics
   --> $DIR/const-fn-not-safe-for-const.rs:25:6
    |
 LL |     &Y
    |      ^
+   |
+   = help: consider extracting the value of the `static` to a `const`, and referring to that
 
 error: aborting due to 3 previous errors
 
diff --git a/src/test/ui/issues/issue-17718-const-bad-values.stderr b/src/test/ui/issues/issue-17718-const-bad-values.stderr
index 14bf5dc38b4..e45d8b6c740 100644
--- a/src/test/ui/issues/issue-17718-const-bad-values.stderr
+++ b/src/test/ui/issues/issue-17718-const-bad-values.stderr
@@ -7,17 +7,21 @@ LL | const C1: &'static mut [usize] = &mut [];
    = note: for more information, see https://github.com/rust-lang/rust/issues/57349
    = help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
 
-error[E0013]: constants cannot refer to statics, use a constant instead
+error[E0013]: constants cannot refer to statics
   --> $DIR/issue-17718-const-bad-values.rs:5:46
    |
 LL | const C2: &'static mut usize = unsafe { &mut S };
    |                                              ^
+   |
+   = help: consider extracting the value of the `static` to a `const`, and referring to that
 
-error[E0013]: constants cannot refer to statics, use a constant instead
+error[E0013]: constants cannot refer to statics
   --> $DIR/issue-17718-const-bad-values.rs:5:46
    |
 LL | const C2: &'static mut usize = unsafe { &mut S };
    |                                              ^
+   |
+   = help: consider extracting the value of the `static` to a `const`, and referring to that
 
 error[E0658]: references in constants may only refer to immutable values
   --> $DIR/issue-17718-const-bad-values.rs:5:41
diff --git a/src/test/ui/issues/issue-17718-references.stderr b/src/test/ui/issues/issue-17718-references.stderr
index 27aad9c03ce..e3c3b369ffb 100644
--- a/src/test/ui/issues/issue-17718-references.stderr
+++ b/src/test/ui/issues/issue-17718-references.stderr
@@ -1,20 +1,26 @@
-error[E0013]: constants cannot refer to statics, use a constant instead
+error[E0013]: constants cannot refer to statics
   --> $DIR/issue-17718-references.rs:9:29
    |
 LL | const T2: &'static usize = &S;
    |                             ^
+   |
+   = help: consider extracting the value of the `static` to a `const`, and referring to that
 
-error[E0013]: constants cannot refer to statics, use a constant instead
+error[E0013]: constants cannot refer to statics
   --> $DIR/issue-17718-references.rs:14:19
    |
 LL | const T6: usize = S;
    |                   ^
+   |
+   = help: consider extracting the value of the `static` to a `const`, and referring to that
 
-error[E0013]: constants cannot refer to statics, use a constant instead
+error[E0013]: constants cannot refer to statics
   --> $DIR/issue-17718-references.rs:19:33
    |
 LL | const T10: Struct = Struct { a: S };
    |                                 ^
+   |
+   = help: consider extracting the value of the `static` to a `const`, and referring to that
 
 error: aborting due to 3 previous errors
 
diff --git a/src/test/ui/issues/issue-18118-2.rs b/src/test/ui/issues/issue-18118-2.rs
index 6d52156b3d2..f712a2eedb7 100644
--- a/src/test/ui/issues/issue-18118-2.rs
+++ b/src/test/ui/issues/issue-18118-2.rs
@@ -1,7 +1,6 @@
 pub fn main() {
     const z: &'static isize = {
         static p: isize = 3;
-        &p
-        //~^ ERROR constants cannot refer to statics, use a constant instead
+        &p //~ ERROR constants cannot refer to statics
     };
 }
diff --git a/src/test/ui/issues/issue-18118-2.stderr b/src/test/ui/issues/issue-18118-2.stderr
index d58822f16eb..4fc3ca78f96 100644
--- a/src/test/ui/issues/issue-18118-2.stderr
+++ b/src/test/ui/issues/issue-18118-2.stderr
@@ -1,8 +1,10 @@
-error[E0013]: constants cannot refer to statics, use a constant instead
+error[E0013]: constants cannot refer to statics
   --> $DIR/issue-18118-2.rs:4:10
    |
 LL |         &p
    |          ^
+   |
+   = help: consider extracting the value of the `static` to a `const`, and referring to that
 
 error: aborting due to previous error
 
diff --git a/src/test/ui/issues/issue-52060.stderr b/src/test/ui/issues/issue-52060.stderr
index c69145c1fe8..502825e9766 100644
--- a/src/test/ui/issues/issue-52060.stderr
+++ b/src/test/ui/issues/issue-52060.stderr
@@ -1,8 +1,10 @@
-error[E0013]: constants cannot refer to statics, use a constant instead
+error[E0013]: constants cannot refer to statics
   --> $DIR/issue-52060.rs:4:26
    |
 LL | static B: [u32; 1] = [0; A.len()];
    |                          ^
+   |
+   = help: consider extracting the value of the `static` to a `const`, and referring to that
 
 error[E0080]: evaluation of constant value failed
   --> $DIR/issue-52060.rs:4:26