Skip to content

Commit 22f88fb

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 2a65b41 commit 22f88fb

File tree

8 files changed

+15
-69
lines changed

8 files changed

+15
-69
lines changed

library/core/src/intrinsics/mod.rs

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

2579-
/// Returns whether we should perform contract-checking at runtime.
2580-
///
2581-
/// This is meant to be similar to the ub_checks intrinsic, in terms
2582-
/// of not prematurely committing at compile-time to whether contract
2583-
/// checking is turned on, so that we can specify contracts in libstd
2584-
/// and let an end user opt into turning them on.
2585-
#[unstable(feature = "contracts_internals", issue = "128044" /* compiler-team#759 */)]
2586-
#[rustc_const_unstable(feature = "contracts", issue = "128044")]
2587-
#[inline(always)]
2588-
#[lang = "contract_checks"]
2589-
#[rustc_intrinsic]
2590-
pub const fn contract_checks() -> bool {
2591-
// FIXME: should this be `false` or `cfg!(contract_checks)`?
2592-
2593-
// cfg!(contract_checks)
2594-
false
2595-
}
2596-
25972579
/// Check if the pre-condition `cond` has been met.
25982580
///
25992581
/// By default, if `contract_checks` is enabled, this will panic with no unwind if the condition
Lines changed: 3 additions & 16 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
136
#![feature(cfg_contract_checks, 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);
Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0658]: contract internal machinery is for internal use only
2-
--> $DIR/internal-feature-gating.rs:16:28
2+
--> $DIR/internal-feature-gating.rs:14:28
33
|
44
LL | fn identity_1() -> i32 contract_requires(|| true) { 10 }
55
| ^^^^^^^^^^^^^^^^^
@@ -9,7 +9,7 @@ LL | fn identity_1() -> i32 contract_requires(|| true) { 10 }
99
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
1010

1111
error[E0658]: contract internal machinery is for internal use only
12-
--> $DIR/internal-feature-gating.rs:18:28
12+
--> $DIR/internal-feature-gating.rs:16:28
1313
|
1414
LL | fn identity_2() -> i32 contract_ensures(|_| true) { 10 }
1515
| ^^^^^^^^^^^^^^^^
@@ -21,16 +21,6 @@ LL | fn identity_2() -> i32 contract_ensures(|_| true) { 10 }
2121
error[E0658]: use of unstable library feature `contracts_internals`
2222
--> $DIR/internal-feature-gating.rs:5:5
2323
|
24-
LL | core::intrinsics::contract_checks();
25-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
26-
|
27-
= note: see issue #128044 <https://github.com/rust-lang/rust/issues/128044> for more information
28-
= help: add `#![feature(contracts_internals)]` to the crate attributes to enable
29-
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
30-
31-
error[E0658]: use of unstable library feature `contracts_internals`
32-
--> $DIR/internal-feature-gating.rs:7:5
33-
|
3424
LL | core::intrinsics::contract_check_requires(|| true);
3525
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3626
|
@@ -39,7 +29,7 @@ LL | core::intrinsics::contract_check_requires(|| true);
3929
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
4030

4131
error[E0658]: use of unstable library feature `contracts_internals`
42-
--> $DIR/internal-feature-gating.rs:9:5
32+
--> $DIR/internal-feature-gating.rs:7:5
4333
|
4434
LL | core::intrinsics::contract_check_ensures(Some(|_: &&u32| true), &1);
4535
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -49,7 +39,7 @@ LL | core::intrinsics::contract_check_ensures(Some(|_: &&u32| true), &1);
4939
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
5040

5141
error[E0658]: use of unstable library feature `contracts_internals`
52-
--> $DIR/internal-feature-gating.rs:12:5
42+
--> $DIR/internal-feature-gating.rs:10:5
5343
|
5444
LL | core::contracts::build_check_ensures(|_: &()| true);
5545
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -58,6 +48,6 @@ LL | core::contracts::build_check_ensures(|_: &()| true);
5848
= help: add `#![feature(contracts_internals)]` to the crate attributes to enable
5949
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
6050

61-
error: aborting due to 6 previous errors
51+
error: aborting due to 5 previous errors
6252

6353
For more information about this error, try `rustc --explain E0658`.

0 commit comments

Comments
 (0)