]> git.lizzy.rs Git - rust.git/commitdiff
introduce new DefPathData variants for traits, assoc types
authorNiko Matsakis <niko@alum.mit.edu>
Fri, 30 Mar 2018 04:51:39 +0000 (00:51 -0400)
committerNiko Matsakis <niko@alum.mit.edu>
Mon, 23 Apr 2018 17:28:14 +0000 (13:28 -0400)
src/librustc/hir/map/def_collector.rs
src/librustc/hir/map/definitions.rs
src/librustc/ty/item_path.rs
src/librustc/util/ppaux.rs

index 4bd857c73e6cf6d50e73961d5b90542d2028e3d8..bfe21549e453d3358ca606b702b13ba80dfb6287 100644 (file)
@@ -107,8 +107,9 @@ fn visit_item(&mut self, i: &'a Item) {
         // 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 @@ fn visit_trait_item(&mut self, ti: &'a TraitItem) {
         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 @@ fn visit_impl_item(&mut self, ii: &'a ImplItem) {
         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),
         };
 
index 1a2840de447de75d3d157288c0074610294d7002..12f146ef49115f0ce99f1110034745790f468d45 100644 (file)
@@ -212,6 +212,9 @@ fn compute_stable_hash(&self, parent_hash: DefPathHash) -> DefPathHash {
         ::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 @@ pub fn get_opt_name(&self) -> Option<InternedString> {
         use self::DefPathData::*;
         match *self {
             TypeNs(name) |
+            Trait(name) |
+            AssocTypeInTrait(name) |
+            AssocTypeInImpl(name) |
             ValueNs(name) |
             Module(name) |
             MacroDef(name) |
@@ -663,6 +675,9 @@ pub fn as_interned_str(&self) -> InternedString {
         use self::DefPathData::*;
         let s = match *self {
             TypeNs(name) |
+            Trait(name) |
+            AssocTypeInTrait(name) |
+            AssocTypeInImpl(name) |
             ValueNs(name) |
             Module(name) |
             MacroDef(name) |
index 8189064db6968eeecfcc353eeb03ee8326b419c6..2819141c81be25888c1f13de987625ecc121c65b 100644 (file)
@@ -204,6 +204,9 @@ pub fn push_item_path<T>(self, buffer: &mut T, def_id: DefId)
             // 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(..) |
index dd478967b185a3539762868eb3f91beb6c979771..84e3358ff13897f5ec0b3449c41ea29ea9602aac 100644 (file)
@@ -268,14 +268,31 @@ fn parameterized<F: fmt::Write>(&mut self,
             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*