mirror of
https://github.com/rust-lang/rust.git
synced 2025-12-01 12:18:17 +00:00
Contract variables can be declared in the `requires` clause and can be referenced both in `requires` and `ensures`, subject to usual borrow checking rules. This allows any setup common to both the `requires` and `ensures` clauses to only be done once.
18 lines
327 B
Rust
18 lines
327 B
Rust
//@ run-pass
|
|
//@ compile-flags: -Zcontract-checks=yes
|
|
#![feature(contracts_internals)]
|
|
|
|
struct Outer { outer: std::cell::Cell<i32> }
|
|
|
|
fn outer(x: Outer)
|
|
contract_requires { x.outer.get() > 0 }
|
|
{
|
|
let inner_closure = || { };
|
|
x.outer.set(0);
|
|
inner_closure();
|
|
}
|
|
|
|
fn main() {
|
|
outer(Outer { outer: 1.into() });
|
|
}
|