Skip to content

Commit 62d711e

Browse files
committed
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 rust-lang#3860
1 parent 47faeb9 commit 62d711e

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

src/librustc/middle/trans/base.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,8 +1018,16 @@ fn trans_stmt(cx: block, s: ast::stmt) -> block {
10181018
debuginfo::update_source_pos(cx, s.span);
10191019

10201020
match s.node {
1021-
ast::stmt_expr(e, _) | ast::stmt_semi(e, _) => {
1022-
bcx = expr::trans_into(cx, e, expr::Ignore);
1021+
ast::stmt_expr(e, s_id) | ast::stmt_semi(e, s_id) => {
1022+
// We introduce a new scope here because even though
1023+
// a statement of the form e; doesn't bind a new var,
1024+
// it might introduce a borrow, and borrowck may
1025+
// consider any statement to introduce a new scope.
1026+
bcx = with_scope(bcx, Some({id: s_id, span: s.span}),
1027+
stmt_to_str(s, cx.tcx().sess.intr()),
1028+
|cx| {
1029+
expr::trans_into(cx, e, expr::Ignore)
1030+
});
10231031
}
10241032
ast::stmt_decl(d, _) => {
10251033
match d.node {

src/test/run-pass/issue-3860.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// xfail-test
1211
struct Foo { x: int }
1312

1413
impl Foo {
@@ -19,11 +18,7 @@ impl Foo {
1918

2019
fn main() {
2120
let mut x = @mut Foo { x: 3 };
22-
x.stuff(); // error: internal compiler error: no enclosing scope with id 49
23-
// storing the result removes the error, so replacing the above
24-
// with the following, works:
25-
// let _y = x.stuff()
26-
27-
// also making 'stuff()' not return anything fixes it
28-
// I guess the "dangling &ptr" cuases issues?
29-
}
21+
// Neither of the next two lines should cause an error
22+
let _ = x.stuff();
23+
x.stuff();
24+
}

0 commit comments

Comments
 (0)