Skip to content

Instantly share code, notes, and snippets.

@stepancheg
Last active August 29, 2015 14:08
Show Gist options
  • Save stepancheg/abb2b6ef3305945b270b to your computer and use it in GitHub Desktop.
Save stepancheg/abb2b6ef3305945b270b to your computer and use it in GitHub Desktop.
tmp.rs:8:9: 8:13 error: `copy` does not live long enough
tmp.rs:8 copy.walk(|a| callback(a));
^~~~
tmp.rs:6:45: 9:6 note: reference must be valid for the lifetime 'a as defined on the block at 6:44...
tmp.rs:6 fn walk(&'a self, callback: |&Aaa<'a>|) {
tmp.rs:7 let copy = Aaa { dummy: self.dummy };
tmp.rs:8 copy.walk(|a| callback(a));
tmp.rs:9 }
tmp.rs:6:45: 9:6 note: ...but borrowed value is only valid for the block at 6:44
tmp.rs:6 fn walk(&'a self, callback: |&Aaa<'a>|) {
tmp.rs:7 let copy = Aaa { dummy: self.dummy };
tmp.rs:8 copy.walk(|a| callback(a));
tmp.rs:9 }
error: aborting due to previous error
struct Aaa<'a> {
dummy: &'a u32,
}
impl<'a> Aaa<'a> {
fn walk(&'a self, callback: |&Aaa<'a>|) {
let copy = Aaa { dummy: self.dummy };
copy.walk(|a| callback(a));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment