Skip to content

Instantly share code, notes, and snippets.

@nikhilshagri
Last active April 6, 2017 19:15
Show Gist options
  • Save nikhilshagri/51fb193ac8f347ba0ff4e6213c49904d to your computer and use it in GitHub Desktop.
Save nikhilshagri/51fb193ac8f347ba0ff4e6213c49904d to your computer and use it in GitHub Desktop.
pub fn get_pattern_source(&self, pat: &Pat) -> Option<PatternSource<'hir>> {
let id = // get id
match self.find(id) {
Some(NodeExpr(ref e)) => {
Some(PatternSource::MatchExpr(e))
}
Some(NodeStmt(ref s)) => {
match s.node {
StmtDecl(ref decl, _) => {
match decl.clone().unwrap().node {
DeclLocal(ref local) => Some(PatternSource::LetDecl(local)),
_ => {
return None;
},
}
}
_ => {
return None;
},
}
}
_ => {
return None;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment