mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 06:44:35 +00:00
Add Tests
This commit is contained in:
parent
0ee7cb5e36
commit
5d9b908571
@ -0,0 +1,70 @@
|
|||||||
|
const fn foo(ptr: *const u8) -> usize {
|
||||||
|
unsafe {
|
||||||
|
std::mem::transmute(ptr)
|
||||||
|
//~^ ERROR pointers cannot be transmuted to integers
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
trait Human {
|
||||||
|
const ID: u64 = {
|
||||||
|
let value = 10;
|
||||||
|
let ptr: *const i32 = &value;
|
||||||
|
unsafe {
|
||||||
|
std::mem::transmute(ptr)
|
||||||
|
//~^ ERROR pointers cannot be transmuted to integers
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
fn id_plus_one() -> u64 {
|
||||||
|
Self::ID + 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Type<T>(T);
|
||||||
|
|
||||||
|
impl<T> Type<T> {
|
||||||
|
const ID: u64 = {
|
||||||
|
let value = 10;
|
||||||
|
let ptr: *const i32 = &value;
|
||||||
|
unsafe {
|
||||||
|
std::mem::transmute(ptr)
|
||||||
|
//~^ ERROR pointers cannot be transmuted to integers
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
fn id_plus_one() -> u64 {
|
||||||
|
Self::ID + 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn control(ptr: *const u8) -> usize {
|
||||||
|
unsafe {
|
||||||
|
std::mem::transmute(ptr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct ControlStruct;
|
||||||
|
|
||||||
|
impl ControlStruct {
|
||||||
|
fn new() -> usize {
|
||||||
|
let value = 10;
|
||||||
|
let ptr: *const i32 = &value;
|
||||||
|
unsafe {
|
||||||
|
std::mem::transmute(ptr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const fn zoom(ptr: *const u8) -> usize {
|
||||||
|
unsafe {
|
||||||
|
std::mem::transmute(ptr)
|
||||||
|
//~^ ERROR pointers cannot be transmuted to integers
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
const a: u8 = 10;
|
||||||
|
const value: usize = zoom(&a);
|
||||||
|
//~^ ERROR evaluation of constant value failed
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
error[E0080]: evaluation of constant value failed
|
||||||
|
--> $DIR/ptr-to-int-transmute-in-consts-issue-87525.rs:68:26
|
||||||
|
|
|
||||||
|
LL | const value: usize = zoom(&a);
|
||||||
|
| ^^^^^^^^ unable to turn pointer into integer
|
||||||
|
|
|
||||||
|
= help: this code performed an operation that depends on the underlying bytes representing a pointer
|
||||||
|
= help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
|
||||||
|
|
||||||
|
error: aborting due to 1 previous error
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0080`.
|
Loading…
Reference in New Issue
Block a user