Skip to content

Commit c38f8f0

Browse files
pnkfelixgitbot
authored and
gitbot
committed
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 6c5ef3c commit c38f8f0

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

core/src/intrinsics/mod.rs

+32
Original file line numberDiff line numberDiff line change
@@ -4064,6 +4064,38 @@ pub const unsafe fn const_deallocate(_ptr: *mut u8, _size: usize, _align: usize)
40644064
// Runtime NOP
40654065
}
40664066

4067+
/// Returns whether we should perform contract-checking at runtime.
4068+
///
4069+
/// This is meant to be similar to the ub_checks intrinsic, in terms
4070+
/// of not prematurely commiting at compile-time to whether contract
4071+
/// checking is turned on, so that we can specify contracts in libstd
4072+
/// and let an end user opt into turning them on.
4073+
#[cfg(not(bootstrap))]
4074+
#[rustc_const_unstable(feature = "rustc_contracts", issue = "none" /* compiler-team#759 */)]
4075+
#[unstable(feature = "rustc_contracts", issue = "none" /* compiler-team#759 */)]
4076+
#[inline(always)]
4077+
#[rustc_intrinsic]
4078+
pub const fn contract_checks() -> bool {
4079+
// FIXME: should this be `false` or `cfg!(contract_checks)`?
4080+
4081+
// cfg!(contract_checks)
4082+
false
4083+
}
4084+
4085+
#[cfg(not(bootstrap))]
4086+
#[unstable(feature = "rustc_contracts", issue = "none" /* compiler-team#759 */)]
4087+
#[rustc_intrinsic]
4088+
pub fn contract_check_requires<C: FnOnce() -> bool>(c: C) -> bool {
4089+
c()
4090+
}
4091+
4092+
#[cfg(not(bootstrap))]
4093+
#[unstable(feature = "rustc_contracts", issue = "none" /* compiler-team#759 */)]
4094+
#[rustc_intrinsic]
4095+
pub fn contract_check_ensures<'a, Ret, C: FnOnce(&'a Ret) -> bool>(ret: &'a Ret, c: C) -> bool {
4096+
c(ret)
4097+
}
4098+
40674099
/// The intrinsic will return the size stored in that vtable.
40684100
///
40694101
/// # Safety

0 commit comments

Comments
 (0)