Skip to content

Commit 5e61e4c

Browse files
committed
Suggest feature for const_mut_refs errors
1 parent 681690d commit 5e61e4c

File tree

6 files changed

+41
-19
lines changed

6 files changed

+41
-19
lines changed

src/librustc_mir/transform/check_consts/ops.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,13 @@ impl NonConstOp for MutBorrow {
197197
}
198198

199199
fn emit_error(&self, item: &Item<'_, '_>, span: Span) {
200-
let mut err = struct_span_err!(item.tcx.sess, span, E0017,
201-
"references in {}s may only refer \
202-
to immutable values", item.const_kind());
200+
let mut err = feature_err(
201+
&item.tcx.sess.parse_sess,
202+
sym::const_mut_refs,
203+
span,
204+
&format!("references in {}s may only refer \
205+
to immutable values", item.const_kind())
206+
);
203207
err.span_label(span, format!("{}s require immutable values",
204208
item.const_kind()));
205209
if item.tcx.sess.teach(&err.get_code().unwrap()) {
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
error[E0017]: references in constants may only refer to immutable values
1+
error[E0658]: references in constants may only refer to immutable values
22
--> $DIR/issue-65394.rs:8:13
33
|
44
LL | let r = &mut x;
55
| ^^^^^^ constants require immutable values
6+
|
7+
= note: for more information, see https://github.com/rust-lang/rust/issues/57349
8+
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
69

710
error[E0493]: destructors cannot be evaluated at compile-time
811
--> $DIR/issue-65394.rs:7:9
@@ -12,5 +15,5 @@ LL | let mut x = Vec::<i32>::new();
1215

1316
error: aborting due to 2 previous errors
1417

15-
Some errors have detailed explanations: E0017, E0493.
16-
For more information about an error, try `rustc --explain E0017`.
18+
Some errors have detailed explanations: E0493, E0658.
19+
For more information about an error, try `rustc --explain E0493`.
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
error[E0017]: references in constants may only refer to immutable values
1+
error[E0658]: references in constants may only refer to immutable values
22
--> $DIR/const-multi-ref.rs:6:13
33
|
44
LL | let p = &mut a;
55
| ^^^^^^ constants require immutable values
6+
|
7+
= note: for more information, see https://github.com/rust-lang/rust/issues/57349
8+
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
69

710
error[E0492]: cannot borrow a constant which may contain interior mutability, create a static instead
811
--> $DIR/const-multi-ref.rs:16:13
@@ -12,5 +15,5 @@ LL | let p = &a;
1215

1316
error: aborting due to 2 previous errors
1417

15-
Some errors have detailed explanations: E0017, E0492.
16-
For more information about an error, try `rustc --explain E0017`.
18+
Some errors have detailed explanations: E0492, E0658.
19+
For more information about an error, try `rustc --explain E0492`.

src/test/ui/consts/const_let_assign3.stderr

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,23 @@ error[E0019]: constant function contains unimplemented expression type
44
LL | self.state = x;
55
| ^^^^^^^^^^^^^^
66

7-
error[E0017]: references in constants may only refer to immutable values
7+
error[E0658]: references in constants may only refer to immutable values
88
--> $DIR/const_let_assign3.rs:16:5
99
|
1010
LL | s.foo(3);
1111
| ^ constants require immutable values
12+
|
13+
= note: for more information, see https://github.com/rust-lang/rust/issues/57349
14+
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
1215

13-
error[E0017]: references in constants may only refer to immutable values
16+
error[E0658]: references in constants may only refer to immutable values
1417
--> $DIR/const_let_assign3.rs:22:13
1518
|
1619
LL | let y = &mut x;
1720
| ^^^^^^ constants require immutable values
21+
|
22+
= note: for more information, see https://github.com/rust-lang/rust/issues/57349
23+
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
1824

1925
error[E0019]: constant contains unimplemented expression type
2026
--> $DIR/const_let_assign3.rs:24:5
@@ -24,5 +30,5 @@ LL | *y = 42;
2430

2531
error: aborting due to 4 previous errors
2632

27-
Some errors have detailed explanations: E0017, E0019.
28-
For more information about an error, try `rustc --explain E0017`.
33+
Some errors have detailed explanations: E0019, E0658.
34+
For more information about an error, try `rustc --explain E0019`.

src/test/ui/consts/projection_qualif.stderr

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
error[E0017]: references in constants may only refer to immutable values
1+
error[E0658]: references in constants may only refer to immutable values
22
--> $DIR/projection_qualif.rs:6:27
33
|
44
LL | let b: *mut u32 = &mut a;
55
| ^^^^^^ constants require immutable values
6+
|
7+
= note: for more information, see https://github.com/rust-lang/rust/issues/57349
8+
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
69

710
error[E0658]: dereferencing raw pointers in constants is unstable
811
--> $DIR/projection_qualif.rs:7:18
@@ -21,5 +24,5 @@ LL | unsafe { *b = 5; }
2124

2225
error: aborting due to 3 previous errors
2326

24-
Some errors have detailed explanations: E0017, E0019, E0658.
25-
For more information about an error, try `rustc --explain E0017`.
27+
Some errors have detailed explanations: E0019, E0658.
28+
For more information about an error, try `rustc --explain E0019`.
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
error[E0017]: references in statics may only refer to immutable values
1+
error[E0658]: references in statics may only refer to immutable values
22
--> $DIR/static_mut_containing_mut_ref2.rs:3:46
33
|
44
LL | pub static mut STDERR_BUFFER: () = unsafe { *(&mut STDERR_BUFFER_SPACE) = 42; };
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ statics require immutable values
6+
|
7+
= note: for more information, see https://github.com/rust-lang/rust/issues/57349
8+
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
69

710
error[E0019]: static contains unimplemented expression type
811
--> $DIR/static_mut_containing_mut_ref2.rs:3:45
@@ -12,5 +15,5 @@ LL | pub static mut STDERR_BUFFER: () = unsafe { *(&mut STDERR_BUFFER_SPACE) = 4
1215

1316
error: aborting due to 2 previous errors
1417

15-
Some errors have detailed explanations: E0017, E0019.
16-
For more information about an error, try `rustc --explain E0017`.
18+
Some errors have detailed explanations: E0019, E0658.
19+
For more information about an error, try `rustc --explain E0019`.

0 commit comments

Comments
 (0)