Skip to content

Instantly share code, notes, and snippets.

@luqmana
Created July 29, 2013 19:13
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 luqmana/6106904 to your computer and use it in GitHub Desktop.
Save luqmana/6106904 to your computer and use it in GitHub Desktop.
fn find_fn(ccx: @mut CrateContext, fn_id: ast::node_id) -> Option<codemap::span> {
match ccx.tcx.def_map.find(&fn_id) {
Some(&ast::def_fn(def_id, _)) => {
if ast_util::is_local(def_id) {
match ccx.tcx.items.find(&def_id.node) {
Some(&ast_map::node_item(item, _)) => {
match item.node {
ast::item_fn(*) => Some(item.span),
_ => None
}
}
None => None
}
} else {
let search = csearch::maybe_get_item_ast(
ccx.tcx, def_id,
|a, b, c, d| astencode::decode_inlined_item(a, b, ccx.maps(), c.clone(), d));
match search {
csearch::found(ast::ii_item(item)) => {
match item.node {
ast::item_fn(*) => Some(item.span),
_ => None
}
}
_ => None
}
}
}
_ => None
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment