]>
git.proxmox.com Git - rustc.git/blob - src/test/compile-fail/pushpop-unsafe-rejects.rs
1 // Copyright 2012 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 #![feature(pushpop_unsafe)]
18 static mut X
: i32 = 0;
20 unsafe fn f() { X += 1; return; }
21 fn g() { unsafe { X += 1_000; }
return; }
26 f() //~ ERROR: call to unsafe function
34 f(); //~ ERROR: call to unsafe function
43 f(); //~ ERROR: call to unsafe function
48 // Note: For implementation simplicity the compiler just
49 // ICE's if you underflow the push_unsafe stack.
51 // Thus all of the following cases cause an ICE.
53 // (The "ERROR" notes are from an earlier version
54 // that used saturated arithmetic rather than checked
57 // pop_unsafe!{ g() };
60 // pop_unsafe!(pop_unsafe!{ g() })
65 // pop_unsafe!(pop_unsafe!({
66 // f() // ERROR: call to unsafe function
71 // f(); // ERROR: call to unsafe function