Rollup merge of #87020 - RalfJung:const_raw_ptr_to_usize_cast, r=oli-obk
remove const_raw_ptr_to_usize_cast feature This feature currently has the strange status of "const-only `unsafe`", which was an experiment that we no longer think is a good idea. We need to find better ways to enable things like "messing with the low bits of a pointer" during CTFE. r? `@oli-obk`
This commit is contained in:
commit
ad2a0fc93f
33 changed files with 65 additions and 331 deletions
|
|
@ -1,19 +0,0 @@
|
|||
error[E0133]: cast of pointer to int is unsafe and requires unsafe function or block
|
||||
--> $DIR/cast-ptr-to-int-const.rs:10:9
|
||||
|
|
||||
LL | &Y as *const u32 as usize
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ cast of pointer to int
|
||||
|
|
||||
= note: casting pointers to integers in constants
|
||||
|
||||
error[E0133]: cast of pointer to int is unsafe and requires unsafe function or block
|
||||
--> $DIR/cast-ptr-to-int-const.rs:17:5
|
||||
|
|
||||
LL | &0 as *const i32 as usize
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ cast of pointer to int
|
||||
|
|
||||
= note: casting pointers to integers in constants
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0133`.
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
// revisions: mir thir
|
||||
// [thir]compile-flags: -Z thir-unsafeck
|
||||
|
||||
#![feature(const_raw_ptr_to_usize_cast)]
|
||||
|
||||
fn main() {
|
||||
const Y: u32 = 0;
|
||||
// Cast in `const` without `unsafe` block
|
||||
const SAFE: usize = {
|
||||
&Y as *const u32 as usize
|
||||
//~^ ERROR cast of pointer to int is unsafe and requires unsafe
|
||||
};
|
||||
}
|
||||
|
||||
// Cast in `const fn` without `unsafe` block
|
||||
const fn test() -> usize {
|
||||
&0 as *const i32 as usize
|
||||
//~^ ERROR cast of pointer to int is unsafe and requires unsafe
|
||||
}
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
error[E0133]: cast of pointer to int is unsafe and requires unsafe function or block
|
||||
--> $DIR/cast-ptr-to-int-const.rs:10:9
|
||||
|
|
||||
LL | &Y as *const u32 as usize
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ cast of pointer to int
|
||||
|
|
||||
= note: casting pointers to integers in constants
|
||||
|
||||
error[E0133]: cast of pointer to int is unsafe and requires unsafe function or block
|
||||
--> $DIR/cast-ptr-to-int-const.rs:17:5
|
||||
|
|
||||
LL | &0 as *const i32 as usize
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ cast of pointer to int
|
||||
|
|
||||
= note: casting pointers to integers in constants
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0133`.
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
fn main() {
|
||||
const X: usize = unsafe {
|
||||
main as usize //~ ERROR casting pointers to integers in constants is unstable
|
||||
};
|
||||
const Y: u32 = 0;
|
||||
const Z: usize = unsafe {
|
||||
&Y as *const u32 as usize //~ ERROR is unstable
|
||||
};
|
||||
}
|
||||
|
||||
const fn test() -> usize {
|
||||
&0 as *const i32 as usize //~ ERROR is unstable
|
||||
}
|
||||
|
|
@ -1,30 +0,0 @@
|
|||
error[E0658]: casting pointers to integers in constants is unstable
|
||||
--> $DIR/feature-gate-const_raw_ptr_to_usize_cast.rs:3:9
|
||||
|
|
||||
LL | main as usize
|
||||
| ^^^^^^^^^^^^^
|
||||
|
|
||||
= note: see issue #51910 <https://github.com/rust-lang/rust/issues/51910> for more information
|
||||
= help: add `#![feature(const_raw_ptr_to_usize_cast)]` to the crate attributes to enable
|
||||
|
||||
error[E0658]: casting pointers to integers in constants is unstable
|
||||
--> $DIR/feature-gate-const_raw_ptr_to_usize_cast.rs:7:9
|
||||
|
|
||||
LL | &Y as *const u32 as usize
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: see issue #51910 <https://github.com/rust-lang/rust/issues/51910> for more information
|
||||
= help: add `#![feature(const_raw_ptr_to_usize_cast)]` to the crate attributes to enable
|
||||
|
||||
error[E0658]: casting pointers to integers in constant functions is unstable
|
||||
--> $DIR/feature-gate-const_raw_ptr_to_usize_cast.rs:12:5
|
||||
|
|
||||
LL | &0 as *const i32 as usize
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: see issue #51910 <https://github.com/rust-lang/rust/issues/51910> for more information
|
||||
= help: add `#![feature(const_raw_ptr_to_usize_cast)]` to the crate attributes to enable
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0658`.
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
#![feature(const_raw_ptr_to_usize_cast)]
|
||||
|
||||
fn main() {
|
||||
const OK: usize = unsafe { 0 as *const i32 as usize };
|
||||
|
||||
const _ERROR: usize = unsafe { &0 as *const i32 as usize };
|
||||
//~^ ERROR [const_err]
|
||||
//~| NOTE cannot cast pointer to integer because it was not created by cast from integer
|
||||
//~| NOTE
|
||||
//~| NOTE `#[deny(const_err)]` on by default
|
||||
//~| WARN this was previously accepted by the compiler but is being phased out
|
||||
//~| NOTE see issue #71800
|
||||
}
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
error: any use of this value will cause an error
|
||||
--> $DIR/ptr_to_usize_cast.rs:6:36
|
||||
|
|
||||
LL | const _ERROR: usize = unsafe { &0 as *const i32 as usize };
|
||||
| -------------------------------^^^^^^^^^^^^^^^^^^^^^^^^^---
|
||||
| |
|
||||
| cannot cast pointer to integer because it was not created by cast from integer
|
||||
|
|
||||
= note: `#[deny(const_err)]` on by default
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
@ -1,15 +1,11 @@
|
|||
#![feature(const_raw_ptr_to_usize_cast, const_raw_ptr_deref)]
|
||||
#![feature(const_raw_ptr_deref)]
|
||||
|
||||
fn main() {}
|
||||
|
||||
// unconst and fine
|
||||
const Y: usize = unsafe { 42usize as *const i32 as usize + 1 };
|
||||
// unconst and bad, will thus error in miri
|
||||
const Y2: usize = unsafe { &1 as *const i32 as usize + 1 }; //~ ERROR any use of this
|
||||
//~| WARN this was previously accepted by the compiler but is being phased out
|
||||
// unconst and fine
|
||||
// fine
|
||||
const Z: i32 = unsafe { *(&1 as *const i32) };
|
||||
// unconst and bad, will thus error in miri
|
||||
|
||||
// bad, will thus error in miri
|
||||
const Z2: i32 = unsafe { *(42 as *const i32) }; //~ ERROR any use of this value will cause
|
||||
//~| WARN this was previously accepted by the compiler but is being phased out
|
||||
const Z3: i32 = unsafe { *(44 as *const i32) }; //~ ERROR any use of this value will cause
|
||||
|
|
|
|||
|
|
@ -1,28 +1,17 @@
|
|||
error: any use of this value will cause an error
|
||||
--> $DIR/const_raw_ptr_ops2.rs:8:28
|
||||
|
|
||||
LL | const Y2: usize = unsafe { &1 as *const i32 as usize + 1 };
|
||||
| ---------------------------^^^^^^^^^^^^^^^^^^^^^^^^^-------
|
||||
| |
|
||||
| cannot cast pointer to integer because it was not created by cast from integer
|
||||
|
|
||||
= note: `#[deny(const_err)]` on by default
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
|
||||
|
||||
error: any use of this value will cause an error
|
||||
--> $DIR/const_raw_ptr_ops2.rs:13:26
|
||||
--> $DIR/const_raw_ptr_ops2.rs:9:26
|
||||
|
|
||||
LL | const Z2: i32 = unsafe { *(42 as *const i32) };
|
||||
| -------------------------^^^^^^^^^^^^^^^^^^^---
|
||||
| |
|
||||
| unable to turn bytes into a pointer
|
||||
|
|
||||
= note: `#[deny(const_err)]` on by default
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
|
||||
|
||||
error: any use of this value will cause an error
|
||||
--> $DIR/const_raw_ptr_ops2.rs:15:26
|
||||
--> $DIR/const_raw_ptr_ops2.rs:11:26
|
||||
|
|
||||
LL | const Z3: i32 = unsafe { *(44 as *const i32) };
|
||||
| -------------------------^^^^^^^^^^^^^^^^^^^---
|
||||
|
|
@ -32,5 +21,5 @@ LL | const Z3: i32 = unsafe { *(44 as *const i32) };
|
|||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +0,0 @@
|
|||
fn main() {
|
||||
[(); { &loop { break } as *const _ as usize } ];
|
||||
//~^ ERROR casting pointers to integers in constants is unstable
|
||||
}
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
error[E0658]: casting pointers to integers in constants is unstable
|
||||
--> $DIR/issue-52442.rs:2:13
|
||||
|
|
||||
LL | [(); { &loop { break } as *const _ as usize } ];
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: see issue #51910 <https://github.com/rust-lang/rust/issues/51910> for more information
|
||||
= help: add `#![feature(const_raw_ptr_to_usize_cast)]` to the crate attributes to enable
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0658`.
|
||||
|
|
@ -4,7 +4,7 @@ fn main() {
|
|||
// bytes.
|
||||
let _: [u8; 0] = [4; {
|
||||
match &1 as *const i32 as usize {
|
||||
//~^ ERROR casting pointers to integers in constants
|
||||
//~^ ERROR pointers cannot be cast to integers during const eval
|
||||
0 => 42,
|
||||
n => n,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,11 @@
|
|||
error[E0658]: casting pointers to integers in constants is unstable
|
||||
error: pointers cannot be cast to integers during const eval.
|
||||
--> $DIR/match-test-ptr-null.rs:6:15
|
||||
|
|
||||
LL | match &1 as *const i32 as usize {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: see issue #51910 <https://github.com/rust-lang/rust/issues/51910> for more information
|
||||
= help: add `#![feature(const_raw_ptr_to_usize_cast)]` to the crate attributes to enable
|
||||
= note: at compile-time, pointers do not have an integer value
|
||||
= note: avoiding this restriction via `transmute`, `union`, or raw pointers leads to compile-time undefined behavior
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0658`.
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#![feature(const_raw_ptr_to_usize_cast, const_raw_ptr_deref)]
|
||||
#![feature(const_raw_ptr_deref)]
|
||||
|
||||
fn main() {
|
||||
let x: &'static bool = &(42 as *const i32 == 43 as *const i32);
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ const unsafe extern "C" fn closure() -> fn() { || {} }
|
|||
const unsafe extern "C" fn use_float() { 1.0 + 1.0; }
|
||||
//~^ ERROR floating point arithmetic
|
||||
const extern "C" fn ptr_cast(val: *const u8) { val as usize; }
|
||||
//~^ ERROR casting pointers to integers
|
||||
//~^ ERROR pointers cannot be cast to integers
|
||||
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -25,14 +25,14 @@ LL | const unsafe extern "C" fn use_float() { 1.0 + 1.0; }
|
|||
= note: see issue #57241 <https://github.com/rust-lang/rust/issues/57241> for more information
|
||||
= help: add `#![feature(const_fn_floating_point_arithmetic)]` to the crate attributes to enable
|
||||
|
||||
error[E0658]: casting pointers to integers in constant functions is unstable
|
||||
error: pointers cannot be cast to integers during const eval.
|
||||
--> $DIR/const-extern-fn-min-const-fn.rs:9:48
|
||||
|
|
||||
LL | const extern "C" fn ptr_cast(val: *const u8) { val as usize; }
|
||||
| ^^^^^^^^^^^^
|
||||
|
|
||||
= note: see issue #51910 <https://github.com/rust-lang/rust/issues/51910> for more information
|
||||
= help: add `#![feature(const_raw_ptr_to_usize_cast)]` to the crate attributes to enable
|
||||
= note: at compile-time, pointers do not have an integer value
|
||||
= note: avoiding this restriction via `transmute`, `union`, or raw pointers leads to compile-time undefined behavior
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
static X: usize = unsafe { core::ptr::null::<usize>() as usize };
|
||||
//~^ ERROR: casting pointers to integers in statics is unstable
|
||||
//~^ ERROR: pointers cannot be cast to integers during const eval
|
||||
|
||||
fn main() {
|
||||
assert_eq!(X, 0);
|
||||
|
|
|
|||
|
|
@ -1,12 +1,11 @@
|
|||
error[E0658]: casting pointers to integers in statics is unstable
|
||||
error: pointers cannot be cast to integers during const eval.
|
||||
--> $DIR/issue-17458.rs:1:28
|
||||
|
|
||||
LL | static X: usize = unsafe { core::ptr::null::<usize>() as usize };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: see issue #51910 <https://github.com/rust-lang/rust/issues/51910> for more information
|
||||
= help: add `#![feature(const_raw_ptr_to_usize_cast)]` to the crate attributes to enable
|
||||
= note: at compile-time, pointers do not have an integer value
|
||||
= note: avoiding this restriction via `transmute`, `union`, or raw pointers leads to compile-time undefined behavior
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0658`.
|
||||
|
|
|
|||
|
|
@ -1,8 +0,0 @@
|
|||
#![feature(const_raw_ptr_to_usize_cast)]
|
||||
|
||||
const BAR: *mut () = ((|| 3) as fn() -> i32) as *mut ();
|
||||
pub const FOO: usize = unsafe { BAR as usize };
|
||||
//~^ ERROR any use of this value will cause an error
|
||||
//~| WARN this was previously accepted by the compiler but is being phased out
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
error: any use of this value will cause an error
|
||||
--> $DIR/issue-51559.rs:4:33
|
||||
|
|
||||
LL | pub const FOO: usize = unsafe { BAR as usize };
|
||||
| --------------------------------^^^^^^^^^^^^---
|
||||
| |
|
||||
| cannot cast pointer to integer because it was not created by cast from integer
|
||||
|
|
||||
= note: `#[deny(const_err)]` on by default
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
@ -1,3 +1,3 @@
|
|||
fn main() {
|
||||
let _ = [0; (&0 as *const i32) as usize]; //~ ERROR casting pointers to integers in constants
|
||||
let _ = [0; (&0 as *const i32) as usize]; //~ ERROR pointers cannot be cast to integers during const eval
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,11 @@
|
|||
error[E0658]: casting pointers to integers in constants is unstable
|
||||
error: pointers cannot be cast to integers during const eval.
|
||||
--> $DIR/issue-52023-array-size-pointer-cast.rs:2:17
|
||||
|
|
||||
LL | let _ = [0; (&0 as *const i32) as usize];
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: see issue #51910 <https://github.com/rust-lang/rust/issues/51910> for more information
|
||||
= help: add `#![feature(const_raw_ptr_to_usize_cast)]` to the crate attributes to enable
|
||||
= note: at compile-time, pointers do not have an integer value
|
||||
= note: avoiding this restriction via `transmute`, `union`, or raw pointers leads to compile-time undefined behavior
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0658`.
|
||||
|
|
|
|||
|
|
@ -1,10 +0,0 @@
|
|||
#![feature(const_raw_ptr_to_usize_cast)]
|
||||
|
||||
fn main() {
|
||||
[(); &(static |x| {}) as *const _ as usize];
|
||||
//~^ ERROR: closures cannot be static
|
||||
//~| ERROR: type annotations needed
|
||||
[(); &(static || {}) as *const _ as usize];
|
||||
//~^ ERROR: closures cannot be static
|
||||
//~| ERROR evaluation of constant value failed
|
||||
}
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
error[E0697]: closures cannot be static
|
||||
--> $DIR/issue-52432.rs:4:12
|
||||
|
|
||||
LL | [(); &(static |x| {}) as *const _ as usize];
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error[E0697]: closures cannot be static
|
||||
--> $DIR/issue-52432.rs:7:12
|
||||
|
|
||||
LL | [(); &(static || {}) as *const _ as usize];
|
||||
| ^^^^^^^^^
|
||||
|
||||
error[E0282]: type annotations needed
|
||||
--> $DIR/issue-52432.rs:4:20
|
||||
|
|
||||
LL | [(); &(static |x| {}) as *const _ as usize];
|
||||
| ^ consider giving this closure parameter a type
|
||||
|
||||
error[E0080]: evaluation of constant value failed
|
||||
--> $DIR/issue-52432.rs:7:10
|
||||
|
|
||||
LL | [(); &(static || {}) as *const _ as usize];
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot cast pointer to integer because it was not created by cast from integer
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0080, E0282, E0697.
|
||||
For more information about an error, try `rustc --explain E0080`.
|
||||
|
|
@ -90,13 +90,13 @@ static BAR: u32 = 42;
|
|||
const fn foo25() -> u32 { BAR } //~ ERROR cannot refer to statics
|
||||
const fn foo26() -> &'static u32 { &BAR } //~ ERROR cannot refer to statics
|
||||
const fn foo30(x: *const u32) -> usize { x as usize }
|
||||
//~^ ERROR casting pointers to integers
|
||||
//~^ ERROR pointers cannot be cast to integers
|
||||
const fn foo30_with_unsafe(x: *const u32) -> usize { unsafe { x as usize } }
|
||||
//~^ ERROR casting pointers to integers
|
||||
//~^ ERROR pointers cannot be cast to integers
|
||||
const fn foo30_2(x: *mut u32) -> usize { x as usize }
|
||||
//~^ ERROR casting pointers to integers
|
||||
//~^ ERROR pointers cannot be cast to integers
|
||||
const fn foo30_2_with_unsafe(x: *mut u32) -> usize { unsafe { x as usize } }
|
||||
//~^ ERROR casting pointers to integers
|
||||
//~^ ERROR pointers cannot be cast to integers
|
||||
const fn foo30_6() -> bool { let x = true; x }
|
||||
const fn inc(x: &mut i32) { *x += 1 }
|
||||
//~^ ERROR mutable references
|
||||
|
|
|
|||
|
|
@ -164,41 +164,41 @@ LL | const fn foo26() -> &'static u32 { &BAR }
|
|||
|
|
||||
= help: consider extracting the value of the `static` to a `const`, and referring to that
|
||||
|
||||
error[E0658]: casting pointers to integers in constant functions is unstable
|
||||
error: pointers cannot be cast to integers during const eval.
|
||||
--> $DIR/min_const_fn.rs:92:42
|
||||
|
|
||||
LL | const fn foo30(x: *const u32) -> usize { x as usize }
|
||||
| ^^^^^^^^^^
|
||||
|
|
||||
= note: see issue #51910 <https://github.com/rust-lang/rust/issues/51910> for more information
|
||||
= help: add `#![feature(const_raw_ptr_to_usize_cast)]` to the crate attributes to enable
|
||||
= note: at compile-time, pointers do not have an integer value
|
||||
= note: avoiding this restriction via `transmute`, `union`, or raw pointers leads to compile-time undefined behavior
|
||||
|
||||
error[E0658]: casting pointers to integers in constant functions is unstable
|
||||
error: pointers cannot be cast to integers during const eval.
|
||||
--> $DIR/min_const_fn.rs:94:63
|
||||
|
|
||||
LL | const fn foo30_with_unsafe(x: *const u32) -> usize { unsafe { x as usize } }
|
||||
| ^^^^^^^^^^
|
||||
|
|
||||
= note: see issue #51910 <https://github.com/rust-lang/rust/issues/51910> for more information
|
||||
= help: add `#![feature(const_raw_ptr_to_usize_cast)]` to the crate attributes to enable
|
||||
= note: at compile-time, pointers do not have an integer value
|
||||
= note: avoiding this restriction via `transmute`, `union`, or raw pointers leads to compile-time undefined behavior
|
||||
|
||||
error[E0658]: casting pointers to integers in constant functions is unstable
|
||||
error: pointers cannot be cast to integers during const eval.
|
||||
--> $DIR/min_const_fn.rs:96:42
|
||||
|
|
||||
LL | const fn foo30_2(x: *mut u32) -> usize { x as usize }
|
||||
| ^^^^^^^^^^
|
||||
|
|
||||
= note: see issue #51910 <https://github.com/rust-lang/rust/issues/51910> for more information
|
||||
= help: add `#![feature(const_raw_ptr_to_usize_cast)]` to the crate attributes to enable
|
||||
= note: at compile-time, pointers do not have an integer value
|
||||
= note: avoiding this restriction via `transmute`, `union`, or raw pointers leads to compile-time undefined behavior
|
||||
|
||||
error[E0658]: casting pointers to integers in constant functions is unstable
|
||||
error: pointers cannot be cast to integers during const eval.
|
||||
--> $DIR/min_const_fn.rs:98:63
|
||||
|
|
||||
LL | const fn foo30_2_with_unsafe(x: *mut u32) -> usize { unsafe { x as usize } }
|
||||
| ^^^^^^^^^^
|
||||
|
|
||||
= note: see issue #51910 <https://github.com/rust-lang/rust/issues/51910> for more information
|
||||
= help: add `#![feature(const_raw_ptr_to_usize_cast)]` to the crate attributes to enable
|
||||
= note: at compile-time, pointers do not have an integer value
|
||||
= note: avoiding this restriction via `transmute`, `union`, or raw pointers leads to compile-time undefined behavior
|
||||
|
||||
error[E0658]: mutable references are not allowed in constant functions
|
||||
--> $DIR/min_const_fn.rs:101:14
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
fn main() {
|
||||
const X: u32 = 1;
|
||||
const Y: usize = unsafe { &X as *const u32 as usize }; //~ ERROR is unstable
|
||||
const Y: usize = unsafe { &X as *const u32 as usize }; //~ ERROR pointers cannot be cast to integers
|
||||
println!("{}", Y);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,11 @@
|
|||
error[E0658]: casting pointers to integers in constants is unstable
|
||||
error: pointers cannot be cast to integers during const eval.
|
||||
--> $DIR/issue-18294.rs:3:31
|
||||
|
|
||||
LL | const Y: usize = unsafe { &X as *const u32 as usize };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: see issue #51910 <https://github.com/rust-lang/rust/issues/51910> for more information
|
||||
= help: add `#![feature(const_raw_ptr_to_usize_cast)]` to the crate attributes to enable
|
||||
= note: at compile-time, pointers do not have an integer value
|
||||
= note: avoiding this restriction via `transmute`, `union`, or raw pointers leads to compile-time undefined behavior
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0658`.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue