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-02-25 13:24:07 -08:00
|
|
|
///
|
|
|
|
|
/// This call helps with type inference for the predicate.
|
2025-01-30 17:06:09 -08:00
|
|
|
#[unstable(feature = "contracts_internals", issue = "128044" /* compiler-team#759 */)]
|
2025-02-25 13:24:07 -08:00
|
|
|
#[rustc_const_unstable(feature = "contracts", issue = "128044")]
|
2024-12-02 21:16:35 +00:00
|
|
|
#[lang = "contract_build_check_ensures"]
|
|
|
|
|
#[track_caller]
|
2025-02-25 13:24:07 -08:00
|
|
|
pub const fn build_check_ensures<Ret, C>(cond: C) -> C
|
2024-12-02 21:16:35 +00:00
|
|
|
where
|
2025-02-25 13:24:07 -08:00
|
|
|
C: Fn(&Ret) -> bool + Copy + 'static,
|
2024-12-02 21:16:35 +00:00
|
|
|
{
|
2025-02-25 13:24:07 -08:00
|
|
|
cond
|
2024-12-02 21:16:35 +00:00
|
|
|
}
|