Skip to content

Commit ad9a20c

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 1f32e37 commit ad9a20c

File tree

15 files changed

+15
-93
lines changed

15 files changed

+15
-93
lines changed

compiler/rustc_codegen_ssa/src/mir/intrinsic.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
115115
| sym::assert_mem_uninitialized_valid
116116
| sym::assert_inhabited
117117
| sym::ub_checks
118-
| sym::contract_checks
119118
| sym::atomic_fence
120119
| sym::atomic_singlethreadfence
121120
| sym::caller_location => {}

compiler/rustc_feature/src/builtin_attrs.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ const GATED_CFGS: &[GatedCfg] = &[
2222
// (name in cfg, feature, function to check if the feature is enabled)
2323
(sym::overflow_checks, sym::cfg_overflow_checks, Features::cfg_overflow_checks),
2424
(sym::ub_checks, sym::cfg_ub_checks, Features::cfg_ub_checks),
25-
(sym::contract_checks, sym::cfg_contract_checks, Features::cfg_contract_checks),
2625
(sym::target_thread_local, sym::cfg_target_thread_local, Features::cfg_target_thread_local),
2726
(
2827
sym::target_has_atomic_equal_alignment,

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 & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ fn intrinsic_operation_unsafety(tcx: TyCtxt<'_>, intrinsic_id: LocalDefId) -> hi
123123
| sym::aggregate_raw_ptr
124124
| sym::ptr_metadata
125125
| sym::ub_checks
126-
| sym::contract_checks
127126
| sym::contract_check_requires
128127
| sym::contract_check_ensures
129128
| sym::fadd_algebraic
@@ -568,8 +567,6 @@ pub(crate) fn check_intrinsic_type(
568567

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

571-
// contract_checks() -> bool
572-
sym::contract_checks => (0, 0, Vec::new(), tcx.types.bool),
573570
// contract_check_requires::<C>(C) -> bool, where C: impl Fn() -> bool
574571
sym::contract_check_requires => (1, 0, vec![param(0)], tcx.types.unit),
575572
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(

compiler/rustc_session/src/config/cfg.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ pub(crate) fn disallow_cfgs(sess: &Session, user_cfgs: &Cfg) {
118118
(sym::overflow_checks, None) => disallow(cfg, "-C overflow-checks"),
119119
(sym::debug_assertions, None) => disallow(cfg, "-C debug-assertions"),
120120
(sym::ub_checks, None) => disallow(cfg, "-Z ub-checks"),
121-
(sym::contract_checks, None) => disallow(cfg, "-Z contract-checks"),
122121
(sym::sanitize, None | Some(_)) => disallow(cfg, "-Z sanitizer"),
123122
(
124123
sym::sanitizer_cfi_generalize_pointers | sym::sanitizer_cfi_normalize_integers,
@@ -305,10 +304,6 @@ pub(crate) fn default_configuration(sess: &Session) -> Cfg {
305304
ins_none!(sym::emscripten_wasm_eh);
306305
}
307306

308-
if sess.contract_checks() {
309-
ins_none!(sym::contract_checks);
310-
}
311-
312307
ret
313308
}
314309

@@ -469,7 +464,6 @@ impl CheckCfg {
469464
ins!(sym::target_thread_local, no_values);
470465

471466
ins!(sym::ub_checks, no_values);
472-
ins!(sym::contract_checks, no_values);
473467

474468
ins!(sym::unix, no_values);
475469
ins!(sym::windows, no_values);

compiler/rustc_span/src/symbol.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,6 @@ symbols! {
747747
contract_build_check_ensures,
748748
contract_check_ensures,
749749
contract_check_requires,
750-
contract_checks,
751750
contracts,
752751
contracts_ensures,
753752
contracts_internals,

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
| ^^^^^^^^^

0 commit comments

Comments
 (0)