Skip to content

Instantly share code, notes, and snippets.

@huonw
Last active December 15, 2015 04:39
Show Gist options
  • Save huonw/5203456 to your computer and use it in GitHub Desktop.
Save huonw/5203456 to your computer and use it in GitHub Desktop.
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);
}
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