Skip to content

Commit b701f3a

Browse files
authored
Fix formatting, make flux happy
1 parent ab64f85 commit b701f3a

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

library/core/src/slice/memchr.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// Original implementation taken from rust-memchr.
22
// Copyright 2015 Andrew Gallant, bluss and Nicolas Koch
33

4-
use crate::intrinsics::const_eval_select;
54
#[cfg(kani)]
65
use crate::forall;
6+
use crate::intrinsics::const_eval_select;
77
#[cfg(kani)]
88
use crate::kani;
99

@@ -40,7 +40,7 @@ const fn memchr_naive(x: u8, text: &[u8]) -> Option<usize> {
4040
let mut i = 0;
4141

4242
// FIXME(const-hack): Replace with `text.iter().pos(|c| *c == x)`.
43-
#[kani::loop_invariant(i <= text.len() && forall!(|j in (0,i)| unsafe {*text.as_ptr().wrapping_add(j)} != x))]
43+
#[cfg_attr(kani, kani::loop_invariant(i <= text.len() && forall!(|j in (0,i)| unsafe {*text.as_ptr().wrapping_add(j)} != x)))]
4444
while i < text.len() {
4545
if text[i] == x {
4646
return Some(i);
@@ -83,8 +83,8 @@ const fn memchr_aligned(x: u8, text: &[u8]) -> Option<usize> {
8383

8484
// search the body of the text
8585
let repeated_x = usize::repeat_u8(x);
86-
#[kani::loop_invariant(len >= 2 * USIZE_BYTES && offset <= len &&
87-
forall!(|j in (0,offset)| unsafe {*text.as_ptr().wrapping_add(j)} != x))]
86+
#[cfg_attr(kani, kani::loop_invariant(len >= 2 * USIZE_BYTES && offset <= len &&
87+
forall!(|j in (0,offset)| unsafe {*text.as_ptr().wrapping_add(j)} != x)))]
8888
while offset <= len - 2 * USIZE_BYTES {
8989
// SAFETY: the while's predicate guarantees a distance of at least 2 * usize_bytes
9090
// between the offset and the end of the slice.
@@ -146,7 +146,7 @@ pub fn memrchr(x: u8, text: &[u8]) -> Option<usize> {
146146
let repeated_x = usize::repeat_u8(x);
147147
let chunk_bytes = size_of::<Chunk>();
148148

149-
#[kani::loop_invariant(true)]
149+
#[cfg_attr(kani, kani::loop_invariant(true))]
150150
while offset > min_aligned_offset {
151151
// SAFETY: offset starts at len - suffix.len(), as long as it is greater than
152152
// min_aligned_offset (prefix.len()) the remaining distance is at least 2 * chunk_bytes.

0 commit comments

Comments
 (0)