Skip to content

Commit 0a30c39

Browse files
committed
Remove no longer used contract_checks intrinsic
The contract_checks compiler flag is now used to determine if runtime contract checks should be enabled, as opposed to the compiler intrinsic as previously.
1 parent 4aa3aff commit 0a30c39

File tree

11 files changed

+16
-84
lines changed

11 files changed

+16
-84
lines changed

compiler/rustc_hir/src/lang_items.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,6 @@ language_item_table! {
429429
// Experimental lang items for implementing contract pre- and post-condition checking.
430430
ContractBuildCheckEnsures, sym::contract_build_check_ensures, contract_build_check_ensures_fn, Target::Fn, GenericRequirement::None;
431431
ContractCheckRequires, sym::contract_check_requires, contract_check_requires_fn, Target::Fn, GenericRequirement::None;
432-
ContractChecks, sym::contract_checks, contract_checks_fn, Target::Fn, GenericRequirement::None;
433432

434433
// Experimental lang items for `MCP: Low level components for async drop`(https://github.com/rust-lang/compiler-team/issues/727)
435434
DefaultTrait4, sym::default_trait4, default_trait4_trait, Target::Trait, GenericRequirement::None;

compiler/rustc_hir_analysis/src/check/intrinsic.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -647,8 +647,6 @@ pub(crate) fn check_intrinsic_type(
647647

648648
sym::box_new => (1, 0, vec![param(0)], Ty::new_box(tcx, param(0))),
649649

650-
// contract_checks() -> bool
651-
sym::contract_checks => (0, 0, Vec::new(), tcx.types.bool),
652650
// contract_check_requires::<C>(C) -> bool, where C: impl Fn() -> bool
653651
sym::contract_check_requires => (1, 0, vec![param(0)], tcx.types.unit),
654652
sym::contract_check_ensures => {

compiler/rustc_mir_transform/src/lower_intrinsics.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,6 @@ impl<'tcx> crate::MirPass<'tcx> for LowerIntrinsics {
3434
));
3535
terminator.kind = TerminatorKind::Goto { target };
3636
}
37-
sym::contract_checks => {
38-
let target = target.unwrap();
39-
block.statements.push(Statement::new(
40-
terminator.source_info,
41-
StatementKind::Assign(Box::new((
42-
*destination,
43-
Rvalue::NullaryOp(NullOp::ContractChecks, tcx.types.bool),
44-
))),
45-
));
46-
terminator.kind = TerminatorKind::Goto { target };
47-
}
4837
sym::forget => {
4938
let target = target.unwrap();
5039
block.statements.push(Statement::new(

library/core/src/intrinsics/mod.rs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2631,24 +2631,6 @@ pub const unsafe fn const_make_global(ptr: *mut u8) -> *const u8 {
26312631
ptr
26322632
}
26332633

2634-
/// Returns whether we should perform contract-checking at runtime.
2635-
///
2636-
/// This is meant to be similar to the ub_checks intrinsic, in terms
2637-
/// of not prematurely committing at compile-time to whether contract
2638-
/// checking is turned on, so that we can specify contracts in libstd
2639-
/// and let an end user opt into turning them on.
2640-
#[unstable(feature = "contracts_internals", issue = "128044" /* compiler-team#759 */)]
2641-
#[rustc_const_unstable(feature = "contracts", issue = "128044")]
2642-
#[inline(always)]
2643-
#[lang = "contract_checks"]
2644-
#[rustc_intrinsic]
2645-
pub const fn contract_checks() -> bool {
2646-
// FIXME: should this be `false` or `cfg!(contract_checks)`?
2647-
2648-
// cfg!(contract_checks)
2649-
false
2650-
}
2651-
26522634
/// Check if the pre-condition `cond` has been met.
26532635
///
26542636
/// By default, if `contract_checks` is enabled, this will panic with no unwind if the condition
Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,23 @@
1-
//@ revisions: default unchk_pass chk_pass chk_fail_ensures chk_fail_requires
1+
//@ revisions: default chk_fail_ensures chk_fail_requires
22
//
33
//@ [default] run-pass
4-
//@ [unchk_pass] run-pass
5-
//@ [chk_pass] run-pass
64
//@ [chk_fail_requires] run-crash
75
//@ [chk_fail_ensures] run-crash
8-
//
9-
//@ [unchk_pass] compile-flags: -Zcontract-checks=no
10-
//@ [chk_pass] compile-flags: -Zcontract-checks=yes
11-
//@ [chk_fail_requires] compile-flags: -Zcontract-checks=yes
12-
//@ [chk_fail_ensures] compile-flags: -Zcontract-checks=yes
13-
#![feature(cfg_contract_checks, contracts_internals, core_intrinsics)]
6+
#![feature(contracts_internals, core_intrinsics)]
147

158
fn main() {
16-
#[cfg(any(default, unchk_pass))] // default: disabled
17-
assert_eq!(core::intrinsics::contract_checks(), false);
18-
19-
#[cfg(chk_pass)] // explicitly enabled
20-
assert_eq!(core::intrinsics::contract_checks(), true);
21-
229
// always pass
2310
core::intrinsics::contract_check_requires(|| true);
2411

2512
// always fail
26-
#[cfg(any(chk_fail_requires))]
13+
#[cfg(chk_fail_requires)]
2714
core::intrinsics::contract_check_requires(|| false);
2815

2916
let doubles_to_two = { let old = 2; move |ret: &u32 | ret + ret == old };
3017
// Always pass
3118
core::intrinsics::contract_check_ensures(Some(doubles_to_two), 1);
3219

3320
// always fail
34-
#[cfg(any(chk_fail_ensures))]
21+
#[cfg(chk_fail_ensures)]
3522
core::intrinsics::contract_check_ensures(Some(doubles_to_two), 2);
3623
}

tests/ui/contracts/internal_machinery/contract-lang-items.chk_fail_post.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
warning: the feature `contracts` is incomplete and may not be safe to use and/or cause compiler crashes
2-
--> $DIR/contract-lang-items.rs:15:12
2+
--> $DIR/contract-lang-items.rs:8:12
33
|
44
LL | #![feature(contracts)] // to access core::contracts
55
| ^^^^^^^^^

tests/ui/contracts/internal_machinery/contract-lang-items.chk_pass.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
warning: the feature `contracts` is incomplete and may not be safe to use and/or cause compiler crashes
2-
--> $DIR/contract-lang-items.rs:15:12
2+
--> $DIR/contract-lang-items.rs:8:12
33
|
44
LL | #![feature(contracts)] // to access core::contracts
55
| ^^^^^^^^^
Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,16 @@
1-
//@ revisions: unchk_pass unchk_fail_post chk_pass chk_fail_post
1+
//@ revisions: unchk_pass chk_pass chk_fail_post
22
//
33
//@ [unchk_pass] run-pass
4-
//@ [unchk_fail_post] run-pass
54
//@ [chk_pass] run-pass
65
//
76
//@ [chk_fail_post] run-crash
8-
//
9-
//@ [unchk_pass] compile-flags: -Zcontract-checks=no
10-
//@ [unchk_fail_post] compile-flags: -Zcontract-checks=no
11-
//
12-
//@ [chk_pass] compile-flags: -Zcontract-checks=yes
13-
//@ [chk_fail_post] compile-flags: -Zcontract-checks=yes
147

158
#![feature(contracts)] // to access core::contracts
169
//~^ WARN the feature `contracts` is incomplete and may not be safe to use and/or cause compiler crashes [incomplete_features]
1710
#![feature(contracts_internals)] // to access check_requires lang item
1811
#![feature(core_intrinsics)]
1912
fn foo(x: Baz) -> i32 {
20-
let injected_checker = if core::intrinsics::contract_checks() {
21-
Some(core::contracts::build_check_ensures(|ret| *ret > 100))
22-
} else {
23-
None
24-
};
13+
let injected_checker = Some(core::contracts::build_check_ensures(|ret| *ret > 100));
2514

2615
let ret = x.baz + 50;
2716
core::intrinsics::contract_check_ensures(injected_checker, ret)
@@ -31,11 +20,11 @@ struct Baz { baz: i32 }
3120

3221

3322
const BAZ_PASS_PRE_POST: Baz = Baz { baz: 100 };
34-
#[cfg(any(unchk_fail_post, chk_fail_post))]
23+
#[cfg(chk_fail_post)]
3524
const BAZ_FAIL_POST: Baz = Baz { baz: 10 };
3625

3726
fn main() {
3827
assert_eq!(foo(BAZ_PASS_PRE_POST), 150);
39-
#[cfg(any(unchk_fail_post, chk_fail_post))]
28+
#[cfg(chk_fail_post)]
4029
foo(BAZ_FAIL_POST);
4130
}

tests/ui/contracts/internal_machinery/contract-lang-items.unchk_pass.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
warning: the feature `contracts` is incomplete and may not be safe to use and/or cause compiler crashes
2-
--> $DIR/contract-lang-items.rs:15:12
2+
--> $DIR/contract-lang-items.rs:8:12
33
|
44
LL | #![feature(contracts)] // to access core::contracts
55
| ^^^^^^^^^

tests/ui/contracts/internal_machinery/internal-feature-gating.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
fn main() {
44
// intrinsics are guarded by contracts_internals feature gate.
5-
core::intrinsics::contract_checks();
6-
//~^ ERROR use of unstable library feature `contracts_internals`
75
core::intrinsics::contract_check_requires(|| true);
86
//~^ ERROR use of unstable library feature `contracts_internals`
97
core::intrinsics::contract_check_ensures(Some(|_: &&u32| true), &1);

0 commit comments

Comments
 (0)