Closed
Description
fn main() {
let foo;
let bar = 1337;
foo = &bar;
}
$ rustc lifetime.rs
lifetime.rs:4:12: 4:15 error: `bar` does not live long enough
lifetime.rs:4 foo = &bar;
^~~
lifetime.rs:2:12: 5:2 note: reference must be valid for the block suffix following statement 0 at 2:11...
lifetime.rs:2 let foo;
lifetime.rs:3 let bar = 1337;
lifetime.rs:4 foo = &bar;
lifetime.rs:5 }
lifetime.rs:3:19: 5:2 note: ...but borrowed value is only valid for the block suffix following statement 1 at 3:18
lifetime.rs:3 let bar = 1337;
lifetime.rs:4 foo = &bar;
lifetime.rs:5 }
error: aborting due to previous error
foo
and bar
go out of scope simultaneously, so the error can only refer to the fact that bar
's lifetime begins after foo
's lifetime. But that still doesn't make sense, as bar
is alive when the reference to it is assigned to foo
.
I'm using the nightly builds from the Ubuntu PPA:
$ rustc --version --verbose
rustc 1.0.0-dev
binary: rustc
commit-hash: unknown
commit-date: unknown
host: x86_64-unknown-linux-gnu
release: 1.0.0-dev