Skip to content

Commit e330f83

Browse files
committed
transmute_unchecked contracts and harnesses
1 parent 346ec7b commit e330f83

File tree

1 file changed

+0
-51
lines changed

1 file changed

+0
-51
lines changed

library/core/src/intrinsics.rs

-51
Original file line numberDiff line numberDiff line change
@@ -3932,56 +3932,5 @@ mod verify {
39323932
let c: i8 = unsafe { transmute_unchecked_wrapper(b) };
39333933
assert_eq!(a,c);
39343934
}
3935-
3936-
#[kani::proof]
3937-
fn test_transmute_u32_to_bytes() {
3938-
// Create a nondeterministic u32 value.
3939-
let num: u32 = kani::any();
3940-
3941-
// SAFETY: This transmute is safe because u32 and [u8; 4] have the same size.
3942-
let bytes: [u8; 4] = unsafe { transmute(num) };
3943-
3944-
// To check if transmute preserves data, we can reinterpret bytes back to u32.
3945-
let num_back: u32 = unsafe { transmute(bytes) };
3946-
3947-
// Assert that the original number and the reconstructed number are the same.
3948-
assert_eq!(num, num_back, "Transmute did not preserve the value");
3949-
}
3950-
3951-
//This doesn't compile, since transmuting values of different sizes is not allowed
3952-
/*#[kani::proof]
3953-
fn transmute_different_sizes() {
3954-
let large_value: u64 = kani::any();
3955-
unsafe {
3956-
let truncated_value: u32 = transmute(large_value);
3957-
assert!(truncated_value == (large_value as u32));
3958-
}
3959-
}*/
3960-
3961-
#[kani::proof]
3962-
fn transmute_zero_size() {
3963-
let empty_arr: [u8;0] = [];
3964-
let unit_val: () = unsafe { transmute(empty_arr) };
3965-
assert!(unit_val == ());
3966-
}
3967-
3968-
#[kani::proof]
3969-
fn transmute_different_validy_reqs() {
3970-
let num: u8 = kani::any();
3971-
if num <= 1 {
3972-
let b: bool = unsafe {transmute(num)};
3973-
assert!(b == (num == 1));
3974-
}
3975-
//What do we check if num > 1?
3976-
}
3977-
3978-
#[kani::proof]
3979-
fn test_transmute_same_size() {
3980-
let a: i32 = kani::any();
3981-
let b: u32 = unsafe { transmute(a) };
3982-
let c: i32 = unsafe { transmute(b) };
3983-
assert_eq!(a,c);
3984-
}
3985-
>>>>>>> 3148918... added transmute harnesses
39863935

39873936
}

0 commit comments

Comments
 (0)