Skip to content

Commit 5a4c2af

Browse files
committed
Add preconditions for disjoint_bitor
Uses the verbatim SAFETY comment as precondition to avoid spurious proof failures.
1 parent f804a33 commit 5a4c2af

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

.github/workflows/kani.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ jobs:
8181
- name: Run Kani Verification
8282
run: |
8383
scripts/run-kani.sh --run autoharness --kani-args \
84+
--include-pattern ">::disjoint_bitor" \
85+
--include-pattern ">::unchecked_disjoint_bitor" \
8486
--include-pattern alloc::layout::Layout::from_size_align \
8587
--include-pattern ascii::ascii_char::AsciiChar::from_u8 \
8688
--include-pattern char::convert::from_u32_unchecked \

library/core/src/intrinsics/fallback.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
use safety::requires;
2+
3+
#[cfg(kani)]
4+
use crate::kani;
5+
16
#![unstable(
27
feature = "core_intrinsics_fallbacks",
38
reason = "The fallbacks will never be stable, as they exist only to be called \
@@ -132,6 +137,7 @@ macro_rules! impl_disjoint_bitor {
132137
impl const DisjointBitOr for $t {
133138
#[cfg_attr(miri, track_caller)]
134139
#[inline]
140+
#[requires((self & other) == 0)]
135141
unsafe fn disjoint_bitor(self, other: Self) -> Self {
136142
// Note that the assume here is required for UB detection in Miri!
137143

library/core/src/num/uint_macros.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,6 +1265,7 @@ macro_rules! uint_impl {
12651265
#[unstable(feature = "disjoint_bitor", issue = "135758")]
12661266
#[rustc_const_unstable(feature = "disjoint_bitor", issue = "135758")]
12671267
#[inline]
1268+
#[requires((self & other) == 0)]
12681269
pub const unsafe fn unchecked_disjoint_bitor(self, other: Self) -> Self {
12691270
assert_unsafe_precondition!(
12701271
check_language_ub,

0 commit comments

Comments
 (0)