Skip to content

Commit ebfa3d8

Browse files
committedOct 16, 2024
Add safety post-condition to unicode functions
1 parent d2e13b1 commit ebfa3d8

File tree

1 file changed

+9
-12
lines changed
  • library/core/src/unicode

1 file changed

+9
-12
lines changed
 

‎library/core/src/unicode/mod.rs

+9-12
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,12 @@ mod verify {
4141

4242
/// Wrapper functions used to verify auto-generated functions from this module.
4343
///
44-
/// The files in this module is auto-generated by a script, so they are harder to annotate.
45-
/// Instead, for each function that we want to verify, we create a wrapper function and add
46-
/// contracts for them instead.
44+
/// The files in this module are auto-generated by a script, so they are harder to annotate.
45+
/// Instead, for each function that we want to verify, we create a wrapper function with
46+
/// contracts.
4747
mod wrappers {
4848
use super::*;
49+
use crate::ub_checks;
4950

5051
/// Wraps `conversions::to_upper` function.
5152
///
@@ -54,9 +55,7 @@ mod verify {
5455
/// # todo!()
5556
/// }
5657
/// ```
57-
#[ensures(|res| c.is_ascii() == res[0].is_ascii())]
58-
#[ensures(|res| if c.is_ascii() { &res[1..2] == &['\0', '\0'] } else { true })]
59-
#[ensures(|res| if ('a'..'z').contains(&c) { ('A'..'Z').contains(&res[0]) } else { c == res[0] })]
58+
#[ensures(|res| ub_checks::can_dereference(res))]
6059
pub fn to_upper_wrapper(c: char) -> [char; 3] {
6160
to_upper(c)
6261
}
@@ -68,21 +67,19 @@ mod verify {
6867
/// # todo!()
6968
/// }
7069
/// ```
71-
#[ensures(|res| c.is_ascii() == res[0].is_ascii())]
72-
#[ensures(|res| if c.is_ascii() { &res[1..2] == &['\0', '\0'] } else { true })]
73-
#[ensures(|res| if ('A'..'Z').contains(&c) { ('a'..'z').contains(&res[0]) } else { c == res[0] })]
70+
#[ensures(|res| ub_checks::can_dereference(res))]
7471
pub fn to_lower_wrapper(c: char) -> [char; 3] {
7572
to_lower(c)
7673
}
7774
}
7875

7976
#[kani::proof_for_contract(to_upper_wrapper)]
80-
fn check_to_upper() {
77+
fn check_to_upper_safety() {
8178
let _ = to_upper_wrapper(kani::any());
8279
}
8380

8481
#[kani::proof_for_contract(to_lower_wrapper)]
85-
fn check_to_lower() {
86-
let _ = to_upper_wrapper(kani::any());
82+
fn check_to_lower_safety() {
83+
let _ = to_lower_wrapper(kani::any());
8784
}
8885
}

0 commit comments

Comments
 (0)