From 62d711e2b237ad08979c44e10847e2ef4357c0b6 Mon Sep 17 00:00:00 2001 From: Tim Chevalier Date: Fri, 14 Dec 2012 15:54:33 -0800 Subject: [PATCH] Make trans treat all statements as if they introduce a new scope This is for consistency with borrowck. Changing borrowck would also be an alternative, but I found it easier to change trans :-) This eliminates an ICE in trans where the scope for a particular borrow was a statement ID, but the code in trans that does cleanups wasn't finding the block with that scope. As per #3860 --- src/librustc/middle/trans/base.rs | 12 ++++++++++-- src/test/run-pass/issue-3860.rs | 13 ++++--------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs index a65f6668cd358..10683f471a9cb 100644 --- a/src/librustc/middle/trans/base.rs +++ b/src/librustc/middle/trans/base.rs @@ -1018,8 +1018,16 @@ fn trans_stmt(cx: block, s: ast::stmt) -> block { debuginfo::update_source_pos(cx, s.span); match s.node { - ast::stmt_expr(e, _) | ast::stmt_semi(e, _) => { - bcx = expr::trans_into(cx, e, expr::Ignore); + ast::stmt_expr(e, s_id) | ast::stmt_semi(e, s_id) => { + // We introduce a new scope here because even though + // a statement of the form e; doesn't bind a new var, + // it might introduce a borrow, and borrowck may + // consider any statement to introduce a new scope. + bcx = with_scope(bcx, Some({id: s_id, span: s.span}), + stmt_to_str(s, cx.tcx().sess.intr()), + |cx| { + expr::trans_into(cx, e, expr::Ignore) + }); } ast::stmt_decl(d, _) => { match d.node { diff --git a/src/test/run-pass/issue-3860.rs b/src/test/run-pass/issue-3860.rs index 7e01640ce406f..7a7c307e23d76 100644 --- a/src/test/run-pass/issue-3860.rs +++ b/src/test/run-pass/issue-3860.rs @@ -8,7 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// xfail-test struct Foo { x: int } impl Foo { @@ -19,11 +18,7 @@ impl Foo { fn main() { let mut x = @mut Foo { x: 3 }; - x.stuff(); // error: internal compiler error: no enclosing scope with id 49 - // storing the result removes the error, so replacing the above - // with the following, works: - // let _y = x.stuff() - - // also making 'stuff()' not return anything fixes it - // I guess the "dangling &ptr" cuases issues? -} + // Neither of the next two lines should cause an error + let _ = x.stuff(); + x.stuff(); +} \ No newline at end of file