From 062a05dde8c3ea5386fa358d882e1eaca99a9ff0 Mon Sep 17 00:00:00 2001 From: Eduard Burtescu Date: Tue, 23 Feb 2016 21:10:29 +0200 Subject: metadata: Constrain FoundAst::FoundParent to an Item. --- src/librustc_metadata/decoder.rs | 63 +++++++++++++++------------------------- 1 file changed, 23 insertions(+), 40 deletions(-) (limited to 'src/librustc_metadata/decoder.rs') diff --git a/src/librustc_metadata/decoder.rs b/src/librustc_metadata/decoder.rs index 579996807d4..7af01d8abe7 100644 --- a/src/librustc_metadata/decoder.rs +++ b/src/librustc_metadata/decoder.rs @@ -798,53 +798,36 @@ pub fn get_item_name(intr: &IdentInterner, cdata: Cmd, id: DefIndex) -> ast::Nam item_name(intr, cdata.lookup_item(id)) } -pub fn maybe_get_item_ast<'tcx>(cdata: Cmd, - tcx: &TyCtxt<'tcx>, - id: DefIndex, +pub fn maybe_get_item_ast<'tcx>(cdata: Cmd, tcx: &TyCtxt<'tcx>, id: DefIndex) -> FoundAst<'tcx> { debug!("Looking up item: {:?}", id); let item_doc = cdata.lookup_item(id); let item_did = item_def_id(item_doc, cdata); - let parent_path = { - let mut path = item_path(item_doc); - path.pop(); - path - }; - let parent_def_path = { - let mut def_path = def_path(cdata, id); - def_path.pop(); - def_path - }; - match decode_inlined_item(cdata, - tcx, - parent_path, - parent_def_path, - item_doc, - item_did) { - Ok(ii) => FoundAst::Found(ii), - Err((mut parent_path, mut parent_def_path)) => { - match item_parent_item(cdata, item_doc) { - Some(parent_did) => { - // Remove the last element from the paths, since we are now - // trying to inline the parent. - parent_path.pop(); - parent_def_path.pop(); - - let parent_item = cdata.lookup_item(parent_did.index); - match decode_inlined_item(cdata, - tcx, - parent_path, - parent_def_path, - parent_item, - parent_did) { - Ok(ii) => FoundAst::FoundParent(parent_did, ii), - Err(_) => FoundAst::NotFound - } - } - None => FoundAst::NotFound + let mut parent_path = item_path(item_doc); + parent_path.pop(); + let mut parent_def_path = def_path(cdata, id); + parent_def_path.pop(); + if let Some(ast_doc) = reader::maybe_get_doc(item_doc, tag_ast as usize) { + let ii = decode_inlined_item(cdata, tcx, parent_path, + parent_def_path, + ast_doc, item_did); + return FoundAst::Found(ii); + } else if let Some(parent_did) = item_parent_item(cdata, item_doc) { + // Remove the last element from the paths, since we are now + // trying to inline the parent. + parent_path.pop(); + parent_def_path.pop(); + let parent_doc = cdata.lookup_item(parent_did.index); + if let Some(ast_doc) = reader::maybe_get_doc(parent_doc, tag_ast as usize) { + let ii = decode_inlined_item(cdata, tcx, parent_path, + parent_def_path, + ast_doc, parent_did); + if let &InlinedItem::Item(ref i) = ii { + return FoundAst::FoundParent(parent_did, i); } } } + FoundAst::NotFound } pub fn is_item_mir_available<'tcx>(cdata: Cmd, id: DefIndex) -> bool { -- cgit 1.4.1-3-g733a5