+#[derive(Clone, Debug, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]
+pub struct DefPath {
+ /// the path leading from the crate root to the item
+ pub data: Vec<DisambiguatedDefPathData>,
+
+ /// what krate root is this path relative to?
+ pub krate: ast::CrateNum,
+}
+
+impl DefPath {
+ pub fn is_local(&self) -> bool {
+ self.krate == LOCAL_CRATE
+ }
+
+ pub fn make<FN>(start_krate: ast::CrateNum,
+ start_index: DefIndex,
+ mut get_key: FN) -> DefPath
+ where FN: FnMut(DefIndex) -> DefKey
+ {
+ let mut krate = start_krate;
+ let mut data = vec![];
+ let mut index = Some(start_index);
+ loop {
+ let p = index.unwrap();
+ let key = get_key(p);
+ match key.disambiguated_data.data {
+ DefPathData::CrateRoot => {
+ assert!(key.parent.is_none());
+ break;
+ }
+ DefPathData::InlinedRoot(ref p) => {
+ assert!(key.parent.is_none());
+ assert!(!p.def_id.is_local());
+ data.extend(p.data.iter().cloned().rev());
+ krate = p.def_id.krate;
+ break;
+ }
+ _ => {
+ data.push(key.disambiguated_data);
+ index = key.parent;
+ }
+ }
+ }
+ data.reverse();
+ DefPath { data: data, krate: krate }
+ }
+}
+