mirror of
https://github.com/rust-lang/rust.git
synced 2025-12-01 07:28:35 +00:00
Refactor contract HIR lowering to ensure no contract code is executed when contract-checks are disabled. The call to contract_checks is moved to inside the lowered fn body, and contract closures are built conditionally, ensuring no side-effects present in contracts occur when those are disabled.
17 lines
377 B
Rust
17 lines
377 B
Rust
//@ 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;
|
|
|
|
#[ensures()]
|
|
//~^ ERROR expected a `Fn(&_)` closure, found `()` [E0277]
|
|
fn foo(x: u32) -> u32 {
|
|
x * 2
|
|
}
|
|
|
|
fn main() {
|
|
foo(1);
|
|
}
|