diff --git a/src/librustc/hir/map/def_collector.rs b/src/librustc/hir/map/def_collector.rs index 4bd857c73e6c..bfe21549e453 100644 --- a/src/librustc/hir/map/def_collector.rs +++ b/src/librustc/hir/map/def_collector.rs @@ -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), }; diff --git a/src/librustc/hir/map/definitions.rs b/src/librustc/hir/map/definitions.rs index 1a2840de447d..12f146ef4911 100644 --- a/src/librustc/hir/map/definitions.rs +++ b/src/librustc/hir/map/definitions.rs @@ -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) | diff --git a/src/librustc/ty/item_path.rs b/src/librustc/ty/item_path.rs index 8189064db696..2819141c81be 100644 --- a/src/librustc/ty/item_path.rs +++ b/src/librustc/ty/item_path.rs @@ -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(..) | diff --git a/src/librustc/util/ppaux.rs b/src/librustc/util/ppaux.rs index dd478967b185..84e3358ff138 100644 --- a/src/librustc/util/ppaux.rs +++ b/src/librustc/util/ppaux.rs @@ -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*