diff options
| author | Felix S. Klock II <pnkfelix@pnkfx.org> | 2024-12-02 20:35:13 +0000 |
|---|---|---|
| committer | Celina G. Val <celinval@amazon.com> | 2025-02-03 12:53:57 -0800 |
| commit | bcb8565f301b579dee60fffe87d5a329cc69fefa (patch) | |
| tree | eb7f0ec9b3ee08283342608c5bbe0eb316834f54 /tests/ui/contracts | |
| parent | 534d79adf938fc3839fad47832c7cf2b4927d7d9 (diff) | |
| download | rust-bcb8565f301b579dee60fffe87d5a329cc69fefa.tar.gz rust-bcb8565f301b579dee60fffe87d5a329cc69fefa.zip | |
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.
Diffstat (limited to 'tests/ui/contracts')
| -rw-r--r-- | tests/ui/contracts/contract-intrinsics.rs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/ui/contracts/contract-intrinsics.rs b/tests/ui/contracts/contract-intrinsics.rs new file mode 100644 index 00000000000..6e3565baf7a --- /dev/null +++ b/tests/ui/contracts/contract-intrinsics.rs @@ -0,0 +1,23 @@ +//@ run-pass +//@ revisions: yes no none +//@ [yes] compile-flags: -Zcontract-checks=yes +//@ [no] compile-flags: -Zcontract-checks=no +#![feature(cfg_contract_checks, rustc_contracts, core_intrinsics)] + +fn main() { + #[cfg(none)] // default: disabled + assert_eq!(core::intrinsics::contract_checks(), false); + + #[cfg(yes)] // explicitly enabled + assert_eq!(core::intrinsics::contract_checks(), true); + + #[cfg(no)] // explicitly disabled + assert_eq!(core::intrinsics::contract_checks(), false); + + assert_eq!(core::intrinsics::contract_check_requires(|| true), true); + assert_eq!(core::intrinsics::contract_check_requires(|| false), false); + + let doubles_to_two = { let old = 2; move |ret| ret + ret == old }; + assert_eq!(core::intrinsics::contract_check_ensures(&1, doubles_to_two), true); + assert_eq!(core::intrinsics::contract_check_ensures(&2, doubles_to_two), false); +} |
