Quantcast
Channel: Recent Gists from luqmana
Viewing all articles
Browse latest Browse all 41

fail-parent-child.rs

$
0
0
fail-parent-child.rs
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();
}
gistfile1.txt
-> % 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

Viewing all articles
Browse latest Browse all 41

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>