Make calling def_id on a DefSelfTy an error; the previous defids that

were returned, either the trait or the *self type itself*, were not
particularly representative of what the Def is (a type parameter).
Rewrite paths to handle this case specially, just as they handle the
primitive case specifically. This entire `def_id` codepath is kind of a
mess.
This commit is contained in:
Niko Matsakis 2015-09-08 10:08:30 -04:00
parent 95ce1ebe7c
commit 3b1399df2d
7 changed files with 17 additions and 9 deletions

View file

@ -2570,17 +2570,19 @@ fn name_from_pat(p: &hir::Pat) -> String {
fn resolve_type(cx: &DocContext,
path: Path,
id: ast::NodeId) -> Type {
debug!("resolve_type({:?},{:?})", path, id);
let tcx = match cx.tcx_opt() {
Some(tcx) => tcx,
// If we're extracting tests, this return value doesn't matter.
None => return Primitive(Bool),
};
debug!("searching for {} in defmap", id);
let def = match tcx.def_map.borrow().get(&id) {
Some(k) => k.full_def(),
None => panic!("unresolved id not in defmap")
};
debug!("resolve_type: def={:?}", def);
let is_generic = match def {
def::DefPrimTy(p) => match p {
hir::TyStr => return Primitive(Str),
@ -2610,6 +2612,8 @@ fn resolve_type(cx: &DocContext,
}
fn register_def(cx: &DocContext, def: def::Def) -> DefId {
debug!("register_def({:?})", def);
let (did, kind) = match def {
def::DefFn(i, _) => (i, TypeFunction),
def::DefTy(i, false) => (i, TypeTypedef),
@ -2619,6 +2623,8 @@ fn register_def(cx: &DocContext, def: def::Def) -> DefId {
def::DefMod(i) => (i, TypeModule),
def::DefStatic(i, _) => (i, TypeStatic),
def::DefVariant(i, _, _) => (i, TypeEnum),
def::DefSelfTy(Some(def_id), _) => (def_id, TypeTrait),
def::DefSelfTy(_, Some((impl_id, _))) => return cx.map.local_def_id(impl_id),
_ => return def.def_id()
};
if did.is_local() { return did }