Skip to content

Commit a53d530

Browse files
pnkfelixgitbot
authored andcommitted
Contracts core intrinsics.
These are hooks to: 1. control whether contract checks are run 2. allow 3rd party tools to intercept and reintepret the results of running contracts.
1 parent 2dd6f1b commit a53d530

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

core/src/intrinsics/mod.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4044,6 +4044,38 @@ pub const unsafe fn const_deallocate(_ptr: *mut u8, _size: usize, _align: usize)
40444044
// Runtime NOP
40454045
}
40464046

4047+
/// Returns whether we should perform contract-checking at runtime.
4048+
///
4049+
/// This is meant to be similar to the ub_checks intrinsic, in terms
4050+
/// of not prematurely commiting at compile-time to whether contract
4051+
/// checking is turned on, so that we can specify contracts in libstd
4052+
/// and let an end user opt into turning them on.
4053+
#[cfg(not(bootstrap))]
4054+
#[rustc_const_unstable(feature = "rustc_contracts", issue = "none" /* compiler-team#759 */)]
4055+
#[unstable(feature = "rustc_contracts", issue = "none" /* compiler-team#759 */)]
4056+
#[inline(always)]
4057+
#[rustc_intrinsic]
4058+
pub const fn contract_checks() -> bool {
4059+
// FIXME: should this be `false` or `cfg!(contract_checks)`?
4060+
4061+
// cfg!(contract_checks)
4062+
false
4063+
}
4064+
4065+
#[cfg(not(bootstrap))]
4066+
#[unstable(feature = "rustc_contracts", issue = "none" /* compiler-team#759 */)]
4067+
#[rustc_intrinsic]
4068+
pub fn contract_check_requires<C: FnOnce() -> bool>(c: C) -> bool {
4069+
c()
4070+
}
4071+
4072+
#[cfg(not(bootstrap))]
4073+
#[unstable(feature = "rustc_contracts", issue = "none" /* compiler-team#759 */)]
4074+
#[rustc_intrinsic]
4075+
pub fn contract_check_ensures<'a, Ret, C: FnOnce(&'a Ret) -> bool>(ret: &'a Ret, c: C) -> bool {
4076+
c(ret)
4077+
}
4078+
40474079
/// The intrinsic will return the size stored in that vtable.
40484080
///
40494081
/// # Safety

0 commit comments

Comments
 (0)