mirror of
https://github.com/rust-lang/rust.git
synced 2025-12-01 22:58:15 +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
394 B
Rust
18 lines
394 B
Rust
//@ run-pass
|
|
//@ compile-flags: -Zcontract-checks=yes
|
|
#![feature(contracts)]
|
|
//~^ WARN the feature `contracts` is incomplete and may not be safe to use and/or cause compiler crashes [incomplete_features]
|
|
|
|
extern crate core;
|
|
use core::contracts::{ensures, requires};
|
|
|
|
#[requires(let y = 1; true)]
|
|
#[ensures(move |_ret| { y == 1 })]
|
|
fn foo(x: u32) -> u32 {
|
|
x * 2
|
|
}
|
|
|
|
fn main() {
|
|
foo(1);
|
|
}
|