Closed roypat closed 1 week ago
Just to clarify, the problem is that slice methods are represented using qualified paths, and today we only support simple paths.
For example, here is a dummy test that calls len()
via a function pointer:
#[test]
fn test_len() {
assert_eq!(len_ptr(&[1u8]), 1);
}
fn len_ptr<T>(slice: &[T]) -> usize {
let ptr = <[T]>::len;
ptr(slice)
}
@feliperodri one workaround that might be easier to implement is to allow users to stub using type alias. @roypat, would something like this work for you:
type Slice<T> = [T];
#[kani::proof]
#[kani::stub(Slice::len, stub_len)]
fn verify_len() {
assert_eq!(vec![1u8].as_slice().len(), 1);
assert_eq!(vec![1u8].as_slice().len(), 0);
}
Requested feature: I recently ran across a situation where I wanted to stub the
binary_search_by_key
function on slices because I knew my slice would always have length 1, which would allow me to save on some unrolls. I ran into some problems expressing this stub however, since[T]::binary_search_by_key
is not a valid path (even theimpl [T]
in the standard library seems to be special-cased into the compiler).Test case:
I'm really not sure how to express this, since
[T]
cannot really be part of paths, but I guess I'd liketo work. Currently, the output I get from running
kani kani_example.rs
is