Skip to content

Commit 67098c5

Browse files
add im port kani
1 parent da0761a commit 67098c5

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

library/core/src/slice/memchr.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Copyright 2015 Andrew Gallant, bluss and Nicolas Koch
33

44
use crate::intrinsics::const_eval_select;
5+
use crate::kani;
56

67
const LO_USIZE: usize = usize::repeat_u8(0x01);
78
const HI_USIZE: usize = usize::repeat_u8(0x80);
@@ -36,7 +37,7 @@ const fn memchr_naive(x: u8, text: &[u8]) -> Option<usize> {
3637
let mut i = 0;
3738

3839
// FIXME(const-hack): Replace with `text.iter().pos(|c| *c == x)`.
39-
#[safety::loop_invariant(i <= text.len() && kani::forall!(|j in (0,i)| unsafe {*text.as_ptr().wrapping_add(j)} != x))]
40+
#[kani::loop_invariant(i <= text.len() && kani::forall!(|j in (0,i)| unsafe {*text.as_ptr().wrapping_add(j)} != x))]
4041
while i < text.len() {
4142
if text[i] == x {
4243
return Some(i);
@@ -79,7 +80,7 @@ const fn memchr_aligned(x: u8, text: &[u8]) -> Option<usize> {
7980

8081
// search the body of the text
8182
let repeated_x = usize::repeat_u8(x);
82-
#[safety::loop_invariant(len >= 2 * USIZE_BYTES && offset <= len &&
83+
#[kani::loop_invariant(len >= 2 * USIZE_BYTES && offset <= len &&
8384
kani::forall!(|j in (0,offset)| unsafe {*text.as_ptr().wrapping_add(j)} != x))]
8485
while offset <= len - 2 * USIZE_BYTES {
8586
// SAFETY: the while's predicate guarantees a distance of at least 2 * usize_bytes
@@ -142,7 +143,7 @@ pub fn memrchr(x: u8, text: &[u8]) -> Option<usize> {
142143
let repeated_x = usize::repeat_u8(x);
143144
let chunk_bytes = size_of::<Chunk>();
144145

145-
#[safety::loop_invariant(true)]
146+
#[kani::loop_invariant(true)]
146147
while offset > min_aligned_offset {
147148
// SAFETY: offset starts at len - suffix.len(), as long as it is greater than
148149
// min_aligned_offset (prefix.len()) the remaining distance is at least 2 * chunk_bytes.
@@ -168,7 +169,6 @@ pub fn memrchr(x: u8, text: &[u8]) -> Option<usize> {
168169
#[unstable(feature = "kani", issue = "none")]
169170
pub mod verify {
170171
use super::*;
171-
use crate::kani;
172172

173173
#[kani::proof]
174174
#[kani::solver(cvc5)]

0 commit comments

Comments
 (0)