Skip to content

Commit 3988fd0

Browse files
committed
refactor DefPathData variants
In particular, remove the name from the Impl, since that name is synthesized and is not predictable (it tends to break incr. comp.). Also rename the variants to be a bit more uniform and remove some distinctions that we were not really taking advantage of anywhere.
1 parent 25bdd61 commit 3988fd0

File tree

2 files changed

+24
-23
lines changed

2 files changed

+24
-23
lines changed

src/librustc/front/map/collector.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,16 @@ impl<'ast> Visitor<'ast> for NodeCollector<'ast> {
133133
// Pick the def data. This need not be unique, but the more
134134
// information we encapsulate into
135135
let def_data = match i.node {
136-
ItemDefaultImpl(..) | ItemImpl(..) => DefPathData::Impl(i.name),
137-
ItemEnum(..) | ItemStruct(..) | ItemTrait(..) => DefPathData::Type(i.name),
138-
ItemExternCrate(..) | ItemMod(..) => DefPathData::Mod(i.name),
139-
ItemStatic(..) | ItemConst(..) | ItemFn(..) => DefPathData::Value(i.name),
140-
_ => DefPathData::Misc,
136+
ItemDefaultImpl(..) | ItemImpl(..) =>
137+
DefPathData::Impl,
138+
ItemEnum(..) | ItemStruct(..) | ItemTrait(..) |
139+
ItemExternCrate(..) | ItemMod(..) | ItemForeignMod(..) |
140+
ItemTy(..) =>
141+
DefPathData::TypeNs(i.name),
142+
ItemStatic(..) | ItemConst(..) | ItemFn(..) =>
143+
DefPathData::ValueNs(i.name),
144+
ItemUse(..) =>
145+
DefPathData::Misc,
141146
};
142147

143148
self.insert_def(i.id, NodeItem(i), def_data);
@@ -202,7 +207,7 @@ impl<'ast> Visitor<'ast> for NodeCollector<'ast> {
202207
fn visit_foreign_item(&mut self, foreign_item: &'ast ForeignItem) {
203208
self.insert_def(foreign_item.id,
204209
NodeForeignItem(foreign_item),
205-
DefPathData::Value(foreign_item.name));
210+
DefPathData::ValueNs(foreign_item.name));
206211

207212
let parent_node = self.parent_node;
208213
self.parent_node = foreign_item.id;
@@ -222,8 +227,8 @@ impl<'ast> Visitor<'ast> for NodeCollector<'ast> {
222227

223228
fn visit_trait_item(&mut self, ti: &'ast TraitItem) {
224229
let def_data = match ti.node {
225-
MethodTraitItem(..) | ConstTraitItem(..) => DefPathData::Value(ti.name),
226-
TypeTraitItem(..) => DefPathData::Type(ti.name),
230+
MethodTraitItem(..) | ConstTraitItem(..) => DefPathData::ValueNs(ti.name),
231+
TypeTraitItem(..) => DefPathData::TypeNs(ti.name),
227232
};
228233

229234
self.insert(ti.id, NodeTraitItem(ti));
@@ -246,8 +251,8 @@ impl<'ast> Visitor<'ast> for NodeCollector<'ast> {
246251

247252
fn visit_impl_item(&mut self, ii: &'ast ImplItem) {
248253
let def_data = match ii.node {
249-
ImplItemKind::Method(..) | ImplItemKind::Const(..) => DefPathData::Value(ii.name),
250-
ImplItemKind::Type(..) => DefPathData::Type(ii.name),
254+
ImplItemKind::Method(..) | ImplItemKind::Const(..) => DefPathData::ValueNs(ii.name),
255+
ImplItemKind::Type(..) => DefPathData::TypeNs(ii.name),
251256
};
252257

253258
self.insert_def(ii.id, NodeImplItem(ii), def_data);

src/librustc/front/map/definitions.rs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,9 @@ pub enum DefPathData {
144144
Misc,
145145

146146
// Different kinds of items and item-like things:
147-
Impl(ast::Name),
148-
Type(ast::Name),
149-
Mod(ast::Name),
150-
Value(ast::Name),
147+
Impl,
148+
TypeNs(ast::Name), // something in the type NS
149+
ValueNs(ast::Name), // something in the value NS
151150
MacroDef(ast::Name),
152151
ClosureExpr,
153152

@@ -159,10 +158,6 @@ pub enum DefPathData {
159158
StructCtor, // implicit ctor for a tuple-like struct
160159
Initializer, // initializer for a const
161160
Binding(ast::Name), // pattern binding
162-
163-
// An external crate that does not have an `extern crate` in this
164-
// crate.
165-
DetachedCrate(ast::Name),
166161
}
167162

168163
impl Definitions {
@@ -247,20 +242,21 @@ impl DefPathData {
247242
pub fn as_interned_str(&self) -> InternedString {
248243
use self::DefPathData::*;
249244
match *self {
250-
Impl(name) |
251-
Type(name) |
252-
Mod(name) |
253-
Value(name) |
245+
TypeNs(name) |
246+
ValueNs(name) |
254247
MacroDef(name) |
255248
TypeParam(name) |
256249
LifetimeDef(name) |
257250
EnumVariant(name) |
258-
DetachedCrate(name) |
259251
Binding(name) |
260252
Field(name) => {
261253
name.as_str()
262254
}
263255

256+
Impl => {
257+
InternedString::new("{{impl}}")
258+
}
259+
264260
// note that this does not show up in user printouts
265261
CrateRoot => {
266262
InternedString::new("{{root}}")

0 commit comments

Comments
 (0)