Rollup merge of #71902 - mibac138:const-feature-diag, r=varkor
Suggest to add missing feature when using gated const features Fixes #71797
This commit is contained in:
commit
ad74ce9d04
@ -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 \
|
||||
|
@ -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
|
||||
@ -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
|
||||
@ -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
|
||||
@ -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
|
||||
@ -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
|
||||
@ -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
|
||||
@ -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
|
||||
|
||||
|
9
src/test/ui/const-suggest-feature.rs
Normal file
9
src/test/ui/const-suggest-feature.rs
Normal file
@ -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
src/test/ui/const-suggest-feature.stderr
Normal file
21
src/test/ui/const-suggest-feature.stderr
Normal file
@ -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`.
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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.
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user