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