Created
July 27, 2013 09:02
-
-
Save luqmana/6094308 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
struct Parent; | |
impl Parent { | |
fn new_child<'a>(&'a self) -> Child<'a> { | |
Child { | |
parent: self | |
} | |
} | |
} | |
struct Child<'self> { | |
parent: &'self Parent | |
} | |
impl<'self> Child<'self> { | |
fn foo(&self) {} | |
} | |
fn main() { | |
let child; | |
{ | |
let parent = Parent; | |
child = parent.new_child(); | |
} | |
child.foo(); | |
} |
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
-> % rustc test.rs | |
test.rs:22:16: 22:22 error: borrowed value does not live long enough | |
test.rs:22 child = parent.new_child(); | |
^~~~~~ | |
test.rs:18:10: 26:1 note: borrowed pointer must be valid for the block at 18:10... | |
test.rs:18 fn main() { | |
test.rs:19 let child; | |
test.rs:20 { | |
test.rs:21 let parent = Parent; | |
test.rs:22 child = parent.new_child(); | |
test.rs:23 } | |
... | |
test.rs:20:4: 23:5 note: ...but borrowed value is only valid for the block at 20:4 | |
test.rs:20 { | |
test.rs:21 let parent = Parent; | |
test.rs:22 child = parent.new_child(); | |
test.rs:23 } | |
error: aborting due to previous error |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment