[rust-dev] Borrow lifetime assignment changed?

Matthieu Monrocq matthieu.monrocq at gmail.com
Sun Jul 7 03:48:35 PDT 2013


On Sat, Jul 6, 2013 at 5:26 PM, Tommy M. McGuire <mcguire at crsr.net> wrote:

> On 07/03/2013 09:53 PM, Ashish Myles wrote:
> > hello.rs:4:8: 4:33 error: borrowed value does not live long enough
>
> I was just about to write asking about this. I discovered it with the
> following code:
>
>   for sorted_keys(dict).iter().advance |key| { ... }
>
> The result of sorted_keys is a temporary vector, which doesn't seem to
> live long enough for the iterator. If I give the temporary a name,
> everything works as expected.
>
>
> --
> Tommy M. McGuire
> mcguire at crsr.net
> _______________________________________________
> Rust-dev mailing list
> Rust-dev at mozilla.org
> https://mail.mozilla.org/listinfo/rust-dev
>

Interesting.

There is a specific rule in the C++ specification to address temporaries:
they should live up until the end of the full expression they are part of.

I suppose that to suppose this case Rust might need the same rule and then
determine that "for .... { }" is a single expression.

It seems feasible (and maybe partly addressed already) however I cannot
help but point out that I regularly see issues related to this popping on
the Clang list and commits to fix it "a bit more", apparently it's quite a
nest of vipers and has ripple effects on implementing pretty much any other
feature of the language.

-- Matthieu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/rust-dev/attachments/20130707/39806100/attachment-0001.html>


More information about the Rust-dev mailing list