Skip to content

Commit 44824f1

Browse files
committed
Add harness for Alignment::new_unchecked
In model-checking#33 a contract was added to `Alignment::new_unchecked`, but its verification was only implicit through `Layout`, and may be affected by future changes to the contract that was added to `Layout`. This commit remedies this by adding a separate harness just for `Alignment`.
1 parent 4f4d032 commit 44824f1

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

library/core/src/ptr/alignment.rs

+17
Original file line numberDiff line numberDiff line change
@@ -370,3 +370,20 @@ enum AlignmentEnum {
370370
_Align1Shl62 = 1 << 62,
371371
_Align1Shl63 = 1 << 63,
372372
}
373+
374+
#[cfg(kani)]
375+
#[unstable(feature="kani", issue="none")]
376+
mod verify {
377+
use super::*;
378+
379+
#[kani::proof_for_contract(Alignment::new_unchecked)]
380+
pub fn check_new_unchecked() {
381+
let a = kani::any::<usize>();
382+
383+
unsafe {
384+
let alignment = Alignment::new_unchecked(a);
385+
assert_eq!(alignment.as_usize(), a);
386+
assert!(a.is_power_of_two());
387+
}
388+
}
389+
}

0 commit comments

Comments
 (0)