1
Fork 0

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

@ -99,6 +99,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
} }
_ if self.ignore_non_const_paths => (), _ if self.ignore_non_const_paths => (),
def::DefPrimTy(_) => (), def::DefPrimTy(_) => (),
def::DefSelfTy(..) => (),
def::DefVariant(enum_id, variant_id, _) => { def::DefVariant(enum_id, variant_id, _) => {
self.check_def_id(enum_id); self.check_def_id(enum_id);
if !self.ignore_variant_stack.contains(&variant_id) { if !self.ignore_variant_stack.contains(&variant_id) {

View file

@ -135,14 +135,12 @@ impl Def {
DefFn(id, _) | DefMod(id) | DefForeignMod(id) | DefStatic(id, _) | DefFn(id, _) | DefMod(id) | DefForeignMod(id) | DefStatic(id, _) |
DefVariant(_, id, _) | DefTy(id, _) | DefAssociatedTy(_, id) | DefVariant(_, id, _) | DefTy(id, _) | DefAssociatedTy(_, id) |
DefTyParam(_, _, id, _) | DefUse(id) | DefStruct(id) | DefTrait(id) | DefTyParam(_, _, id, _) | DefUse(id) | DefStruct(id) | DefTrait(id) |
DefMethod(id) | DefConst(id) | DefAssociatedConst(id) | DefMethod(id) | DefConst(id) | DefAssociatedConst(id) => {
DefSelfTy(Some(id), None)=> {
id id
} }
DefLocal(id) | DefLocal(id) |
DefUpvar(id, _, _) | DefUpvar(id, _, _) => {
DefSelfTy(_, Some((_, id))) => {
DefId::xxx_local(id) // TODO, clearly DefId::xxx_local(id) // TODO, clearly
} }

View file

@ -474,6 +474,7 @@ pub fn check_path(tcx: &ty::ctxt, path: &hir::Path, id: ast::NodeId,
cb: &mut FnMut(DefId, Span, &Option<&Stability>)) { cb: &mut FnMut(DefId, Span, &Option<&Stability>)) {
match tcx.def_map.borrow().get(&id).map(|d| d.full_def()) { match tcx.def_map.borrow().get(&id).map(|d| d.full_def()) {
Some(def::DefPrimTy(..)) => {} Some(def::DefPrimTy(..)) => {}
Some(def::DefSelfTy(..)) => {}
Some(def) => { Some(def) => {
maybe_do_stability_check(tcx, def.def_id(), path.span, cb); maybe_do_stability_check(tcx, def.def_id(), path.span, cb);
} }

View file

@ -263,6 +263,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for EmbargoVisitor<'a, 'tcx> {
hir::TyPath(..) => { hir::TyPath(..) => {
match self.tcx.def_map.borrow().get(&ty.id).unwrap().full_def() { match self.tcx.def_map.borrow().get(&ty.id).unwrap().full_def() {
def::DefPrimTy(..) => true, def::DefPrimTy(..) => true,
def::DefSelfTy(..) => true,
def => { def => {
let did = def.def_id(); let did = def.def_id();
if let Some(node_id) = self.tcx.map.as_local_node_id(did) { if let Some(node_id) = self.tcx.map.as_local_node_id(did) {
@ -337,7 +338,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for EmbargoVisitor<'a, 'tcx> {
hir::ItemTy(ref ty, _) if public_first => { hir::ItemTy(ref ty, _) if public_first => {
if let hir::TyPath(..) = ty.node { if let hir::TyPath(..) = ty.node {
match self.tcx.def_map.borrow().get(&ty.id).unwrap().full_def() { match self.tcx.def_map.borrow().get(&ty.id).unwrap().full_def() {
def::DefPrimTy(..) | def::DefTyParam(..) => {}, def::DefPrimTy(..) | def::DefSelfTy(..) | def::DefTyParam(..) => {},
def => { def => {
let did = def.def_id(); let did = def.def_id();
if let Some(node_id) = self.tcx.map.as_local_node_id(did) { if let Some(node_id) = self.tcx.map.as_local_node_id(did) {
@ -1148,7 +1149,7 @@ impl<'a, 'tcx> VisiblePrivateTypesVisitor<'a, 'tcx> {
fn path_is_private_type(&self, path_id: ast::NodeId) -> bool { fn path_is_private_type(&self, path_id: ast::NodeId) -> bool {
let did = match self.tcx.def_map.borrow().get(&path_id).map(|d| d.full_def()) { let did = match self.tcx.def_map.borrow().get(&path_id).map(|d| d.full_def()) {
// `int` etc. (None doesn't seem to occur.) // `int` etc. (None doesn't seem to occur.)
None | Some(def::DefPrimTy(..)) => return false, None | Some(def::DefPrimTy(..)) | Some(def::DefSelfTy(..)) => return false,
Some(def) => def.def_id(), Some(def) => def.def_id(),
}; };

View file

@ -235,7 +235,8 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
} }
let def = self.tcx.def_map.borrow().get(&ref_id).unwrap().full_def(); let def = self.tcx.def_map.borrow().get(&ref_id).unwrap().full_def();
match def { match def {
def::DefPrimTy(_) => None, def::DefPrimTy(..) => None,
def::DefSelfTy(..) => None,
_ => Some(def.def_id()), _ => Some(def.def_id()),
} }
} }

View file

@ -637,7 +637,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
} }
let def = self.tcx.def_map.borrow().get(&ref_id).unwrap().full_def(); let def = self.tcx.def_map.borrow().get(&ref_id).unwrap().full_def();
match def { match def {
def::DefPrimTy(_) => None, def::DefPrimTy(_) | def::DefSelfTy(..) => None,
_ => Some(def.def_id()), _ => Some(def.def_id()),
} }
} }

View file

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