99// except according to those terms.
1010
1111use hir:: map:: definitions:: * ;
12- use hir:: def_id:: { CRATE_DEF_INDEX , DefIndex } ;
12+ use hir:: def_id:: { CRATE_DEF_INDEX , DefIndex , DefIndexAddressSpace } ;
1313
1414use syntax:: ast:: * ;
1515use syntax:: ext:: hygiene:: Mark ;
1616use syntax:: visit;
1717use syntax:: symbol:: { Symbol , keywords} ;
1818
19+ use hir:: map:: { ITEM_LIKE_SPACE , REGULAR_SPACE } ;
20+
1921/// Creates def ids for nodes in the AST.
2022pub struct DefCollector < ' a > {
2123 definitions : & ' a mut Definitions ,
@@ -39,23 +41,31 @@ impl<'a> DefCollector<'a> {
3941 }
4042
4143 pub fn collect_root ( & mut self ) {
42- let root = self . create_def_with_parent ( None , CRATE_NODE_ID , DefPathData :: CrateRoot ) ;
44+ let root = self . create_def_with_parent ( None ,
45+ CRATE_NODE_ID ,
46+ DefPathData :: CrateRoot ,
47+ ITEM_LIKE_SPACE ) ;
4348 assert_eq ! ( root, CRATE_DEF_INDEX ) ;
4449 self . parent_def = Some ( root) ;
4550 }
4651
47- fn create_def ( & mut self , node_id : NodeId , data : DefPathData ) -> DefIndex {
52+ fn create_def ( & mut self ,
53+ node_id : NodeId ,
54+ data : DefPathData ,
55+ address_space : DefIndexAddressSpace )
56+ -> DefIndex {
4857 let parent_def = self . parent_def ;
4958 debug ! ( "create_def(node_id={:?}, data={:?}, parent_def={:?})" , node_id, data, parent_def) ;
50- self . definitions . create_def_with_parent ( parent_def, node_id, data)
59+ self . definitions . create_def_with_parent ( parent_def, node_id, data, address_space )
5160 }
5261
5362 fn create_def_with_parent ( & mut self ,
5463 parent : Option < DefIndex > ,
5564 node_id : NodeId ,
56- data : DefPathData )
65+ data : DefPathData ,
66+ address_space : DefIndexAddressSpace )
5767 -> DefIndex {
58- self . definitions . create_def_with_parent ( parent, node_id, data)
68+ self . definitions . create_def_with_parent ( parent, node_id, data, address_space )
5969 }
6070
6171 pub fn with_parent < F : FnOnce ( & mut Self ) > ( & mut self , parent_def : DefIndex , f : F ) {
@@ -76,7 +86,7 @@ impl<'a> DefCollector<'a> {
7686 _ => { }
7787 }
7888
79- self . create_def ( expr. id , DefPathData :: Initializer ) ;
89+ self . create_def ( expr. id , DefPathData :: Initializer , REGULAR_SPACE ) ;
8090 }
8191
8292 fn visit_macro_invoc ( & mut self , id : NodeId , const_expr : bool ) {
@@ -118,27 +128,32 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
118128 ViewPathSimple ( ..) => { }
119129 ViewPathList ( _, ref imports) => {
120130 for import in imports {
121- self . create_def ( import. node . id , DefPathData :: Misc ) ;
131+ self . create_def ( import. node . id ,
132+ DefPathData :: Misc ,
133+ ITEM_LIKE_SPACE ) ;
122134 }
123135 }
124136 }
125137 DefPathData :: Misc
126138 }
127139 } ;
128- let def = self . create_def ( i. id , def_data) ;
140+ let def = self . create_def ( i. id , def_data, ITEM_LIKE_SPACE ) ;
129141
130142 self . with_parent ( def, |this| {
131143 match i. node {
132144 ItemKind :: Enum ( ref enum_definition, _) => {
133145 for v in & enum_definition. variants {
134146 let variant_def_index =
135147 this. create_def ( v. node . data . id ( ) ,
136- DefPathData :: EnumVariant ( v. node . name . name . as_str ( ) ) ) ;
148+ DefPathData :: EnumVariant ( v. node . name . name . as_str ( ) ) ,
149+ REGULAR_SPACE ) ;
137150 this. with_parent ( variant_def_index, |this| {
138151 for ( index, field) in v. node . data . fields ( ) . iter ( ) . enumerate ( ) {
139152 let name = field. ident . map ( |ident| ident. name )
140153 . unwrap_or_else ( || Symbol :: intern ( & index. to_string ( ) ) ) ;
141- this. create_def ( field. id , DefPathData :: Field ( name. as_str ( ) ) ) ;
154+ this. create_def ( field. id ,
155+ DefPathData :: Field ( name. as_str ( ) ) ,
156+ REGULAR_SPACE ) ;
142157 }
143158
144159 if let Some ( ref expr) = v. node . disr_expr {
@@ -151,13 +166,14 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
151166 // If this is a tuple-like struct, register the constructor.
152167 if !struct_def. is_struct ( ) {
153168 this. create_def ( struct_def. id ( ) ,
154- DefPathData :: StructCtor ) ;
169+ DefPathData :: StructCtor ,
170+ REGULAR_SPACE ) ;
155171 }
156172
157173 for ( index, field) in struct_def. fields ( ) . iter ( ) . enumerate ( ) {
158174 let name = field. ident . map ( |ident| ident. name . as_str ( ) )
159175 . unwrap_or ( Symbol :: intern ( & index. to_string ( ) ) . as_str ( ) ) ;
160- this. create_def ( field. id , DefPathData :: Field ( name) ) ;
176+ this. create_def ( field. id , DefPathData :: Field ( name) , REGULAR_SPACE ) ;
161177 }
162178 }
163179 _ => { }
@@ -168,7 +184,8 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
168184
169185 fn visit_foreign_item ( & mut self , foreign_item : & ' a ForeignItem ) {
170186 let def = self . create_def ( foreign_item. id ,
171- DefPathData :: ValueNs ( foreign_item. ident . name . as_str ( ) ) ) ;
187+ DefPathData :: ValueNs ( foreign_item. ident . name . as_str ( ) ) ,
188+ REGULAR_SPACE ) ;
172189
173190 self . with_parent ( def, |this| {
174191 visit:: walk_foreign_item ( this, foreign_item) ;
@@ -177,7 +194,9 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
177194
178195 fn visit_generics ( & mut self , generics : & ' a Generics ) {
179196 for ty_param in generics. ty_params . iter ( ) {
180- self . create_def ( ty_param. id , DefPathData :: TypeParam ( ty_param. ident . name . as_str ( ) ) ) ;
197+ self . create_def ( ty_param. id ,
198+ DefPathData :: TypeParam ( ty_param. ident . name . as_str ( ) ) ,
199+ REGULAR_SPACE ) ;
181200 }
182201
183202 visit:: walk_generics ( self , generics) ;
@@ -191,7 +210,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
191210 TraitItemKind :: Macro ( ..) => return self . visit_macro_invoc ( ti. id , false ) ,
192211 } ;
193212
194- let def = self . create_def ( ti. id , def_data) ;
213+ let def = self . create_def ( ti. id , def_data, ITEM_LIKE_SPACE ) ;
195214 self . with_parent ( def, |this| {
196215 if let TraitItemKind :: Const ( _, Some ( ref expr) ) = ti. node {
197216 this. visit_const_expr ( expr) ;
@@ -209,7 +228,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
209228 ImplItemKind :: Macro ( ..) => return self . visit_macro_invoc ( ii. id , false ) ,
210229 } ;
211230
212- let def = self . create_def ( ii. id , def_data) ;
231+ let def = self . create_def ( ii. id , def_data, ITEM_LIKE_SPACE ) ;
213232 self . with_parent ( def, |this| {
214233 if let ImplItemKind :: Const ( _, ref expr) = ii. node {
215234 this. visit_const_expr ( expr) ;
@@ -225,7 +244,9 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
225244 match pat. node {
226245 PatKind :: Mac ( ..) => return self . visit_macro_invoc ( pat. id , false ) ,
227246 PatKind :: Ident ( _, id, _) => {
228- let def = self . create_def ( pat. id , DefPathData :: Binding ( id. node . name . as_str ( ) ) ) ;
247+ let def = self . create_def ( pat. id ,
248+ DefPathData :: Binding ( id. node . name . as_str ( ) ) ,
249+ REGULAR_SPACE ) ;
229250 self . parent_def = Some ( def) ;
230251 }
231252 _ => { }
@@ -242,7 +263,9 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
242263 ExprKind :: Mac ( ..) => return self . visit_macro_invoc ( expr. id , false ) ,
243264 ExprKind :: Repeat ( _, ref count) => self . visit_const_expr ( count) ,
244265 ExprKind :: Closure ( ..) => {
245- let def = self . create_def ( expr. id , DefPathData :: ClosureExpr ) ;
266+ let def = self . create_def ( expr. id ,
267+ DefPathData :: ClosureExpr ,
268+ REGULAR_SPACE ) ;
246269 self . parent_def = Some ( def) ;
247270 }
248271 _ => { }
@@ -257,7 +280,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
257280 TyKind :: Mac ( ..) => return self . visit_macro_invoc ( ty. id , false ) ,
258281 TyKind :: Array ( _, ref length) => self . visit_const_expr ( length) ,
259282 TyKind :: ImplTrait ( ..) => {
260- self . create_def ( ty. id , DefPathData :: ImplTrait ) ;
283+ self . create_def ( ty. id , DefPathData :: ImplTrait , REGULAR_SPACE ) ;
261284 }
262285 TyKind :: Typeof ( ref expr) => self . visit_const_expr ( expr) ,
263286 _ => { }
@@ -266,7 +289,9 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
266289 }
267290
268291 fn visit_lifetime_def ( & mut self , def : & ' a LifetimeDef ) {
269- self . create_def ( def. lifetime . id , DefPathData :: LifetimeDef ( def. lifetime . name . as_str ( ) ) ) ;
292+ self . create_def ( def. lifetime . id ,
293+ DefPathData :: LifetimeDef ( def. lifetime . name . as_str ( ) ) ,
294+ REGULAR_SPACE ) ;
270295 }
271296
272297 fn visit_stmt ( & mut self , stmt : & ' a Stmt ) {
0 commit comments