core/contracts.rs
1//! Unstable module containing the unstable contracts lang items and attribute macros.
2
3pub use crate::macros::builtin::{contracts_ensures as ensures, contracts_requires as requires};
4
5/// Emitted by rustc as a desugaring of `#[ensures(PRED)] fn foo() -> R { ... [return R;] ... }`
6/// into: `fn foo() { let _check = build_check_ensures(|ret| PRED) ... [return _check(R);] ... }`
7/// (including the implicit return of the tail expression, if any).
8#[unstable(feature = "contracts_internals", issue = "128044" /* compiler-team#759 */)]
9#[lang = "contract_build_check_ensures"]
10#[track_caller]
11pub fn build_check_ensures<Ret, C>(cond: C) -> impl (Fn(Ret) -> Ret) + Copy
12where
13 C: for<'a> Fn(&'a Ret) -> bool + Copy + 'static,
14{
15 #[track_caller]
16 move |ret| {
17 crate::intrinsics::contract_check_ensures(&ret, cond);
18 ret
19 }
20}