Skip to content

Suggest to add missing feature when using gated const features #71902

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/librustc_mir/transform/check_consts/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
14 changes: 14 additions & 0 deletions src/test/ui/check-static-values-constraints.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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

Expand Down
9 changes: 9 additions & 0 deletions src/test/ui/const-suggest-feature.rs
Original file line number Diff line number Diff line change
@@ -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() {}
21 changes: 21 additions & 0 deletions src/test/ui/const-suggest-feature.stderr
Original file line number Diff line number Diff line change
@@ -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`.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions src/test/ui/consts/const-eval/mod-static-with-const-fn.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/test/ui/consts/const_let_assign3.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
2 changes: 2 additions & 0 deletions src/test/ui/consts/projection_qualif.stock.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions src/test/ui/error-codes/E0010-teach.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
2 changes: 2 additions & 0 deletions src/test/ui/error-codes/E0010.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions src/test/ui/error-codes/E0017.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/test/ui/error-codes/E0388.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/test/ui/issues/issue-7364.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/test/ui/static/static-mut-not-constant.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down