We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent ce5e910 commit 074e20eCopy full SHA for 074e20e
tests/run-pass-noseed/intptrcast.rs
@@ -1,4 +1,7 @@
1
// compile-flags: -Zmiri-seed=0000000000000000
2
+fn transmute_ptr_to_int<T>(x: *const T) -> usize {
3
+ unsafe { std::mem::transmute::<*const T, usize>(x) * 1 }
4
+}
5
6
fn main() {
7
// Some casting-to-int with arithmetic.
@@ -11,4 +14,11 @@ fn main() {
11
14
// Pointer string formatting! We can't check the output as it changes when libstd changes,
12
15
// but we can make sure Miri does not error.
13
16
format!("{:?}", &mut 13 as *mut _);
17
+
18
+ // Check that intptrcast is triggered for explicit casts and that it is consistent with
19
+ // transmuting.
20
+ let a: *const i32 = &42;
21
+ let b = transmute_ptr_to_int(a) as u8;
22
+ let c = a as usize as u8;
23
+ assert_eq!(b, c);
24
}
0 commit comments