introduce new DefPathData variants for traits, assoc types

This commit is contained in:
Niko Matsakis 2018-03-30 00:51:39 -04:00
parent cfbf62f7df
commit 09bd6f3ee7
4 changed files with 41 additions and 5 deletions

View File

@ -107,8 +107,9 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
// information we encapsulate into
let def_data = match i.node {
ItemKind::Impl(..) => DefPathData::Impl,
ItemKind::Trait(..) => DefPathData::Trait(i.ident.name.as_str()),
ItemKind::Enum(..) | ItemKind::Struct(..) | ItemKind::Union(..) |
ItemKind::Trait(..) | ItemKind::TraitAlias(..) |
ItemKind::TraitAlias(..) |
ItemKind::ExternCrate(..) | ItemKind::ForeignMod(..) | ItemKind::Ty(..) =>
DefPathData::TypeNs(i.ident.name.as_str()),
ItemKind::Mod(..) if i.ident == keywords::Invalid.ident() => {
@ -222,7 +223,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
let def_data = match ti.node {
TraitItemKind::Method(..) | TraitItemKind::Const(..) =>
DefPathData::ValueNs(ti.ident.name.as_str()),
TraitItemKind::Type(..) => DefPathData::TypeNs(ti.ident.name.as_str()),
TraitItemKind::Type(..) => DefPathData::AssocTypeInTrait(ti.ident.name.as_str()),
TraitItemKind::Macro(..) => return self.visit_macro_invoc(ti.id, false),
};
@ -240,7 +241,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
let def_data = match ii.node {
ImplItemKind::Method(..) | ImplItemKind::Const(..) =>
DefPathData::ValueNs(ii.ident.name.as_str()),
ImplItemKind::Type(..) => DefPathData::TypeNs(ii.ident.name.as_str()),
ImplItemKind::Type(..) => DefPathData::AssocTypeInImpl(ii.ident.name.as_str()),
ImplItemKind::Macro(..) => return self.visit_macro_invoc(ii.id, false),
};

View File

@ -212,6 +212,9 @@ impl DefKey {
::std::mem::discriminant(data).hash(&mut hasher);
match *data {
DefPathData::TypeNs(name) |
DefPathData::Trait(name) |
DefPathData::AssocTypeInTrait(name) |
DefPathData::AssocTypeInImpl(name) |
DefPathData::ValueNs(name) |
DefPathData::Module(name) |
DefPathData::MacroDef(name) |
@ -358,6 +361,12 @@ pub enum DefPathData {
// Different kinds of items and item-like things:
/// An impl
Impl,
/// A trait
Trait(InternedString),
/// An associated type **declaration** (i.e., in a trait)
AssocTypeInTrait(InternedString),
/// An associated type **value** (i.e., in an impl)
AssocTypeInImpl(InternedString),
/// Something in the type NS
TypeNs(InternedString),
/// Something in the value NS
@ -639,6 +648,9 @@ impl DefPathData {
use self::DefPathData::*;
match *self {
TypeNs(name) |
Trait(name) |
AssocTypeInTrait(name) |
AssocTypeInImpl(name) |
ValueNs(name) |
Module(name) |
MacroDef(name) |
@ -663,6 +675,9 @@ impl DefPathData {
use self::DefPathData::*;
let s = match *self {
TypeNs(name) |
Trait(name) |
AssocTypeInTrait(name) |
AssocTypeInImpl(name) |
ValueNs(name) |
Module(name) |
MacroDef(name) |

View File

@ -204,6 +204,9 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
// finer-grained distinctions, e.g. between enum/struct).
data @ DefPathData::Misc |
data @ DefPathData::TypeNs(..) |
data @ DefPathData::Trait(..) |
data @ DefPathData::AssocTypeInTrait(..) |
data @ DefPathData::AssocTypeInImpl(..) |
data @ DefPathData::ValueNs(..) |
data @ DefPathData::Module(..) |
data @ DefPathData::TypeParam(..) |

View File

@ -268,14 +268,31 @@ impl PrintContext {
loop {
let key = tcx.def_key(item_def_id);
match key.disambiguated_data.data {
DefPathData::AssocTypeInTrait(_) |
DefPathData::AssocTypeInImpl(_) |
DefPathData::Trait(_) |
DefPathData::TypeNs(_) => {
break;
}
DefPathData::ValueNs(_) | DefPathData::EnumVariant(_) => {
DefPathData::ValueNs(_) |
DefPathData::EnumVariant(_) => {
is_value_path = true;
break;
}
_ => {
DefPathData::CrateRoot |
DefPathData::Misc |
DefPathData::Impl |
DefPathData::Module(_) |
DefPathData::MacroDef(_) |
DefPathData::ClosureExpr |
DefPathData::TypeParam(_) |
DefPathData::LifetimeDef(_) |
DefPathData::Field(_) |
DefPathData::StructCtor |
DefPathData::Initializer |
DefPathData::ImplTrait |
DefPathData::Typeof |
DefPathData::GlobalMetaData(_) => {
// if we're making a symbol for something, there ought
// to be a value or type-def or something in there
// *somewhere*