Skip to content

Commit ad74ce9

Browse files
authored
Rollup merge of #71902 - mibac138:const-feature-diag, r=varkor
Suggest to add missing feature when using gated const features Fixes #71797
2 parents ac84daf + 7386736 commit ad74ce9

15 files changed

+70
-0
lines changed

src/librustc_mir/transform/check_consts/ops.rs

+3
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ pub trait NonConstOp: std::fmt::Debug {
3939
"{} contains unimplemented expression type",
4040
ccx.const_kind()
4141
);
42+
if let Some(feat) = Self::feature_gate() {
43+
err.help(&format!("add `#![feature({})]` to the crate attributes to enable", feat));
44+
}
4245
if ccx.tcx.sess.teach(&err.get_code().unwrap()) {
4346
err.note(
4447
"A function call isn't allowed in the const's initialization expression \

src/test/ui/check-static-values-constraints.stderr

+14
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ error[E0019]: static contains unimplemented expression type
1818
|
1919
LL | static STATIC11: Box<MyOwned> = box MyOwned;
2020
| ^^^^^^^
21+
|
22+
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
2123

2224
error[E0015]: calls in statics are limited to constant functions, tuple structs and tuple variants
2325
--> $DIR/check-static-values-constraints.rs:90:32
@@ -36,6 +38,8 @@ error[E0019]: static contains unimplemented expression type
3638
|
3739
LL | box MyOwned,
3840
| ^^^^^^^
41+
|
42+
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
3943

4044
error[E0010]: allocations are not allowed in statics
4145
--> $DIR/check-static-values-constraints.rs:97:5
@@ -48,6 +52,8 @@ error[E0019]: static contains unimplemented expression type
4852
|
4953
LL | box MyOwned,
5054
| ^^^^^^^
55+
|
56+
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
5157

5258
error[E0010]: allocations are not allowed in statics
5359
--> $DIR/check-static-values-constraints.rs:102:6
@@ -60,6 +66,8 @@ error[E0019]: static contains unimplemented expression type
6066
|
6167
LL | &box MyOwned,
6268
| ^^^^^^^
69+
|
70+
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
6371

6472
error[E0010]: allocations are not allowed in statics
6573
--> $DIR/check-static-values-constraints.rs:104:6
@@ -72,6 +80,8 @@ error[E0019]: static contains unimplemented expression type
7280
|
7381
LL | &box MyOwned,
7482
| ^^^^^^^
83+
|
84+
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
7585

7686
error[E0010]: allocations are not allowed in statics
7787
--> $DIR/check-static-values-constraints.rs:111:5
@@ -84,6 +94,8 @@ error[E0019]: static contains unimplemented expression type
8494
|
8595
LL | box 3;
8696
| ^
97+
|
98+
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
8799

88100
error[E0507]: cannot move out of static item `x`
89101
--> $DIR/check-static-values-constraints.rs:116:45
@@ -105,6 +117,8 @@ error[E0019]: static contains unimplemented expression type
105117
|
106118
LL | let y = { static x: Box<isize> = box 3; x };
107119
| ^
120+
|
121+
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
108122

109123
error: aborting due to 17 previous errors
110124

src/test/ui/const-suggest-feature.rs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const WRITE: () = unsafe {
2+
*std::ptr::null_mut() = 0;
3+
//~^ ERROR dereferencing raw pointers in constants is unstable
4+
//~| HELP add `#![feature(const_raw_ptr_deref)]` to the crate attributes to enable
5+
//~| ERROR constant contains unimplemented expression type
6+
//~| HELP add `#![feature(const_mut_refs)]` to the crate attributes to enable
7+
};
8+
9+
fn main() {}
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
error[E0658]: dereferencing raw pointers in constants is unstable
2+
--> $DIR/const-suggest-feature.rs:2:5
3+
|
4+
LL | *std::ptr::null_mut() = 0;
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: see issue #51911 <https://github.com/rust-lang/rust/issues/51911> for more information
8+
= help: add `#![feature(const_raw_ptr_deref)]` to the crate attributes to enable
9+
10+
error[E0019]: constant contains unimplemented expression type
11+
--> $DIR/const-suggest-feature.rs:2:5
12+
|
13+
LL | *std::ptr::null_mut() = 0;
14+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
15+
|
16+
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
17+
18+
error: aborting due to 2 previous errors
19+
20+
Some errors have detailed explanations: E0019, E0658.
21+
For more information about an error, try `rustc --explain E0019`.

src/test/ui/consts/const-eval/assign-to-static-within-other-static-2.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ error[E0019]: static contains unimplemented expression type
33
|
44
LL | *FOO.0.get() = 5;
55
| ^^^^^^^^^^^^^^^^
6+
|
7+
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
68

79
error: aborting due to previous error
810

src/test/ui/consts/const-eval/mod-static-with-const-fn.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ error[E0019]: static contains unimplemented expression type
33
|
44
LL | *FOO.0.get() = 5;
55
| ^^^^^^^^^^^^^^^^
6+
|
7+
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
68

79
error[E0015]: calls in statics are limited to constant functions, tuple structs and tuple variants
810
--> $DIR/mod-static-with-const-fn.rs:21:5

src/test/ui/consts/const_let_assign3.stderr

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ error[E0019]: constant function contains unimplemented expression type
33
|
44
LL | self.state = x;
55
| ^^^^^^^^^^^^^^
6+
|
7+
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
68

79
error[E0658]: references in constants may only refer to immutable values
810
--> $DIR/const_let_assign3.rs:16:5
@@ -27,6 +29,8 @@ error[E0019]: constant contains unimplemented expression type
2729
|
2830
LL | *y = 42;
2931
| ^^^^^^^
32+
|
33+
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
3034

3135
error: aborting due to 4 previous errors
3236

src/test/ui/consts/projection_qualif.stock.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ error[E0019]: constant contains unimplemented expression type
2121
|
2222
LL | unsafe { *b = 5; }
2323
| ^^^^^^
24+
|
25+
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
2426

2527
error: aborting due to 3 previous errors
2628

src/test/ui/consts/static_mut_containing_mut_ref2.stock.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ error[E0019]: static contains unimplemented expression type
1212
|
1313
LL | pub static mut STDERR_BUFFER: () = unsafe { *(&mut STDERR_BUFFER_SPACE) = 42; };
1414
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15+
|
16+
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
1517

1618
error: aborting due to 2 previous errors
1719

src/test/ui/error-codes/E0010-teach.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ error[E0019]: constant contains unimplemented expression type
1212
LL | const CON : Box<i32> = box 0;
1313
| ^
1414
|
15+
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
1516
= note: A function call isn't allowed in the const's initialization expression because the expression's value must be known at compile-time.
1617
= note: Remember: you can't use a function call inside a const's initialization expression! However, you can use it anywhere else.
1718

src/test/ui/error-codes/E0010.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ error[E0019]: constant contains unimplemented expression type
99
|
1010
LL | const CON : Box<i32> = box 0;
1111
| ^
12+
|
13+
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
1214

1315
error: aborting due to 2 previous errors
1416

src/test/ui/error-codes/E0017.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ error[E0019]: static contains unimplemented expression type
1212
|
1313
LL | static STATIC_REF: &'static mut i32 = &mut X;
1414
| ^^^^^^
15+
|
16+
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
1517

1618
error[E0658]: references in statics may only refer to immutable values
1719
--> $DIR/E0017.rs:6:39

src/test/ui/error-codes/E0388.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ error[E0019]: static contains unimplemented expression type
1212
|
1313
LL | static STATIC_REF: &'static mut i32 = &mut X;
1414
| ^^^^^^
15+
|
16+
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
1517

1618
error[E0658]: references in statics may only refer to immutable values
1719
--> $DIR/E0388.rs:5:39

src/test/ui/issues/issue-7364.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ error[E0019]: static contains unimplemented expression type
99
|
1010
LL | static boxed: Box<RefCell<isize>> = box RefCell::new(0);
1111
| ^^^^^^^^^^^^^^^
12+
|
13+
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
1214

1315
error[E0277]: `std::cell::RefCell<isize>` cannot be shared between threads safely
1416
--> $DIR/issue-7364.rs:6:1

src/test/ui/static/static-mut-not-constant.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ error[E0019]: static contains unimplemented expression type
99
|
1010
LL | static mut a: Box<isize> = box 3;
1111
| ^
12+
|
13+
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
1214

1315
error: aborting due to 2 previous errors
1416

0 commit comments

Comments
 (0)