mirror of
https://github.com/rust-lang/rust.git
synced 2024-10-31 14:31:55 +00:00
Add unsafe blocks, unsafe functions, and two rudimentary tests
related to them
This commit is contained in:
parent
29584cc5ac
commit
046ca827dd
@ -1552,10 +1552,12 @@ fn require_pure_call(ccx: @crate_ctxt, caller_purity: ast::purity,
|
||||
ccx.tcx.sess.span_fatal
|
||||
(sp, "safe function calls function marked unsafe");
|
||||
}
|
||||
//some(ast::def_native_fn(_)) {
|
||||
// ccx.tcx.sess.span_fatal
|
||||
// (sp, "native functions can only be invoked from unsafe code");
|
||||
//}
|
||||
/* Temporarily disable until unsafe blocks parse!
|
||||
some(ast::def_native_fn(_)) {
|
||||
ccx.tcx.sess.span_fatal
|
||||
(sp, "native functions can only be invoked from unsafe code");
|
||||
}
|
||||
*/
|
||||
_ {
|
||||
}
|
||||
}
|
||||
|
@ -2165,7 +2165,8 @@ fn parse_item(p: parser, attrs: [ast::attribute]) -> option::t<@ast::item> {
|
||||
let proto = parse_fn_proto(p);
|
||||
ret some(parse_item_fn_or_iter(p, ast::pure_fn, proto, attrs,
|
||||
ast::il_normal));
|
||||
} else if eat_word(p, "unsafe") {
|
||||
} else if is_word(p, "unsafe") && p.look_ahead(1u) != token::LBRACE {
|
||||
p.bump();
|
||||
expect_word(p, "fn");
|
||||
ret some(parse_item_fn_or_iter(p, ast::unsafe_fn, ast::proto_fn,
|
||||
attrs, ast::il_normal));
|
||||
|
@ -15,7 +15,9 @@ native "rust" mod rustrt {
|
||||
|
||||
/// Reserves space for `n` elements in the given vector.
|
||||
fn reserve<@T>(&v: [mutable? T], n: uint) {
|
||||
rustrt::vec_reserve_shared(v, n);
|
||||
//unsafe {
|
||||
rustrt::vec_reserve_shared(v, n);
|
||||
//}
|
||||
}
|
||||
|
||||
pure fn len<T>(v: [mutable? T]) -> uint { unchecked { rusti::vec_len(v) } }
|
||||
|
8
src/test/compile-fail/unsafe-fn-called-from-safe.rs
Normal file
8
src/test/compile-fail/unsafe-fn-called-from-safe.rs
Normal file
@ -0,0 +1,8 @@
|
||||
// -*- rust -*-
|
||||
// error-pattern: safe function calls function marked unsafe
|
||||
|
||||
unsafe fn f() { ret; }
|
||||
|
||||
fn main() {
|
||||
f();
|
||||
}
|
11
src/test/run-pass/unsafe-fn-called-from-unsafe-blk.rs
Normal file
11
src/test/run-pass/unsafe-fn-called-from-unsafe-blk.rs
Normal file
@ -0,0 +1,11 @@
|
||||
// -*- rust -*-
|
||||
//
|
||||
// See also: compile-fail/unsafe-fn-called-from-safe.rs
|
||||
|
||||
unsafe fn f() { ret; }
|
||||
|
||||
fn main() {
|
||||
unsafe {
|
||||
f();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user