On Sat, Jul 6, 2013 at 5:26 PM, Tommy M. McGuire <[email protected]> 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
> [email protected]
> _______________________________________________
> Rust-dev mailing list
> [email protected]
> 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
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev