News for hackers. Stuff that matters.
Re:Rust, Lifetimes, and Collections by renox on Friday November 21, 2014 @10:54AM (#8641772)
I'm quite surprised by Rust behaviour here: if x isn't used after 'v.push(6);' (doesn't seem too difficult to know by the compiler) then I would have expected the compiler to allow this code and to reject it only if x is used after the 'v.push(6)'.. Sure as he explained you can do "let mut v = vec![1i32, 2, 3, 4, 5]; { let x = v.get(2); <work with x> } v.push(6);" but this must be quite annoying..
Re:Rust, Lifetimes, and Collections by Jweb_Guru on Saturday November 22, 2014 @08:24AM (#8645503)
Currently, borrows last for block scope, which is why this doesn't work. There is a feature in the making called SEME (single entry, multiple exit) which will resolve this and other annoying borrow hazards. It at least at one point was considered a priority for 1.0.
Re:Rust, Lifetimes, and Collections by kibwen on Saturday November 22, 2014 @01:21AM (#8644950)
I think this might be more difficult than it seems, given that Rust allows you to store references in structs. I'll ask the developers sometime.