Skip to content

Commit 09bd6f3

Browse files
committed
introduce new DefPathData variants for traits, assoc types
1 parent cfbf62f commit 09bd6f3

File tree

4 files changed

+41
-5
lines changed

4 files changed

+41
-5
lines changed

src/librustc/hir/map/def_collector.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,9 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
107107
// information we encapsulate into
108108
let def_data = match i.node {
109109
ItemKind::Impl(..) => DefPathData::Impl,
110+
ItemKind::Trait(..) => DefPathData::Trait(i.ident.name.as_str()),
110111
ItemKind::Enum(..) | ItemKind::Struct(..) | ItemKind::Union(..) |
111-
ItemKind::Trait(..) | ItemKind::TraitAlias(..) |
112+
ItemKind::TraitAlias(..) |
112113
ItemKind::ExternCrate(..) | ItemKind::ForeignMod(..) | ItemKind::Ty(..) =>
113114
DefPathData::TypeNs(i.ident.name.as_str()),
114115
ItemKind::Mod(..) if i.ident == keywords::Invalid.ident() => {
@@ -222,7 +223,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
222223
let def_data = match ti.node {
223224
TraitItemKind::Method(..) | TraitItemKind::Const(..) =>
224225
DefPathData::ValueNs(ti.ident.name.as_str()),
225-
TraitItemKind::Type(..) => DefPathData::TypeNs(ti.ident.name.as_str()),
226+
TraitItemKind::Type(..) => DefPathData::AssocTypeInTrait(ti.ident.name.as_str()),
226227
TraitItemKind::Macro(..) => return self.visit_macro_invoc(ti.id, false),
227228
};
228229

@@ -240,7 +241,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
240241
let def_data = match ii.node {
241242
ImplItemKind::Method(..) | ImplItemKind::Const(..) =>
242243
DefPathData::ValueNs(ii.ident.name.as_str()),
243-
ImplItemKind::Type(..) => DefPathData::TypeNs(ii.ident.name.as_str()),
244+
ImplItemKind::Type(..) => DefPathData::AssocTypeInImpl(ii.ident.name.as_str()),
244245
ImplItemKind::Macro(..) => return self.visit_macro_invoc(ii.id, false),
245246
};
246247

src/librustc/hir/map/definitions.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,9 @@ impl DefKey {
212212
::std::mem::discriminant(data).hash(&mut hasher);
213213
match *data {
214214
DefPathData::TypeNs(name) |
215+
DefPathData::Trait(name) |
216+
DefPathData::AssocTypeInTrait(name) |
217+
DefPathData::AssocTypeInImpl(name) |
215218
DefPathData::ValueNs(name) |
216219
DefPathData::Module(name) |
217220
DefPathData::MacroDef(name) |
@@ -358,6 +361,12 @@ pub enum DefPathData {
358361
// Different kinds of items and item-like things:
359362
/// An impl
360363
Impl,
364+
/// A trait
365+
Trait(InternedString),
366+
/// An associated type **declaration** (i.e., in a trait)
367+
AssocTypeInTrait(InternedString),
368+
/// An associated type **value** (i.e., in an impl)
369+
AssocTypeInImpl(InternedString),
361370
/// Something in the type NS
362371
TypeNs(InternedString),
363372
/// Something in the value NS
@@ -639,6 +648,9 @@ impl DefPathData {
639648
use self::DefPathData::*;
640649
match *self {
641650
TypeNs(name) |
651+
Trait(name) |
652+
AssocTypeInTrait(name) |
653+
AssocTypeInImpl(name) |
642654
ValueNs(name) |
643655
Module(name) |
644656
MacroDef(name) |
@@ -663,6 +675,9 @@ impl DefPathData {
663675
use self::DefPathData::*;
664676
let s = match *self {
665677
TypeNs(name) |
678+
Trait(name) |
679+
AssocTypeInTrait(name) |
680+
AssocTypeInImpl(name) |
666681
ValueNs(name) |
667682
Module(name) |
668683
MacroDef(name) |

src/librustc/ty/item_path.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,9 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
204204
// finer-grained distinctions, e.g. between enum/struct).
205205
data @ DefPathData::Misc |
206206
data @ DefPathData::TypeNs(..) |
207+
data @ DefPathData::Trait(..) |
208+
data @ DefPathData::AssocTypeInTrait(..) |
209+
data @ DefPathData::AssocTypeInImpl(..) |
207210
data @ DefPathData::ValueNs(..) |
208211
data @ DefPathData::Module(..) |
209212
data @ DefPathData::TypeParam(..) |

src/librustc/util/ppaux.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,14 +268,31 @@ impl PrintContext {
268268
loop {
269269
let key = tcx.def_key(item_def_id);
270270
match key.disambiguated_data.data {
271+
DefPathData::AssocTypeInTrait(_) |
272+
DefPathData::AssocTypeInImpl(_) |
273+
DefPathData::Trait(_) |
271274
DefPathData::TypeNs(_) => {
272275
break;
273276
}
274-
DefPathData::ValueNs(_) | DefPathData::EnumVariant(_) => {
277+
DefPathData::ValueNs(_) |
278+
DefPathData::EnumVariant(_) => {
275279
is_value_path = true;
276280
break;
277281
}
278-
_ => {
282+
DefPathData::CrateRoot |
283+
DefPathData::Misc |
284+
DefPathData::Impl |
285+
DefPathData::Module(_) |
286+
DefPathData::MacroDef(_) |
287+
DefPathData::ClosureExpr |
288+
DefPathData::TypeParam(_) |
289+
DefPathData::LifetimeDef(_) |
290+
DefPathData::Field(_) |
291+
DefPathData::StructCtor |
292+
DefPathData::Initializer |
293+
DefPathData::ImplTrait |
294+
DefPathData::Typeof |
295+
DefPathData::GlobalMetaData(_) => {
279296
// if we're making a symbol for something, there ought
280297
// to be a value or type-def or something in there
281298
// *somewhere*

0 commit comments

Comments
 (0)