Introduce TyCtxt::expect_def/expect_resolution helpers and use them where possible

This commit is contained in:
Vadim Petrochenkov 2016-06-03 23:15:00 +03:00
parent 4c30f6405c
commit ee4e55398b
42 changed files with 276 additions and 472 deletions

View file

@ -50,8 +50,8 @@ pub fn try_inline(cx: &DocContext, id: ast::NodeId, into: Option<ast::Name>)
Some(tcx) => tcx,
None => return None,
};
let def = match tcx.def_map.borrow().get(&id) {
Some(d) => d.full_def(),
let def = match tcx.expect_def_or_none(id) {
Some(def) => def,
None => return None,
};
let did = def.def_id();

View file

@ -2631,7 +2631,7 @@ fn resolve_type(cx: &DocContext,
};
}
};
let def = tcx.def_map.borrow().get(&id).expect("unresolved id not in defmap").full_def();
let def = tcx.expect_def(id);
debug!("resolve_type: def={:?}", def);
let is_generic = match def {
@ -2700,7 +2700,7 @@ fn resolve_use_source(cx: &DocContext, path: Path, id: ast::NodeId) -> ImportSou
fn resolve_def(cx: &DocContext, id: ast::NodeId) -> Option<DefId> {
cx.tcx_opt().and_then(|tcx| {
tcx.def_map.borrow().get(&id).map(|d| register_def(cx, d.full_def()))
tcx.expect_def_or_none(id).map(|def| register_def(cx, def))
})
}

View file

@ -241,7 +241,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
Some(tcx) => tcx,
None => return false
};
let def = tcx.def_map.borrow()[&id];
let def = tcx.expect_def(id);
let def_did = def.def_id();
let use_attrs = tcx.map.attrs(id).clean(self.cx);
@ -251,10 +251,10 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
// reachable in documentation - a previously nonreachable item can be
// made reachable by cross-crate inlining which we're checking here.
// (this is done here because we need to know this upfront)
if !def.def_id().is_local() && !is_no_inline {
if !def_did.is_local() && !is_no_inline {
let attrs = clean::inline::load_attrs(self.cx, tcx, def_did);
let self_is_hidden = attrs.list("doc").has_word("hidden");
match def.base_def {
match def {
Def::Trait(did) |
Def::Struct(did) |
Def::Enum(did) |