Skip to content

rooting of boxes in borrowck fails to take moves into account #3053

Closed
@nikomatsakis

Description

@nikomatsakis

The following code:

// exec-env:RUST_POISON_ON_FREE=1

fn free<T>(-x: @T) {}

fn lend(+x: @{f: @{g: int}}) -> int {
    let y = &x.f.g;
    free(x);
    *y
}

fn main() {
    assert lend(@{f: @{g: 22}}) == 22;
}

is handled incorrectly by borrowck right now. It will opt not to root the x.f box even though it ought to. This is because it sees that x.f is found in immutable data which will outlive the lifetime of the borrow: but it doesn't consider moves. To be correct, it should either (1) know which variables might be moved (liveness can tell us) and conservatively root boxes that are found in those variables or (2) take out a loan on x so that an error would be reported. But (2) seems suboptimal since this is not really an error, just a failure of borrowck to make the right call on whether to root x.f.

Metadata

Metadata

Assignees

Labels

A-lifetimesArea: Lifetimes / regionsI-crashIssue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions