Skip to content

Remove wrappers and contracts per PR comments #2

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

Merged
merged 1 commit into from
Oct 28, 2024
Merged
Changes from all commits
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
46 changes: 6 additions & 40 deletions library/core/src/unicode/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,51 +35,17 @@ pub const UNICODE_VERSION: (u8, u8, u8) = unicode_data::UNICODE_VERSION;
#[cfg(kani)]
mod verify {
use super::conversions::{to_upper, to_lower};
use wrappers::*;
use crate::kani;
use safety::*;

/// Wrapper functions used to verify auto-generated functions from this module.
///
/// The files in this module are auto-generated by a script, so they are harder to annotate.
/// Instead, for each function that we want to verify, we create a wrapper function with
/// contracts.
mod wrappers {
use super::*;
use crate::ub_checks;

/// Wraps `conversions::to_upper` function.
///
/// ```no_run
/// pub fn to_upper(c: char) -> [char; 3] {
/// # todo!()
/// }
/// ```
#[ensures(|res| ub_checks::can_dereference(res))]
pub fn to_upper_wrapper(c: char) -> [char; 3] {
to_upper(c)
}

/// Wraps `conversions::to_lower` function.
///
/// ```no_run
/// pub fn to_lower(c: char) -> [char; 3] {
/// # todo!()
/// }
/// ```
#[ensures(|res| ub_checks::can_dereference(res))]
pub fn to_lower_wrapper(c: char) -> [char; 3] {
to_lower(c)
}
}

#[kani::proof_for_contract(to_upper_wrapper)]
/// Checks that `to_upper` does not trigger UB or panics for all valid characters.
#[kani::proof]
fn check_to_upper_safety() {
let _ = to_upper_wrapper(kani::any());
let _ = to_upper(kani::any());
}

#[kani::proof_for_contract(to_lower_wrapper)]
/// Checks that `to_lower` does not trigger UB or panics for all valid characters.
#[kani::proof]
fn check_to_lower_safety() {
let _ = to_lower_wrapper(kani::any());
let _ = to_lower(kani::any());
}
}
Loading