1 // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 // Basic sanity check for `push_unsafe!(EXPR)` and
12 // `pop_unsafe!(EXPR)`: we can call unsafe code when there are a
13 // positive number of pushes in the stack, or if we are within a
14 // normal `unsafe` block, but otherwise cannot.
16 // ignore-pretty because the `push_unsafe!` and `pop_unsafe!` macros
17 // are not integrated with the pretty-printer.
19 #![feature(pushpop_unsafe)]
21 static mut X
: i32 = 0;
23 unsafe fn f() { X += 1; return; }
24 fn g() { unsafe { X += 1_000; }
return; }
26 fn check_reset_x(x
: i32) -> bool
{
27 #![allow(unused_parens)] // dont you judge my style choices!
36 // double-check test infrastructure
37 assert
!(check_reset_x(0));
39 assert
!(check_reset_x(1));
40 assert
!(check_reset_x(0));
42 assert
!(check_reset_x(1000));
43 assert
!(check_reset_x(0));
44 unsafe { f(); g(); g(); }
45 assert
!(check_reset_x(2001));
47 push_unsafe
!( { f(); pop_unsafe!( g() ) }
);
48 assert
!(check_reset_x(1_001));
49 push_unsafe
!( { g(); pop_unsafe!( unsafe { f(); f(); }
) } );
50 assert
!(check_reset_x(1_002));
52 unsafe { push_unsafe!( { f(); pop_unsafe!( { f(); f(); }
) } ); }
53 assert
!(check_reset_x(3));
54 push_unsafe
!( { f(); push_unsafe!( { pop_unsafe!( { f(); f(); f(); }
) } ); } );
55 assert
!(check_reset_x(4));