|
1 | 1 | //! Unstable module containing the unstable contracts lang items and attribute macros.
|
| 2 | +#![cfg(not(bootstrap))] |
2 | 3 |
|
3 |
| -#[cfg(not(bootstrap))] |
4 |
| -pub use crate::macros::builtin::contracts_ensures as ensures; |
5 |
| -#[cfg(not(bootstrap))] |
6 |
| -pub use crate::macros::builtin::contracts_requires as requires; |
7 |
| - |
8 |
| -/// Emitted by rustc as a desugaring of `#[requires(PRED)] fn foo(x: X) { ... }` |
9 |
| -/// into: `fn foo(x: X) { check_requires(|| PRED) ... }` |
10 |
| -#[cfg(not(bootstrap))] |
11 |
| -#[unstable(feature = "rustc_contracts_internals", issue = "133866" /* compiler-team#759 */)] |
12 |
| -#[lang = "contract_check_requires"] |
13 |
| -#[track_caller] |
14 |
| -pub fn check_requires<C: FnOnce() -> bool>(c: C) { |
15 |
| - if core::intrinsics::contract_checks() { |
16 |
| - assert!(core::intrinsics::contract_check_requires(c), "failed requires check"); |
17 |
| - } |
18 |
| -} |
| 4 | +pub use crate::macros::builtin::{contracts_ensures as ensures, contracts_requires as requires}; |
19 | 5 |
|
20 | 6 | /// Emitted by rustc as a desugaring of `#[ensures(PRED)] fn foo() -> R { ... [return R;] ... }`
|
21 | 7 | /// into: `fn foo() { let _check = build_check_ensures(|ret| PRED) ... [return _check(R);] ... }`
|
22 | 8 | /// (including the implicit return of the tail expression, if any).
|
23 |
| -#[cfg(not(bootstrap))] |
24 | 9 | #[unstable(feature = "rustc_contracts_internals", issue = "133866" /* compiler-team#759 */)]
|
25 | 10 | #[lang = "contract_build_check_ensures"]
|
26 | 11 | #[track_caller]
|
27 |
| -pub fn build_check_ensures<Ret, C>(c: C) -> impl (FnOnce(Ret) -> Ret) + Copy |
| 12 | +pub fn build_check_ensures<Ret, C>(cond: C) -> impl (Fn(Ret) -> Ret) + Copy |
28 | 13 | where
|
29 |
| - C: for<'a> FnOnce(&'a Ret) -> bool + Copy + 'static, |
| 14 | + C: for<'a> Fn(&'a Ret) -> bool + Copy + 'static, |
30 | 15 | {
|
31 | 16 | #[track_caller]
|
32 | 17 | move |ret| {
|
33 |
| - if core::intrinsics::contract_checks() { |
34 |
| - assert!(core::intrinsics::contract_check_ensures(&ret, c), "failed ensures check"); |
35 |
| - } |
| 18 | + crate::intrinsics::contract_check_ensures(&ret, cond); |
36 | 19 | ret
|
37 | 20 | }
|
38 | 21 | }
|
0 commit comments