提交 60603703 编写于 作者: N Niko Matsakis

handle moves in let initializers and allow moves from unsafe ptrs

Related to issue #2657, but this is not a complete fix.
上级 f9afce31
......@@ -47,6 +47,7 @@ fn check_loans(bccx: borrowck_ctxt,
mut declared_purity: ast::impure_fn,
mut fn_args: @[]});
let vt = visit::mk_vt(@{visit_expr: check_loans_in_expr,
visit_local: check_loans_in_local,
visit_block: check_loans_in_block,
visit_fn: check_loans_in_fn
with *visit::default_visitor()});
......@@ -419,6 +420,9 @@ fn check_move_out_from_cmt(cmt: cmt) {
// rvalues, I guess.
cat_special(sk_static_item) { }
cat_deref(_, _, unsafe_ptr) {
}
// Nothing else.
_ {
self.bccx.span_err(
......@@ -542,6 +546,18 @@ fn check_loans_in_fn(fk: visit::fn_kind, decl: ast::fn_decl, body: ast::blk,
#debug["purity on exit=%?", copy self.declared_purity];
}
fn check_loans_in_local(local: @ast::local,
&&self: check_loan_ctxt,
vt: visit::vt<check_loan_ctxt>) {
alt local.node.init {
some({op: ast::init_move, expr: expr}) {
self.check_move_out(expr);
}
some({op: ast::init_assign, _}) | none {}
}
visit::visit_local(local, self, vt);
}
fn check_loans_in_expr(expr: @ast::expr,
&&self: check_loan_ctxt,
vt: visit::vt<check_loan_ctxt>) {
......
fn main() {
let x = some(~1);
alt x { //! NOTE loan of immutable local variable granted here
some(y) {
let _a <- x; //! ERROR moving out of immutable local variable prohibited due to outstanding loan
}
_ {}
}
}
//xfail-test
// this should be illegal but borrowck is not handling
// pattern bindings correctly right now
fn main() {
let x = some(~1);
alt x {
some(y) {
let b <- y;
}
_ {}
}
}
fn foo(x: *~int) -> ~int {
let y <- *x; //! ERROR dereference of unsafe pointer requires unsafe function or block
ret y;
}
fn main() {
}
\ No newline at end of file
// just make sure this compiles:
fn bar(x: *~int) -> ~int {
unsafe {
let y <- *x;
ret y;
}
}
fn main() {
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册