@@ -59,7 +59,54 @@ pub struct DefData {
5959 pub node_id : ast:: NodeId ,
6060}
6161
62- pub type DefPath = Vec < DisambiguatedDefPathData > ;
62+ #[ derive( Clone , Debug , PartialEq , Eq , Hash , RustcEncodable , RustcDecodable ) ]
63+ pub struct DefPath {
64+ /// the path leading from the crate root to the item
65+ pub data : Vec < DisambiguatedDefPathData > ,
66+
67+ /// what krate root is this path relative to?
68+ pub krate : ast:: CrateNum ,
69+ }
70+
71+ impl DefPath {
72+ pub fn is_local ( & self ) -> bool {
73+ self . krate == LOCAL_CRATE
74+ }
75+
76+ pub fn make < FN > ( start_krate : ast:: CrateNum ,
77+ start_index : DefIndex ,
78+ mut get_key : FN ) -> DefPath
79+ where FN : FnMut ( DefIndex ) -> DefKey
80+ {
81+ let mut krate = start_krate;
82+ let mut data = vec ! [ ] ;
83+ let mut index = Some ( start_index) ;
84+ loop {
85+ let p = index. unwrap ( ) ;
86+ let key = get_key ( p) ;
87+ match key. disambiguated_data . data {
88+ DefPathData :: CrateRoot => {
89+ assert ! ( key. parent. is_none( ) ) ;
90+ break ;
91+ }
92+ DefPathData :: InlinedRoot ( ref p) => {
93+ assert ! ( key. parent. is_none( ) ) ;
94+ assert ! ( !p. def_id. is_local( ) ) ;
95+ data. extend ( p. data . iter ( ) . cloned ( ) . rev ( ) ) ;
96+ krate = p. def_id . krate ;
97+ break ;
98+ }
99+ _ => {
100+ data. push ( key. disambiguated_data ) ;
101+ index = key. parent ;
102+ }
103+ }
104+ }
105+ data. reverse ( ) ;
106+ DefPath { data : data, krate : krate }
107+ }
108+ }
109+
63110/// Root of an inlined item. We track the `DefPath` of the item within
64111/// the original crate but also its def-id. This is kind of an
65112/// augmented version of a `DefPath` that includes a `DefId`. This is
@@ -141,7 +188,7 @@ impl Definitions {
141188 /// will be the path of the item in the external crate (but the
142189 /// path will begin with the path to the external crate).
143190 pub fn def_path ( & self , index : DefIndex ) -> DefPath {
144- make_def_path ( index, |p| self . def_key ( p) )
191+ DefPath :: make ( LOCAL_CRATE , index, |p| self . def_key ( p) )
145192 }
146193
147194 pub fn opt_def_index ( & self , node : ast:: NodeId ) -> Option < DefIndex > {
@@ -247,29 +294,3 @@ impl DefPathData {
247294 }
248295}
249296
250- pub fn make_def_path < FN > ( start_index : DefIndex , mut get_key : FN ) -> DefPath
251- where FN : FnMut ( DefIndex ) -> DefKey
252- {
253- let mut result = vec ! [ ] ;
254- let mut index = Some ( start_index) ;
255- while let Some ( p) = index {
256- let key = get_key ( p) ;
257- match key. disambiguated_data . data {
258- DefPathData :: CrateRoot => {
259- assert ! ( key. parent. is_none( ) ) ;
260- break ;
261- }
262- DefPathData :: InlinedRoot ( ref p) => {
263- assert ! ( key. parent. is_none( ) ) ;
264- result. extend ( p. iter ( ) . cloned ( ) . rev ( ) ) ;
265- break ;
266- }
267- _ => {
268- result. push ( key. disambiguated_data ) ;
269- index = key. parent ;
270- }
271- }
272- }
273- result. reverse ( ) ;
274- result
275- }
0 commit comments