Skip to content

Commit

Permalink
Make trans treat all statements as if they introduce a new scope
Browse files Browse the repository at this point in the history
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 rust-lang#3860
  • Loading branch information
catamorphism committed Dec 14, 2012
1 parent 47faeb9 commit 62d711e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
12 changes: 10 additions & 2 deletions src/librustc/middle/trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
13 changes: 4 additions & 9 deletions src/test/run-pass/issue-3860.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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();
}

0 comments on commit 62d711e

Please sign in to comment.