Skip to content

Commit e45fc91

Browse files
authored
Remove unused msg parameter from any_where (rust-lang#2257)
1 parent e53ed63 commit e45fc91

File tree

6 files changed

+28
-6
lines changed

6 files changed

+28
-6
lines changed

CHANGELOG

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Changelog
2+
3+
This file contains notable changes (e.g. breaking changes, major changes, etc.) in Kani releases.
4+
5+
This file was introduced starting Kani 0.23.0, so it only contains changes from version 0.23.0 onwards.
6+
7+
## [0.23.0]
8+
9+
### **Breaking Changes**
10+
11+
- The second parameter in the `kani::any_where` function (`_msg: &'static str`) was removed to make the function more ergonomic to use.
12+
We suggest moving the explanation for why the assumption is introduced into a comment.
13+
For example, the following code:
14+
```rust
15+
let len: usize = kani::any_where(|x| *x < 5, "Restrict the length to a value less than 5");
16+
```
17+
should be replaced by:
18+
```rust
19+
// Restrict the length to a value less than 5
20+
let len: usize = kani::any_where(|x| *x < 5);
21+
```

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ repository = "https://github.com/model-checking/kani"
1414
documentation = "https://model-checking.github.io/kani/"
1515
homepage = "https://github.com/model-checking/kani"
1616
# N.B. Cargo.* is included automatically:
17-
include = ["/src", "/build.rs", "/rust-toolchain.toml", "/LICENSE-*", "/README.md"]
17+
include = ["/src", "/build.rs", "/rust-toolchain.toml", "/LICENSE-*", "/README.md", "/CHANGELOG"]
1818

1919
[dependencies]
2020
anyhow = "1"

library/kani/src/lib.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -112,23 +112,22 @@ pub fn any<T: Arbitrary>() -> T {
112112
/// This creates a symbolic *valid* value of type `T`.
113113
/// The value is constrained to be a value accepted by the predicate passed to the filter.
114114
/// You can assign the return value of this function to a variable that you want to make symbolic.
115-
/// The explanation field gives a mechanism to explain why the assumption is required for the proof.
116115
///
117116
/// # Example:
118117
///
119118
/// In the snippet below, we are verifying the behavior of the function `fn_under_verification`
120119
/// under all possible `NonZeroU8` input values between 0 and 12.
121120
///
122121
/// ```rust
123-
/// let inputA = kani::any_where::<std::num::NonZeroU8>(|x| *x < 12, "explanation");
122+
/// let inputA = kani::any_where::<std::num::NonZeroU8>(|x| *x < 12);
124123
/// fn_under_verification(inputA);
125124
/// ```
126125
///
127126
/// Note: This is a safe construct and can only be used with types that implement the `Arbitrary`
128127
/// trait. The Arbitrary trait is used to build a symbolic value that represents all possible
129128
/// valid values for type `T`.
130129
#[inline(always)]
131-
pub fn any_where<T: Arbitrary, F: FnOnce(&T) -> bool>(f: F, _msg: &'static str) -> T {
130+
pub fn any_where<T: Arbitrary, F: FnOnce(&T) -> bool>(f: F) -> T {
132131
let result = T::any();
133132
assume(f(&result));
134133
result

scripts/ci/copyright-exclude

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
.props
77
.public.key
88
Cargo.lock
9+
CHANGELOG
910
LICENSE-APACHE
1011
LICENSE-MIT
1112
editorconfig

tests/kani/Assume/main.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ fn main() {
1010

1111
#[kani::proof]
1212
fn verify_any_where() {
13-
let i: i32 = kani::any_where(|x| *x < 10, "Only single digit values are legal");
13+
// Only single digit values are legal
14+
let i: i32 = kani::any_where(|x| *x < 10);
1415
assert!(i < 20);
1516
}

tools/build-kani/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ fn bundle_kani(dir: &Path) -> Result<()> {
104104
// 5. Record the exact toolchain we use
105105
std::fs::write(dir.join("rust-toolchain-version"), env!("RUSTUP_TOOLCHAIN"))?;
106106

107-
// 5. Include a licensing note
107+
// 6. Include a licensing note
108108
cp(Path::new("tools/build-kani/license-notes.txt"), dir)?;
109109

110110
Ok(())

0 commit comments

Comments
 (0)