about summary refs log tree commit diff
path: root/tests/ui/contracts
AgeCommit message (Collapse)AuthorLines
2025-07-19tests: Require `run-fail` ui tests to have an exit code (`SIGABRT` not ok)Martin Nordholts-20/+20
And introduce two new directives for ui tests: * `run-crash` * `run-fail-or-crash` Normally a `run-fail` ui test like tests that panic shall not be terminated by a signal like `SIGABRT`. So begin having that as a hard requirement. Some of our current tests do terminate by a signal/crash however. Introduce and use `run-crash` for those tests. Note that Windows crashes are not handled by signals but by certain high bits set on the process exit code. Example exit code for crash on Windows: `0xc000001d`. Because of this, we define "crash" on all platforms as "not exit with success and not exit with a regular failure code in the range 1..=127". Some tests behave differently on different targets: * Targets without unwind support will abort (crash) instead of exit with failure code 101 after panicking. As a special case, allow crashes for `run-fail` tests for such targets. * Different sanitizer implementations handle detected memory problems differently. Some abort (crash) the process while others exit with failure code 1. Introduce and use `run-fail-or-crash` for such tests.
2025-04-08Fix unreachable expression warningCelina G. Val-55/+10
Invert the order that we pass the arguments to the `contract_check_ensures` function to avoid the warning when the tail of the function is unreachable. Note that the call itself is also unreachable, but we have already handled that case by ignoring unreachable call for contract calls.
2025-04-07Enable contracts for const functionsCelina G. Val-9/+144
Use `const_eval_select!()` macro to enable contract checking only at runtime. The existing contract logic relies on closures, which are not supported in constant functions. This commit also removes one level of indirection for ensures clauses, however, it currently has a spurious warning message when the bottom of the function is unreachable.
2025-02-11Rollup merge of #136837 - compiler-errors:contracts-body-lowering, r=celinvalJacob Pratt-0/+29
Overhaul how contracts are lowered on fn-like bodies Consolidates all of the contracts lowering logic into `lower_fn_body`, rather than having it be split between `lower_item_kind` and `lower_fn_body`. This should fix #136683. r? celinval
2025-02-10Don't ICE when failing to lower contracts for associated impl itemsMichael Goulet-0/+29
2025-02-10Stop using span hack for contracts feature gatingMichael Goulet-4/+4
2025-02-03Rename rustc_contract to contractCelina G. Val-72/+429
This has now been approved as a language feature and no longer needs a `rustc_` prefix. Also change the `contracts` feature to be marked as incomplete and `contracts_internals` as internal.
2025-02-03Improve contracts intrisics and remove wrapper functionCelina G. Val-40/+30
1. Document the new intrinsics. 2. Make the intrinsics actually check the contract if enabled, and remove `contract::check_requires` function. 3. Use panic with no unwind in case contract is using to check for safety, we probably don't want to unwind. Following the same reasoning as UB checks.
2025-02-03Refactor contract builtin macro + error handlingCelina G. Val-0/+207
Instead of parsing the different components of a function signature, eagerly look for either the `where` keyword or the function body. - Also address feedback to use `From` instead of `TryFrom` in cranelift contract and ubcheck codegen.
2025-02-03Separate contract feature gates for the internal machineryFelix S. Klock II-6/+103
The extended syntax for function signature that includes contract clauses should never be user exposed versus the interface we want to ship externally eventually.
2025-02-03demonstrate how to capture state at precondition time and feed into ↵Felix S. Klock II-0/+74
postcondition predicate.
2025-02-03Desugars contract into the internal AST extensionsFelix S. Klock II-0/+164
Check ensures on early return due to Try / Yeet Expand these two expressions to include a call to contract checking
2025-02-03Express contracts as part of function header and lower it to the contract ↵Celina G. Val-0/+118
lang items includes post-developed commit: do not suggest internal-only keywords as corrections to parse failures. includes post-developed commit: removed tabs that creeped in into rustfmt tool source code. includes post-developed commit, placating rustfmt self dogfooding. includes post-developed commit: add backquotes to prevent markdown checking from trying to treat an attr as a markdown hyperlink/ includes post-developed commit: fix lowering to keep contracts from being erroneously inherited by nested bodies (like closures). Rebase Conflicts: - compiler/rustc_parse/src/parser/diagnostics.rs - compiler/rustc_parse/src/parser/item.rs - compiler/rustc_span/src/hygiene.rs Remove contracts keywords from diagnostic messages
2025-02-03contracts: added lang items that act as hooks for rustc-injected code to invoke.Felix S. Klock II-0/+47
see test for an example of the kind of injected code that is anticipated here.
2025-02-03Contracts core intrinsics.Felix S. Klock II-0/+23
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.