Created
August 26, 2013 02:04
-
-
Save mythmon/6337540 to your computer and use it in GitHub Desktop.
Short self contained test case demonstrating something I don't understand about rust.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn foo<T:Copy>(arr: ~[T]) -> ~[T] { | |
~[arr[0]] | |
} | |
fn main() { | |
let bar = ~[1,2,3]; | |
for foo(bar).iter().advance |i| { | |
println(fmt!("%?", i)); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> rust run test.rs | |
test.rs:8:8: 8:17 error: borrowed value does not live long enough | |
test.rs:8 for foo(bar).iter().advance |i| { | |
^~~~~~~~~ | |
test.rs:10:4: 10:5 note: borrowed pointer must be valid for the method call at 10:4... | |
test.rs:10 } | |
^ | |
test.rs:8:8: 8:24 note: ...but borrowed value is only valid for the method call at 8:8 | |
test.rs:8 for foo(bar).iter().advance |i| { | |
^~~~~~~~~~~~~~~~ | |
test.rs:8:12: 8:15 error: use of moved value: `bar` | |
test.rs:8 for foo(bar).iter().advance |i| { | |
^~~ | |
test.rs:7:27: 7:30 note: `bar` moved here because it has type `~[int]`, which is moved by default (use `copy` to override) | |
test.rs:7 println(fmt!("%?", foo(bar))); | |
^~~ | |
note: in expansion of fmt! | |
test.rs:7:12: 7:33 note: expansion site | |
error: aborting due to 2 previous errors |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment