@@ -45,15 +45,25 @@ use syntax::visit::{self, Visitor};
45
45
46
46
use syntax_pos:: { Span , DUMMY_SP } ;
47
47
48
- impl < ' a > ToNameBinding < ' a > for ( Module < ' a > , Span , ty:: Visibility ) {
48
+ impl < ' a > ToNameBinding < ' a > for ( Module < ' a > , ty:: Visibility , Span , Mark ) {
49
49
fn to_name_binding ( self ) -> NameBinding < ' a > {
50
- NameBinding { kind : NameBindingKind :: Module ( self . 0 ) , span : self . 1 , vis : self . 2 }
50
+ NameBinding {
51
+ kind : NameBindingKind :: Module ( self . 0 ) ,
52
+ vis : self . 1 ,
53
+ span : self . 2 ,
54
+ expansion : self . 3 ,
55
+ }
51
56
}
52
57
}
53
58
54
- impl < ' a > ToNameBinding < ' a > for ( Def , Span , ty:: Visibility ) {
59
+ impl < ' a > ToNameBinding < ' a > for ( Def , ty:: Visibility , Span , Mark ) {
55
60
fn to_name_binding ( self ) -> NameBinding < ' a > {
56
- NameBinding { kind : NameBindingKind :: Def ( self . 0 ) , span : self . 1 , vis : self . 2 }
61
+ NameBinding {
62
+ kind : NameBindingKind :: Def ( self . 0 ) ,
63
+ vis : self . 1 ,
64
+ span : self . 2 ,
65
+ expansion : self . 3 ,
66
+ }
57
67
}
58
68
}
59
69
@@ -148,8 +158,9 @@ impl<'b> Resolver<'b> {
148
158
}
149
159
150
160
let subclass = ImportDirectiveSubclass :: single ( binding. name , source. name ) ;
151
- let span = view_path. span ;
152
- self . add_import_directive ( module_path, subclass, span, item. id , vis) ;
161
+ self . add_import_directive (
162
+ module_path, subclass, view_path. span , item. id , vis, expansion,
163
+ ) ;
153
164
}
154
165
ViewPathList ( _, ref source_items) => {
155
166
// Make sure there's at most one `mod` import in the list.
@@ -196,17 +207,20 @@ impl<'b> Resolver<'b> {
196
207
}
197
208
} ;
198
209
let subclass = ImportDirectiveSubclass :: single ( rename, name) ;
199
- let ( span, id) = ( source_item. span , source_item. node . id ) ;
200
- self . add_import_directive ( module_path, subclass, span, id, vis) ;
210
+ let id = source_item. node . id ;
211
+ self . add_import_directive (
212
+ module_path, subclass, source_item. span , id, vis, expansion,
213
+ ) ;
201
214
}
202
215
}
203
216
ViewPathGlob ( _) => {
204
217
let subclass = GlobImport {
205
218
is_prelude : is_prelude,
206
219
max_vis : Cell :: new ( ty:: Visibility :: PrivateExternal ) ,
207
220
} ;
208
- let span = view_path. span ;
209
- self . add_import_directive ( module_path, subclass, span, item. id , vis) ;
221
+ self . add_import_directive (
222
+ module_path, subclass, view_path. span , item. id , vis, expansion,
223
+ ) ;
210
224
}
211
225
}
212
226
}
@@ -217,7 +231,7 @@ impl<'b> Resolver<'b> {
217
231
// n.b. we don't need to look at the path option here, because cstore already did
218
232
let crate_id = self . session . cstore . extern_mod_stmt_cnum ( item. id ) . unwrap ( ) ;
219
233
let module = self . get_extern_crate_root ( crate_id) ;
220
- let binding = ( module, sp , ty:: Visibility :: Public ) . to_name_binding ( ) ;
234
+ let binding = ( module, ty:: Visibility :: Public , sp , expansion ) . to_name_binding ( ) ;
221
235
let binding = self . arenas . alloc_name_binding ( binding) ;
222
236
let directive = self . arenas . alloc_import_directive ( ImportDirective {
223
237
id : item. id ,
@@ -227,6 +241,7 @@ impl<'b> Resolver<'b> {
227
241
span : item. span ,
228
242
module_path : Vec :: new ( ) ,
229
243
vis : Cell :: new ( vis) ,
244
+ expansion : expansion,
230
245
} ) ;
231
246
let imported_binding = self . import ( binding, directive) ;
232
247
self . define ( parent, name, TypeNS , imported_binding) ;
@@ -245,7 +260,7 @@ impl<'b> Resolver<'b> {
245
260
normal_ancestor_id : Some ( item. id ) ,
246
261
..ModuleS :: new ( Some ( parent) , ModuleKind :: Def ( def, name) )
247
262
} ) ;
248
- self . define ( parent, name, TypeNS , ( module, sp, vis ) ) ;
263
+ self . define ( parent, name, TypeNS , ( module, vis , sp, expansion ) ) ;
249
264
self . module_map . insert ( item. id , module) ;
250
265
251
266
// Descend into the module.
@@ -258,45 +273,45 @@ impl<'b> Resolver<'b> {
258
273
ItemKind :: Static ( _, m, _) => {
259
274
let mutbl = m == Mutability :: Mutable ;
260
275
let def = Def :: Static ( self . definitions . local_def_id ( item. id ) , mutbl) ;
261
- self . define ( parent, name, ValueNS , ( def, sp, vis ) ) ;
276
+ self . define ( parent, name, ValueNS , ( def, vis , sp, expansion ) ) ;
262
277
}
263
278
ItemKind :: Const ( ..) => {
264
279
let def = Def :: Const ( self . definitions . local_def_id ( item. id ) ) ;
265
- self . define ( parent, name, ValueNS , ( def, sp, vis ) ) ;
280
+ self . define ( parent, name, ValueNS , ( def, vis , sp, expansion ) ) ;
266
281
}
267
282
ItemKind :: Fn ( ..) => {
268
283
let def = Def :: Fn ( self . definitions . local_def_id ( item. id ) ) ;
269
- self . define ( parent, name, ValueNS , ( def, sp, vis ) ) ;
284
+ self . define ( parent, name, ValueNS , ( def, vis , sp, expansion ) ) ;
270
285
}
271
286
272
287
// These items live in the type namespace.
273
288
ItemKind :: Ty ( ..) => {
274
289
let def = Def :: TyAlias ( self . definitions . local_def_id ( item. id ) ) ;
275
- self . define ( parent, name, TypeNS , ( def, sp, vis ) ) ;
290
+ self . define ( parent, name, TypeNS , ( def, vis , sp, expansion ) ) ;
276
291
}
277
292
278
293
ItemKind :: Enum ( ref enum_definition, _) => {
279
294
let def = Def :: Enum ( self . definitions . local_def_id ( item. id ) ) ;
280
295
let module = self . new_module ( parent, ModuleKind :: Def ( def, name) , true ) ;
281
- self . define ( parent, name, TypeNS , ( module, sp, vis ) ) ;
296
+ self . define ( parent, name, TypeNS , ( module, vis , sp, expansion ) ) ;
282
297
283
298
for variant in & ( * enum_definition) . variants {
284
- self . build_reduced_graph_for_variant ( variant, module, vis) ;
299
+ self . build_reduced_graph_for_variant ( variant, module, vis, expansion ) ;
285
300
}
286
301
}
287
302
288
303
// These items live in both the type and value namespaces.
289
304
ItemKind :: Struct ( ref struct_def, _) => {
290
305
// Define a name in the type namespace.
291
306
let def = Def :: Struct ( self . definitions . local_def_id ( item. id ) ) ;
292
- self . define ( parent, name, TypeNS , ( def, sp, vis ) ) ;
307
+ self . define ( parent, name, TypeNS , ( def, vis , sp, expansion ) ) ;
293
308
294
309
// If this is a tuple or unit struct, define a name
295
310
// in the value namespace as well.
296
311
if !struct_def. is_struct ( ) {
297
312
let ctor_def = Def :: StructCtor ( self . definitions . local_def_id ( struct_def. id ( ) ) ,
298
313
CtorKind :: from_ast ( struct_def) ) ;
299
- self . define ( parent, name, ValueNS , ( ctor_def, sp, vis ) ) ;
314
+ self . define ( parent, name, ValueNS , ( ctor_def, vis , sp, expansion ) ) ;
300
315
}
301
316
302
317
// Record field names for error reporting.
@@ -310,7 +325,7 @@ impl<'b> Resolver<'b> {
310
325
311
326
ItemKind :: Union ( ref vdata, _) => {
312
327
let def = Def :: Union ( self . definitions . local_def_id ( item. id ) ) ;
313
- self . define ( parent, name, TypeNS , ( def, sp, vis ) ) ;
328
+ self . define ( parent, name, TypeNS , ( def, vis , sp, expansion ) ) ;
314
329
315
330
// Record field names for error reporting.
316
331
let field_names = vdata. fields ( ) . iter ( ) . filter_map ( |field| {
@@ -329,7 +344,7 @@ impl<'b> Resolver<'b> {
329
344
// Add all the items within to a new module.
330
345
let module =
331
346
self . new_module ( parent, ModuleKind :: Def ( Def :: Trait ( def_id) , name) , true ) ;
332
- self . define ( parent, name, TypeNS , ( module, sp, vis ) ) ;
347
+ self . define ( parent, name, TypeNS , ( module, vis , sp, expansion ) ) ;
333
348
self . current_module = module;
334
349
}
335
350
ItemKind :: Mac ( _) => panic ! ( "unexpanded macro in resolve!" ) ,
@@ -338,27 +353,28 @@ impl<'b> Resolver<'b> {
338
353
339
354
// Constructs the reduced graph for one variant. Variants exist in the
340
355
// type and value namespaces.
341
- fn build_reduced_graph_for_variant ( & mut self ,
342
- variant : & Variant ,
343
- parent : Module < ' b > ,
344
- vis : ty:: Visibility ) {
356
+ fn build_reduced_graph_for_variant (
357
+ & mut self , variant : & Variant , parent : Module < ' b > , vis : ty:: Visibility , expansion : Mark ,
358
+ ) {
345
359
let name = variant. node . name . name ;
346
360
let def_id = self . definitions . local_def_id ( variant. node . data . id ( ) ) ;
347
361
348
362
// Define a name in the type namespace.
349
363
let def = Def :: Variant ( def_id) ;
350
- self . define ( parent, name, TypeNS , ( def, variant. span , vis ) ) ;
364
+ self . define ( parent, name, TypeNS , ( def, vis , variant. span , expansion ) ) ;
351
365
352
366
// Define a constructor name in the value namespace.
353
367
// Braced variants, unlike structs, generate unusable names in
354
368
// value namespace, they are reserved for possible future use.
355
369
let ctor_kind = CtorKind :: from_ast ( & variant. node . data ) ;
356
370
let ctor_def = Def :: VariantCtor ( def_id, ctor_kind) ;
357
- self . define ( parent, name, ValueNS , ( ctor_def, variant. span , vis ) ) ;
371
+ self . define ( parent, name, ValueNS , ( ctor_def, vis , variant. span , expansion ) ) ;
358
372
}
359
373
360
374
/// Constructs the reduced graph for one foreign item.
361
- fn build_reduced_graph_for_foreign_item ( & mut self , foreign_item : & ForeignItem ) {
375
+ fn build_reduced_graph_for_foreign_item (
376
+ & mut self , foreign_item : & ForeignItem , expansion : Mark ,
377
+ ) {
362
378
let parent = self . current_module ;
363
379
let name = foreign_item. ident . name ;
364
380
@@ -371,7 +387,7 @@ impl<'b> Resolver<'b> {
371
387
}
372
388
} ;
373
389
let vis = self . resolve_visibility ( & foreign_item. vis ) ;
374
- self . define ( parent, name, ValueNS , ( def, foreign_item. span , vis ) ) ;
390
+ self . define ( parent, name, ValueNS , ( def, vis , foreign_item. span , expansion ) ) ;
375
391
}
376
392
377
393
fn build_reduced_graph_for_block ( & mut self , block : & Block ) {
@@ -404,24 +420,24 @@ impl<'b> Resolver<'b> {
404
420
match def {
405
421
Def :: Mod ( ..) | Def :: Enum ( ..) => {
406
422
let module = self . new_module ( parent, ModuleKind :: Def ( def, name) , false ) ;
407
- self . define ( parent, name, TypeNS , ( module, DUMMY_SP , vis ) ) ;
423
+ self . define ( parent, name, TypeNS , ( module, vis , DUMMY_SP , Mark :: root ( ) ) ) ;
408
424
}
409
425
Def :: Variant ( ..) => {
410
- self . define ( parent, name, TypeNS , ( def, DUMMY_SP , vis ) ) ;
426
+ self . define ( parent, name, TypeNS , ( def, vis , DUMMY_SP , Mark :: root ( ) ) ) ;
411
427
}
412
428
Def :: VariantCtor ( ..) => {
413
- self . define ( parent, name, ValueNS , ( def, DUMMY_SP , vis ) ) ;
429
+ self . define ( parent, name, ValueNS , ( def, vis , DUMMY_SP , Mark :: root ( ) ) ) ;
414
430
}
415
431
Def :: Fn ( ..) |
416
432
Def :: Static ( ..) |
417
433
Def :: Const ( ..) |
418
434
Def :: AssociatedConst ( ..) |
419
435
Def :: Method ( ..) => {
420
- self . define ( parent, name, ValueNS , ( def, DUMMY_SP , vis ) ) ;
436
+ self . define ( parent, name, ValueNS , ( def, vis , DUMMY_SP , Mark :: root ( ) ) ) ;
421
437
}
422
438
Def :: Trait ( ..) => {
423
439
let module = self . new_module ( parent, ModuleKind :: Def ( def, name) , false ) ;
424
- self . define ( parent, name, TypeNS , ( module, DUMMY_SP , vis ) ) ;
440
+ self . define ( parent, name, TypeNS , ( module, vis , DUMMY_SP , Mark :: root ( ) ) ) ;
425
441
426
442
// If this is a trait, add all the trait item names to the trait info.
427
443
let trait_item_def_ids = self . session . cstore . associated_item_def_ids ( def_id) ;
@@ -433,27 +449,27 @@ impl<'b> Resolver<'b> {
433
449
}
434
450
}
435
451
Def :: TyAlias ( ..) | Def :: AssociatedTy ( ..) => {
436
- self . define ( parent, name, TypeNS , ( def, DUMMY_SP , vis ) ) ;
452
+ self . define ( parent, name, TypeNS , ( def, vis , DUMMY_SP , Mark :: root ( ) ) ) ;
437
453
}
438
454
Def :: Struct ( ..) => {
439
- self . define ( parent, name, TypeNS , ( def, DUMMY_SP , vis ) ) ;
455
+ self . define ( parent, name, TypeNS , ( def, vis , DUMMY_SP , Mark :: root ( ) ) ) ;
440
456
441
457
// Record field names for error reporting.
442
458
let field_names = self . session . cstore . struct_field_names ( def_id) ;
443
459
self . insert_field_names ( def_id, field_names) ;
444
460
}
445
461
Def :: StructCtor ( ..) => {
446
- self . define ( parent, name, ValueNS , ( def, DUMMY_SP , vis ) ) ;
462
+ self . define ( parent, name, ValueNS , ( def, vis , DUMMY_SP , Mark :: root ( ) ) ) ;
447
463
}
448
464
Def :: Union ( ..) => {
449
- self . define ( parent, name, TypeNS , ( def, DUMMY_SP , vis ) ) ;
465
+ self . define ( parent, name, TypeNS , ( def, vis , DUMMY_SP , Mark :: root ( ) ) ) ;
450
466
451
467
// Record field names for error reporting.
452
468
let field_names = self . session . cstore . struct_field_names ( def_id) ;
453
469
self . insert_field_names ( def_id, field_names) ;
454
470
}
455
471
Def :: Macro ( ..) => {
456
- self . define ( parent, name, MacroNS , ( def, DUMMY_SP , vis ) ) ;
472
+ self . define ( parent, name, MacroNS , ( def, vis , DUMMY_SP , Mark :: root ( ) ) ) ;
457
473
}
458
474
Def :: Local ( ..) |
459
475
Def :: PrimTy ( ..) |
@@ -695,7 +711,7 @@ impl<'a, 'b> Visitor for BuildReducedGraphVisitor<'a, 'b> {
695
711
}
696
712
697
713
fn visit_foreign_item ( & mut self , foreign_item : & ForeignItem ) {
698
- self . resolver . build_reduced_graph_for_foreign_item ( foreign_item) ;
714
+ self . resolver . build_reduced_graph_for_foreign_item ( foreign_item, self . expansion ) ;
699
715
visit:: walk_foreign_item ( self , foreign_item) ;
700
716
}
701
717
@@ -732,7 +748,7 @@ impl<'a, 'b> Visitor for BuildReducedGraphVisitor<'a, 'b> {
732
748
self . resolver . trait_item_map . insert ( ( item. ident . name , def_id) , is_static_method) ;
733
749
734
750
let vis = ty:: Visibility :: Public ;
735
- self . resolver . define ( parent, item. ident . name , ns, ( def, item. span , vis ) ) ;
751
+ self . resolver . define ( parent, item. ident . name , ns, ( def, vis , item. span , self . expansion ) ) ;
736
752
737
753
self . resolver . current_module = parent. parent . unwrap ( ) ; // nearest normal ancestor
738
754
visit:: walk_trait_item ( self , item) ;
0 commit comments