Skip to content

Commit 815b42b

Browse files
committed
Challenge 24: IntoIter + spec_* harness suite (squashed)
1 parent cd371e0 commit 815b42b

7 files changed

Lines changed: 980 additions & 0 deletions

File tree

‎library/alloc/src/vec/extract_if.rs‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,49 @@ where
154154
.finish_non_exhaustive()
155155
}
156156
}
157+
158+
#[cfg(kani)]
159+
mod verify {
160+
use core::kani;
161+
162+
use crate::vec::Vec;
163+
164+
// ExtractIf::next: drains in place through `vec.as_mut_ptr().add(i)`, reading
165+
// and writing the REAL pointer (no `can_write` assumption). The symbolic
166+
// predicate exercises the drained and hole-shift (`del > 0`) branches; the
167+
// implicit Drop exercises the backshift of the untouched tail. Bounded at 3:
168+
// larger sizes exceed the CI-standard object-bits 12 object budget (measured).
169+
#[kani::proof]
170+
#[kani::unwind(8)]
171+
fn check_extract_if_next_u8() {
172+
let arr: [u8; 3] = kani::any();
173+
let mut v: Vec<u8> = kani::slice::any_slice_of_array(&arr).to_vec();
174+
kani::cover(v.len() > 1, "non-vacuity: a multi-element drain is reachable");
175+
let mut ei = v.extract_if(.., |_x: &mut u8| kani::any::<bool>());
176+
// Two steps exercise the drain path and the `del > 0` hole-shift; the implicit
177+
// Drop then exercises the backshift-on-drop of the untouched tail.
178+
let _ = ei.next();
179+
let _ = ei.next();
180+
}
181+
182+
use crate::vec::kani_shapes::DropToken;
183+
184+
// ExtractIf::next over a Drop-carrying T: the implicit Drop backshift is the
185+
// leak-amplification guard path. Bounded at 3 (object-bits 12 budget).
186+
// Mirrors check_extract_if_next_u8. (No explicit assert: like the u8 form,
187+
// this verifies absence of UB on the drain + drop path.)
188+
fn check_extract_if_next_shape<T: kani::Arbitrary + Clone, const N: usize>() {
189+
let arr: [T; N] = kani::any();
190+
let mut v: Vec<T> = kani::slice::any_slice_of_array(&arr).to_vec();
191+
kani::cover(v.len() > 1, "non-vacuity: a multi-element drain is reachable");
192+
let mut ei = v.extract_if(.., |_x: &mut T| kani::any::<bool>());
193+
let _ = ei.next();
194+
let _ = ei.next();
195+
}
196+
197+
#[kani::proof]
198+
#[kani::unwind(8)]
199+
fn check_extract_if_next_droptoken() {
200+
check_extract_if_next_shape::<DropToken, 3>();
201+
}
202+
}

0 commit comments

Comments
 (0)