2024-12-02 21:16:35 +00:00
|
|
|
//! Unstable module containing the unstable contracts lang items and attribute macros.
|
|
|
|
|
|
2025-01-17 14:49:10 -08:00
|
|
|
pub use crate::macros::builtin::{contracts_ensures as ensures, contracts_requires as requires};
|
2024-12-02 21:16:35 +00:00
|
|
|
|
|
|
|
|
/// Emitted by rustc as a desugaring of `#[ensures(PRED)] fn foo() -> R { ... [return R;] ... }`
|
|
|
|
|
/// into: `fn foo() { let _check = build_check_ensures(|ret| PRED) ... [return _check(R);] ... }`
|
|
|
|
|
/// (including the implicit return of the tail expression, if any).
|
2025-01-30 17:06:09 -08:00
|
|
|
#[unstable(feature = "contracts_internals", issue = "128044" /* compiler-team#759 */)]
|
2024-12-02 21:16:35 +00:00
|
|
|
#[lang = "contract_build_check_ensures"]
|
|
|
|
|
#[track_caller]
|
2025-01-17 14:49:10 -08:00
|
|
|
pub fn build_check_ensures<Ret, C>(cond: C) -> impl (Fn(Ret) -> Ret) + Copy
|
2024-12-02 21:16:35 +00:00
|
|
|
where
|
2025-01-17 14:49:10 -08:00
|
|
|
C: for<'a> Fn(&'a Ret) -> bool + Copy + 'static,
|
2024-12-02 21:16:35 +00:00
|
|
|
{
|
|
|
|
|
#[track_caller]
|
|
|
|
|
move |ret| {
|
2025-01-17 14:49:10 -08:00
|
|
|
crate::intrinsics::contract_check_ensures(&ret, cond);
|
2024-12-02 21:16:35 +00:00
|
|
|
ret
|
|
|
|
|
}
|
|
|
|
|
}
|