Last active
December 15, 2015 04:39
-
-
Save huonw/5203456 to your computer and use it in GitHub Desktop.
This file contains 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 borrow(s: &'a str) -> &'a str { | |
s | |
} | |
fn make_str() -> ~str { ~"foo" } | |
fn main() { | |
let x = borrow(make_str()); | |
/* Current solution: | |
let temp = make_str(); | |
let x = borrow(temp) | |
*/ | |
io::println(x); | |
} |
This file contains 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
borrow.rs:8:19: 8:30 error: illegal borrow: borrowed value does not live long enough | |
borrow.rs:8 let x = borrow(make_str()); | |
^~~~~~~~~~~ | |
borrow.rs:7:10: 1:0 note: borrowed pointer must be valid for the block at 7:10... | |
borrow.rs:8:12: 8:31 note: ...but borrowed value is only valid for the call at 8:12 | |
borrow.rs:8 let x = borrow(make_str()); | |
^~~~~~~~~~~~~~~~~~~ | |
error: aborting due to previous error |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment