Skip to content

Commit d8aa566

Browse files
add feature target for loop invariant
1 parent 9cf5177 commit d8aa566

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

library/alloc/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@
9393
// Library features:
9494
// tidy-alphabetical-start
9595
#![cfg_attr(kani, feature(kani))]
96+
#![cfg_attr(kani, feature(proc_macro_hygiene))]
97+
#![cfg_attr(kani, feature(stmt_expr_attributes))]
9698
#![feature(alloc_layout_extra)]
9799
#![feature(allocator_api)]
98100
#![feature(array_into_iter_constructors)]

library/alloc/src/slice.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ use core::borrow::{Borrow, BorrowMut};
1414
use core::cmp::Ordering::{self, Less};
1515
#[cfg(kani)]
1616
use core::kani;
17+
#[cfg(kani)]
18+
use core::kani;
1719
#[cfg(not(no_global_oom_handling))]
1820
use core::mem::MaybeUninit;
1921
#[cfg(kani)]
@@ -68,8 +70,6 @@ use crate::alloc::Global;
6870
#[cfg(not(no_global_oom_handling))]
6971
use crate::borrow::ToOwned;
7072
use crate::boxed::Box;
71-
#[cfg(kani)]
72-
use crate::kani;
7373
use crate::vec::Vec;
7474

7575
impl<T> [T] {
@@ -536,14 +536,14 @@ impl<T> [T] {
536536
let buf_ptr = ptr::slice_from_raw_parts(buf.as_ptr(), capacity);
537537
#[cfg(kani)]
538538
let len_ptr = unsafe { (&buf as *const Vec<T> as *const usize).add(2) };
539-
#[safety::loop_invariant(
539+
#[cfg_attr(kani, kani::loop_invariant(
540540
kani::mem::same_allocation(buf.as_ptr(), buf.as_ptr().wrapping_add(capacity)) &&
541541
unsafe {*len_ptr <= T::MAX_SLICE_LEN} &&
542542
unsafe {*len_ptr <= capacity} &&
543543
m.leading_zeros() > n.leading_zeros() &&
544544
unsafe {*len_ptr == sef.len() * (1usize << (m.leading_zeros() - n.leading_zeros() - 1))}
545-
)]
546-
#[safety::loop_modifies(&m, buf_ptr, len_ptr)]
545+
))]
546+
#[cfg_attr(kani, kani::loop_modifies(&m, buf_ptr, len_ptr))]
547547
while m > 0 {
548548
// `buf.extend(buf)`:
549549
unsafe {
@@ -897,13 +897,13 @@ pub mod slice_verify {
897897
fn check_repeat_u8() {
898898
let mut a: [u8; 10] = kani::any();
899899
let n = kani::any_where(|i| *i < 10);
900-
let _result = repeat(a.as_slice(), n);
900+
let _result = a.repeat(n);
901901
}
902902

903903
#[kani::proof]
904904
fn check_repeat_u16() {
905905
let mut a: [u16; 10] = kani::any();
906906
let n = kani::any_where(|i| *i < 10);
907-
let _result = repeat(a.as_slice(), n);
907+
let _result = a.repeat(n);
908908
}
909909
}

0 commit comments

Comments
 (0)