[rust-dev] Help understanding lifetimes.

Steven Blenkinsop steven099 at gmail.com
Mon Dec 24 21:25:36 PST 2012


Turns out the issue was borrowing from a reborrowed value.  i.e. this
doesn't work:

fn rereborrow(v: &r/int) -> &r/int {
    &*&*v
}

I've filed an issue: https://github.com/mozilla/rust/issues/4285

Incidentally, I can make my original code work by eliminating the
intermediate borrow:

struct T1 { value: int }
struct T2 { t1: option::Option<~T1> }

fn value(t2: &r/T2, def: &r/int) -> &r/int {
        match t2.t1 {
                Some(~T1{value: ref value}) => value,
                None => def
        }
}

fn main() {
        let t2 = ~T2{ t1: Some(~T1{ value: 5 }) };
        let def = ~0;
        io::println(fmt!("%d", *value(t2, def)));
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/rust-dev/attachments/20121225/2f331c06/attachment.html>


More information about the Rust-dev mailing list