Skip to content

Instantly share code, notes, and snippets.

@jmgrosen
Created July 28, 2013 23:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmgrosen/6100721 to your computer and use it in GitHub Desktop.
Save jmgrosen/6100721 to your computer and use it in GitHub Desktop.
use std::hashmap::HashMap;
enum Thing { Foo, Bar }
struct Context<'self> {
scope: HashMap<&'self str, Thing>,
parent: &'self Option<Context<'self>>
}
impl<'self> Context<'self> {
fn get(&self, identifier: &str) -> Option<&'self Thing> {
match self.scope.find_equiv(&identifier) {
Some(thing) => Some(thing),
None => match (*self.parent) {
Some(parent) => parent.get(identifier),
None => None
}
}
}
}
fn main() {}
@jmgrosen
Copy link
Author

help.rs:12:14: 12:50 error: cannot infer an appropriate lifetime due to conflicting requirements
help.rs:12         match self.scope.find_equiv(&identifier) {
                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
help.rs:13:27: 13:39 note: first, the lifetime cannot outlive the call at 13:27...
help.rs:13             Some(thing) => Some(thing),
                                      ^~~~~~~~~~~~
help.rs:13:27: 13:39 note: ...due to the following expression
help.rs:13             Some(thing) => Some(thing),
                                      ^~~~~~~~~~~~
help.rs:12:14: 12:24 note: but, the lifetime must be valid for the expression at 12:14...
help.rs:12         match self.scope.find_equiv(&identifier) {
                         ^~~~~~~~~~
help.rs:12:14: 12:24 note: ...due to the following expression
help.rs:12         match self.scope.find_equiv(&identifier) {
                         ^~~~~~~~~~
error: aborting due to previous error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment