Last active
August 29, 2015 14:02
-
-
Save wackywendell/4a1e2c5190480e3bef10 to your computer and use it in GitHub Desktop.
Fails to compile, with a complaint about "foo does not live long enough... reference must be valid for the static lifetime"
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 Foo { | |
n : int | |
} | |
struct Bar<'a> { | |
n : int, | |
other : Option<&'a mut Foo> | |
} | |
impl<'a> Bar<'a> { | |
fn set_foo(&mut self, foo : &'a mut Foo){ | |
self.other = Some(foo); | |
} | |
} | |
fn with_bar(func : |&mut Bar|) { | |
let mut bar = Bar { n : 1, other : None }; | |
func(&mut bar) | |
} | |
fn main() { | |
let mut foo = Foo { n : 4 }; | |
with_bar(|bar: &mut Bar| { | |
bar.set_foo(&mut foo); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment