Skip to content

Commit 800a8e7

Browse files
authored
Verify safety of to_lower and to_upper (#115)
These are safety abstractions that are auto-generated via script. Add minimum contract for now. Note: I tried adding a slightly tighter post-condition, but Kani takes a long time to solve them. This may be an interesting test for other tools later.
1 parent b818553 commit 800a8e7

File tree

1 file changed

+18
-0
lines changed
  • library/core/src/unicode

1 file changed

+18
-0
lines changed

library/core/src/unicode/mod.rs

+18
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,21 @@ mod unicode_data;
3131
/// [Unicode 11.0 or later, Section 3.1 Versions of the Unicode Standard](https://www.unicode.org/versions/Unicode11.0.0/ch03.pdf#page=4).
3232
#[stable(feature = "unicode_version", since = "1.45.0")]
3333
pub const UNICODE_VERSION: (u8, u8, u8) = unicode_data::UNICODE_VERSION;
34+
35+
#[cfg(kani)]
36+
mod verify {
37+
use super::conversions::{to_upper, to_lower};
38+
use crate::kani;
39+
40+
/// Checks that `to_upper` does not trigger UB or panics for all valid characters.
41+
#[kani::proof]
42+
fn check_to_upper_safety() {
43+
let _ = to_upper(kani::any());
44+
}
45+
46+
/// Checks that `to_lower` does not trigger UB or panics for all valid characters.
47+
#[kani::proof]
48+
fn check_to_lower_safety() {
49+
let _ = to_lower(kani::any());
50+
}
51+
}

0 commit comments

Comments
 (0)