Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate any_slice #2789

Merged
merged 3 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions library/kani/src/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,17 @@ fn any_range<const LENGTH: usize>() -> (usize, usize) {
/// let slice: kani::slice::AnySlice<u8, 5> = kani::slice::any_slice();
/// foo(&slice); // where foo is a function that takes a slice and verifies a property about it
/// ```
#[deprecated(
since = "0.38.0",
note = "Use `any_slice_of_array` or `any_slice_of_array_mut` instead"
)]
pub struct AnySlice<T, const MAX_SLICE_LENGTH: usize> {
layout: Layout,
ptr: *mut T,
slice_len: usize,
}

#[allow(deprecated)]
impl<T, const MAX_SLICE_LENGTH: usize> AnySlice<T, MAX_SLICE_LENGTH> {
fn new() -> Self
where
Expand Down Expand Up @@ -103,6 +108,7 @@ impl<T, const MAX_SLICE_LENGTH: usize> AnySlice<T, MAX_SLICE_LENGTH> {
}
}

#[allow(deprecated)]
impl<T, const MAX_SLICE_LENGTH: usize> Drop for AnySlice<T, MAX_SLICE_LENGTH> {
fn drop(&mut self) {
if self.slice_len > 0 {
Expand All @@ -114,6 +120,7 @@ impl<T, const MAX_SLICE_LENGTH: usize> Drop for AnySlice<T, MAX_SLICE_LENGTH> {
}
}

#[allow(deprecated)]
impl<T, const MAX_SLICE_LENGTH: usize> Deref for AnySlice<T, MAX_SLICE_LENGTH> {
type Target = [T];

Expand All @@ -122,15 +129,22 @@ impl<T, const MAX_SLICE_LENGTH: usize> Deref for AnySlice<T, MAX_SLICE_LENGTH> {
}
}

#[allow(deprecated)]
impl<T, const MAX_SLICE_LENGTH: usize> DerefMut for AnySlice<T, MAX_SLICE_LENGTH> {
fn deref_mut(&mut self) -> &mut Self::Target {
self.get_slice_mut()
}
}

#[deprecated(
since = "0.38.0",
note = "Use `any_slice_of_array` or `any_slice_of_array_mut` instead"
)]
#[allow(deprecated)]
pub fn any_slice<T, const MAX_SLICE_LENGTH: usize>() -> AnySlice<T, MAX_SLICE_LENGTH>
where
T: Arbitrary,
{
#[allow(deprecated)]
AnySlice::<T, MAX_SLICE_LENGTH>::new()
}
2 changes: 2 additions & 0 deletions tests/ui/any-slice-deprecated/expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
warning: use of deprecated function `kani::slice::any_slice`: Use `any_slice_of_array` or `any_slice_of_array_mut` instead
warning: use of deprecated struct `kani::slice::AnySlice`: Use `any_slice_of_array` or `any_slice_of_array_mut` instead
10 changes: 10 additions & 0 deletions tests/ui/any-slice-deprecated/test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright Kani Contributors
// SPDX-License-Identifier: Apache-2.0 OR MIT

//! A test that checks that Kani emits the deprecated message for `any_slice`
//! and `AnySlice`

#[kani::proof]
fn check_any_slice_deprecated() {
let _s: kani::slice::AnySlice<i32, 5> = kani::slice::any_slice();
}