Hi Rusters, I'm very new to Rust, so I'd like you to check if this is really a compiler bug or not.
fn main() { let s1 = &[0i]; { let s2 = &[0i]; let s3 = if true { s1 } else { s2 }; }; } http://is.gd/NCeGpl <anon>:5:19: 5:23 error: borrowed value does not live long enough <anon>:5 let s2 = &[0i]; ^~~~ <anon>:2:11: 8:2 note: reference must be valid for the block at 2:10... <anon>:2 fn main() { <anon>:3 let s1 = &[0i]; <anon>:4 { <anon>:5 let s2 = &[0i]; <anon>:6 let s3 = if true { s1 } else { s2 }; <anon>:7 }; ... <anon>:4:5: 7:6 note: ...but borrowed value is only valid for the block at 4:4 <anon>:4 { <anon>:5 let s2 = &[0i]; <anon>:6 let s3 = if true { s1 } else { s2 }; <anon>:7 }; error: aborting due to previous error Seems like s1 and s2 are inferred as &[int, ..1] and when I manually type them as &[int], it successfully compiles. fn main() { let s1: &[int] = &[0i]; { let s2: &[int] = &[0i]; let s3 = if true { s1 } else { s2 }; }; } Putting s1 and s2 into a single block also satisfies the compiler. fn main() { let s1 = &[0i]; let s2 = &[0i]; let s3 = if true { s1 } else { s2 }; } I came from C++ and I think the way I take reference of a fixed vector literal is correct. http://doc.rust-lang.org/rust.html#pointer-types I was originally trying to fix this line which doesn't compile with the nightly build of Rust: https://github.com/servo/rust-url/blob/master/src/form_urlencoded.rs#L55 No similar issue is filed here: https://github.com/rust-lang/rust/labels/A-lifetimes Best regards, Kai 野田 開 <noda...@gmail.com>
_______________________________________________ Rust-dev mailing list Rust-dev@mozilla.org https://mail.mozilla.org/listinfo/rust-dev