Skip to content

Commit 8ca5564

Browse files
committedJan 10, 2020
Clarify suggestion for E0013
1 parent 2d8d559 commit 8ca5564

7 files changed

+35
-16
lines changed
 

‎src/librustc_mir/transform/check_consts/ops.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -350,16 +350,18 @@ impl NonConstOp for StaticAccess {
350350
item.tcx.sess,
351351
span,
352352
E0013,
353-
"{}s cannot refer to statics, use \
354-
a constant instead",
353+
"{}s cannot refer to statics",
355354
item.const_kind()
356355
);
356+
err.help(
357+
"consider extracting the value of the `static` to a `const`, and referring to that",
358+
);
357359
if item.tcx.sess.teach(&err.get_code().unwrap()) {
358360
err.note(
359-
"Static and const variables can refer to other const variables. \
360-
But a const variable cannot refer to a static variable.",
361+
"`static` and `const` variables can refer to other `const` variables. \
362+
A `const` variable, however, cannot refer to a `static` variable.",
361363
);
362-
err.help("To fix this, the value can be extracted as a const and then used.");
364+
err.help("To fix this, the value can be extracted to a `const` and then used.");
363365
}
364366
err.emit();
365367
}

‎src/test/ui/consts/const-fn-not-safe-for-const.stderr

+6-2
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,21 @@ error[E0015]: calls in constant functions are limited to constant functions, tup
44
LL | random()
55
| ^^^^^^^^
66

7-
error[E0013]: constant functions cannot refer to statics, use a constant instead
7+
error[E0013]: constant functions cannot refer to statics
88
--> $DIR/const-fn-not-safe-for-const.rs:20:5
99
|
1010
LL | Y
1111
| ^
12+
|
13+
= help: consider extracting the value of the `static` to a `const`, and referring to that
1214

13-
error[E0013]: constant functions cannot refer to statics, use a constant instead
15+
error[E0013]: constant functions cannot refer to statics
1416
--> $DIR/const-fn-not-safe-for-const.rs:25:6
1517
|
1618
LL | &Y
1719
| ^
20+
|
21+
= help: consider extracting the value of the `static` to a `const`, and referring to that
1822

1923
error: aborting due to 3 previous errors
2024

‎src/test/ui/issues/issue-17718-const-bad-values.stderr

+6-2
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,21 @@ LL | const C1: &'static mut [usize] = &mut [];
77
= note: for more information, see https://github.com/rust-lang/rust/issues/57349
88
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
99

10-
error[E0013]: constants cannot refer to statics, use a constant instead
10+
error[E0013]: constants cannot refer to statics
1111
--> $DIR/issue-17718-const-bad-values.rs:5:46
1212
|
1313
LL | const C2: &'static mut usize = unsafe { &mut S };
1414
| ^
15+
|
16+
= help: consider extracting the value of the `static` to a `const`, and referring to that
1517

16-
error[E0013]: constants cannot refer to statics, use a constant instead
18+
error[E0013]: constants cannot refer to statics
1719
--> $DIR/issue-17718-const-bad-values.rs:5:46
1820
|
1921
LL | const C2: &'static mut usize = unsafe { &mut S };
2022
| ^
23+
|
24+
= help: consider extracting the value of the `static` to a `const`, and referring to that
2125

2226
error[E0658]: references in constants may only refer to immutable values
2327
--> $DIR/issue-17718-const-bad-values.rs:5:41

‎src/test/ui/issues/issue-17718-references.stderr

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
1-
error[E0013]: constants cannot refer to statics, use a constant instead
1+
error[E0013]: constants cannot refer to statics
22
--> $DIR/issue-17718-references.rs:9:29
33
|
44
LL | const T2: &'static usize = &S;
55
| ^
6+
|
7+
= help: consider extracting the value of the `static` to a `const`, and referring to that
68

7-
error[E0013]: constants cannot refer to statics, use a constant instead
9+
error[E0013]: constants cannot refer to statics
810
--> $DIR/issue-17718-references.rs:14:19
911
|
1012
LL | const T6: usize = S;
1113
| ^
14+
|
15+
= help: consider extracting the value of the `static` to a `const`, and referring to that
1216

13-
error[E0013]: constants cannot refer to statics, use a constant instead
17+
error[E0013]: constants cannot refer to statics
1418
--> $DIR/issue-17718-references.rs:19:33
1519
|
1620
LL | const T10: Struct = Struct { a: S };
1721
| ^
22+
|
23+
= help: consider extracting the value of the `static` to a `const`, and referring to that
1824

1925
error: aborting due to 3 previous errors
2026

‎src/test/ui/issues/issue-18118-2.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
pub fn main() {
22
const z: &'static isize = {
33
static p: isize = 3;
4-
&p
5-
//~^ ERROR constants cannot refer to statics, use a constant instead
4+
&p //~ ERROR constants cannot refer to statics
65
};
76
}

‎src/test/ui/issues/issue-18118-2.stderr

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
error[E0013]: constants cannot refer to statics, use a constant instead
1+
error[E0013]: constants cannot refer to statics
22
--> $DIR/issue-18118-2.rs:4:10
33
|
44
LL | &p
55
| ^
6+
|
7+
= help: consider extracting the value of the `static` to a `const`, and referring to that
68

79
error: aborting due to previous error
810

‎src/test/ui/issues/issue-52060.stderr

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
error[E0013]: constants cannot refer to statics, use a constant instead
1+
error[E0013]: constants cannot refer to statics
22
--> $DIR/issue-52060.rs:4:26
33
|
44
LL | static B: [u32; 1] = [0; A.len()];
55
| ^
6+
|
7+
= help: consider extracting the value of the `static` to a `const`, and referring to that
68

79
error[E0080]: evaluation of constant value failed
810
--> $DIR/issue-52060.rs:4:26

0 commit comments

Comments
 (0)
Please sign in to comment.