Skip to content

Commit baed8ca

Browse files
committed
---
yaml --- r: 276933 b: refs/heads/try c: d8263c4 h: refs/heads/master i: 276931: 646e153
1 parent 8871134 commit baed8ca

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 6dbb0e86aec11050480beb76eade6fb805010ba7
33
refs/heads/snap-stage3: 235d77457d80b549dad3ac36d94f235208a1eafb
4-
refs/heads/try: a9b6205aff943d44820df53d63d14a06b319b9dd
4+
refs/heads/try: d8263c4758e8821d87d4fc300fd30e78457c769f
55
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
66
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
77
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try/src/librustc/hir/map/definitions.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,17 +203,56 @@ impl Definitions {
203203
}
204204
}
205205

206+
pub fn retrace_path(&self, path: &DefPath) -> Option<DefIndex> {
207+
debug!("retrace_path(path={:?})", path);
208+
209+
// we assume that we only want to retrace paths relative to
210+
// the crate root
211+
assert!(path.is_local());
212+
213+
let root_key = DefKey {
214+
parent: None,
215+
disambiguated_data: DisambiguatedDefPathData {
216+
data: DefPathData::CrateRoot,
217+
disambiguator: 0,
218+
},
219+
};
220+
let root_id = self.key_map[&root_key];
221+
222+
debug!("retrace_path: root_id={:?}", root_id);
223+
224+
let mut id = root_id;
225+
for data in &path.data {
226+
let key = DefKey { parent: Some(id), disambiguated_data: data.clone() };
227+
debug!("key = {:?}", key);
228+
id = match self.key_map.get(&key) {
229+
Some(&id) => id,
230+
None => return None
231+
};
232+
}
233+
234+
Some(id)
235+
}
236+
206237
pub fn create_def_with_parent(&mut self,
207238
parent: Option<DefIndex>,
208239
node_id: ast::NodeId,
209240
data: DefPathData)
210241
-> DefIndex {
242+
debug!("create_def_with_parent(parent={:?}, node_id={:?}, data={:?})",
243+
parent, node_id, data);
244+
211245
assert!(!self.node_map.contains_key(&node_id),
212246
"adding a def'n for node-id {:?} and data {:?} but a previous def'n exists: {:?}",
213247
node_id,
214248
data,
215249
self.data[self.node_map[&node_id].as_usize()]);
216250

251+
assert!(parent.is_some() ^ match data {
252+
DefPathData::CrateRoot | DefPathData::InlinedRoot(_) => true,
253+
_ => false,
254+
});
255+
217256
// Find a unique DefKey. This basically means incrementing the disambiguator
218257
// until we get no match.
219258
let mut key = DefKey {
@@ -228,12 +267,17 @@ impl Definitions {
228267
key.disambiguated_data.disambiguator += 1;
229268
}
230269

270+
debug!("create_def_with_parent: after disambiguation, key = {:?}", key);
271+
231272
// Create the definition.
232273
let index = DefIndex::new(self.data.len());
233274
self.data.push(DefData { key: key.clone(), node_id: node_id });
275+
debug!("create_def_with_parent: node_map[{:?}] = {:?}", node_id, index);
234276
self.node_map.insert(node_id, index);
277+
debug!("create_def_with_parent: key_map[{:?}] = {:?}", key, index);
235278
self.key_map.insert(key, index);
236279

280+
237281
index
238282
}
239283
}

branches/try/src/librustc/hir/map/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,11 @@ impl<'ast> Map<'ast> {
282282
self.definitions.borrow().def_path(def_id.index)
283283
}
284284

285+
pub fn retrace_path(&self, path: &DefPath) -> Option<DefId> {
286+
self.definitions.borrow().retrace_path(path)
287+
.map(DefId::local)
288+
}
289+
285290
pub fn local_def_id(&self, node: NodeId) -> DefId {
286291
self.opt_local_def_id(node).unwrap_or_else(|| {
287292
bug!("local_def_id: no entry for `{}`, which has a map of `{:?}`",

0 commit comments

Comments
 (0)