Skip to content

Make trans treat all statements as if they introduce a new scope #4192

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}