@@ -28,6 +28,10 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher, StableHashe
28
28
pub ( super ) struct NodeCollector < ' a , ' hir > {
29
29
/// The crate
30
30
krate : & ' hir Crate ,
31
+
32
+ /// Source map
33
+ source_map : & ' a SourceMap ,
34
+
31
35
/// The node map
32
36
map : Vec < Option < Entry < ' hir > > > ,
33
37
/// The parent of this node
@@ -54,7 +58,8 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
54
58
pub ( super ) fn root ( krate : & ' hir Crate ,
55
59
dep_graph : & ' a DepGraph ,
56
60
definitions : & ' a definitions:: Definitions ,
57
- hcx : StableHashingContext < ' a > )
61
+ hcx : StableHashingContext < ' a > ,
62
+ source_map : & ' a SourceMap )
58
63
-> NodeCollector < ' a , ' hir > {
59
64
let root_mod_def_path_hash = definitions. def_path_hash ( CRATE_DEF_INDEX ) ;
60
65
@@ -102,6 +107,7 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
102
107
103
108
let mut collector = NodeCollector {
104
109
krate,
110
+ source_map,
105
111
map : vec ! [ ] ,
106
112
parent_node : CRATE_NODE_ID ,
107
113
current_signature_dep_index : root_mod_sig_dep_index,
@@ -125,7 +131,6 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
125
131
pub ( super ) fn finalize_and_compute_crate_hash ( mut self ,
126
132
crate_disambiguator : CrateDisambiguator ,
127
133
cstore : & dyn CrateStore ,
128
- source_map : & SourceMap ,
129
134
commandline_args_hash : u64 )
130
135
-> ( Vec < Option < Entry < ' hir > > > , Svh )
131
136
{
@@ -154,7 +159,8 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
154
159
// If we included the full mapping in the SVH, we could only have
155
160
// reproducible builds by compiling from the same directory. So we just
156
161
// hash the result of the mapping instead of the mapping itself.
157
- let mut source_file_names: Vec < _ > = source_map
162
+ let mut source_file_names: Vec < _ > = self
163
+ . source_map
158
164
. files ( )
159
165
. iter ( )
160
166
. filter ( |source_file| CrateNum :: from_u32 ( source_file. crate_of_origin ) == LOCAL_CRATE )
@@ -186,7 +192,7 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
186
192
self . map [ id. as_usize ( ) ] = Some ( entry) ;
187
193
}
188
194
189
- fn insert ( & mut self , id : NodeId , node : Node < ' hir > ) {
195
+ fn insert ( & mut self , span : Span , id : NodeId , node : Node < ' hir > ) {
190
196
let entry = Entry {
191
197
parent : self . parent_node ,
192
198
dep_node : if self . currently_in_body {
@@ -216,16 +222,20 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
216
222
String :: new ( )
217
223
} ;
218
224
219
- bug ! ( "inconsistent DepNode for `{}`: \
220
- current_dep_node_owner={} ({:?}), hir_id.owner={} ({:?}){}",
225
+ span_bug ! (
226
+ span,
227
+ "inconsistent DepNode at `{:?}` for `{}`: \
228
+ current_dep_node_owner={} ({:?}), hir_id.owner={} ({:?}){}",
229
+ self . source_map. span_to_string( span) ,
221
230
node_str,
222
231
self . definitions
223
232
. def_path( self . current_dep_node_owner)
224
233
. to_string_no_crate( ) ,
225
234
self . current_dep_node_owner,
226
235
self . definitions. def_path( hir_id. owner) . to_string_no_crate( ) ,
227
236
hir_id. owner,
228
- forgot_str)
237
+ forgot_str,
238
+ )
229
239
}
230
240
}
231
241
@@ -309,12 +319,12 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
309
319
debug_assert_eq ! ( i. hir_id. owner,
310
320
self . definitions. opt_def_index( i. id) . unwrap( ) ) ;
311
321
self . with_dep_node_owner ( i. hir_id . owner , i, |this| {
312
- this. insert ( i. id , Node :: Item ( i) ) ;
322
+ this. insert ( i. span , i . id , Node :: Item ( i) ) ;
313
323
this. with_parent ( i. id , |this| {
314
324
if let ItemKind :: Struct ( ref struct_def, _) = i. node {
315
325
// If this is a tuple-like struct, register the constructor.
316
326
if !struct_def. is_struct ( ) {
317
- this. insert ( struct_def. id ( ) , Node :: StructCtor ( struct_def) ) ;
327
+ this. insert ( i . span , struct_def. id ( ) , Node :: StructCtor ( struct_def) ) ;
318
328
}
319
329
}
320
330
intravisit:: walk_item ( this, i) ;
@@ -323,23 +333,23 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
323
333
}
324
334
325
335
fn visit_foreign_item ( & mut self , foreign_item : & ' hir ForeignItem ) {
326
- self . insert ( foreign_item. id , Node :: ForeignItem ( foreign_item) ) ;
336
+ self . insert ( foreign_item. span , foreign_item . id , Node :: ForeignItem ( foreign_item) ) ;
327
337
328
338
self . with_parent ( foreign_item. id , |this| {
329
339
intravisit:: walk_foreign_item ( this, foreign_item) ;
330
340
} ) ;
331
341
}
332
342
333
343
fn visit_generic_param ( & mut self , param : & ' hir GenericParam ) {
334
- self . insert ( param. id , Node :: GenericParam ( param) ) ;
344
+ self . insert ( param. span , param . id , Node :: GenericParam ( param) ) ;
335
345
intravisit:: walk_generic_param ( self , param) ;
336
346
}
337
347
338
348
fn visit_trait_item ( & mut self , ti : & ' hir TraitItem ) {
339
349
debug_assert_eq ! ( ti. hir_id. owner,
340
350
self . definitions. opt_def_index( ti. id) . unwrap( ) ) ;
341
351
self . with_dep_node_owner ( ti. hir_id . owner , ti, |this| {
342
- this. insert ( ti. id , Node :: TraitItem ( ti) ) ;
352
+ this. insert ( ti. span , ti . id , Node :: TraitItem ( ti) ) ;
343
353
344
354
this. with_parent ( ti. id , |this| {
345
355
intravisit:: walk_trait_item ( this, ti) ;
@@ -351,7 +361,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
351
361
debug_assert_eq ! ( ii. hir_id. owner,
352
362
self . definitions. opt_def_index( ii. id) . unwrap( ) ) ;
353
363
self . with_dep_node_owner ( ii. hir_id . owner , ii, |this| {
354
- this. insert ( ii. id , Node :: ImplItem ( ii) ) ;
364
+ this. insert ( ii. span , ii . id , Node :: ImplItem ( ii) ) ;
355
365
356
366
this. with_parent ( ii. id , |this| {
357
367
intravisit:: walk_impl_item ( this, ii) ;
@@ -365,23 +375,23 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
365
375
} else {
366
376
Node :: Pat ( pat)
367
377
} ;
368
- self . insert ( pat. id , node) ;
378
+ self . insert ( pat. span , pat . id , node) ;
369
379
370
380
self . with_parent ( pat. id , |this| {
371
381
intravisit:: walk_pat ( this, pat) ;
372
382
} ) ;
373
383
}
374
384
375
385
fn visit_anon_const ( & mut self , constant : & ' hir AnonConst ) {
376
- self . insert ( constant. id , Node :: AnonConst ( constant) ) ;
386
+ self . insert ( DUMMY_SP , constant. id , Node :: AnonConst ( constant) ) ;
377
387
378
388
self . with_parent ( constant. id , |this| {
379
389
intravisit:: walk_anon_const ( this, constant) ;
380
390
} ) ;
381
391
}
382
392
383
393
fn visit_expr ( & mut self , expr : & ' hir Expr ) {
384
- self . insert ( expr. id , Node :: Expr ( expr) ) ;
394
+ self . insert ( expr. span , expr . id , Node :: Expr ( expr) ) ;
385
395
386
396
self . with_parent ( expr. id , |this| {
387
397
intravisit:: walk_expr ( this, expr) ;
@@ -390,7 +400,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
390
400
391
401
fn visit_stmt ( & mut self , stmt : & ' hir Stmt ) {
392
402
let id = stmt. node . id ( ) ;
393
- self . insert ( id, Node :: Stmt ( stmt) ) ;
403
+ self . insert ( stmt . span , id, Node :: Stmt ( stmt) ) ;
394
404
395
405
self . with_parent ( id, |this| {
396
406
intravisit:: walk_stmt ( this, stmt) ;
@@ -399,21 +409,21 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
399
409
400
410
fn visit_path_segment ( & mut self , path_span : Span , path_segment : & ' hir PathSegment ) {
401
411
if let Some ( id) = path_segment. id {
402
- self . insert ( id, Node :: PathSegment ( path_segment) ) ;
412
+ self . insert ( path_span , id, Node :: PathSegment ( path_segment) ) ;
403
413
}
404
414
intravisit:: walk_path_segment ( self , path_span, path_segment) ;
405
415
}
406
416
407
417
fn visit_ty ( & mut self , ty : & ' hir Ty ) {
408
- self . insert ( ty. id , Node :: Ty ( ty) ) ;
418
+ self . insert ( ty. span , ty . id , Node :: Ty ( ty) ) ;
409
419
410
420
self . with_parent ( ty. id , |this| {
411
421
intravisit:: walk_ty ( this, ty) ;
412
422
} ) ;
413
423
}
414
424
415
425
fn visit_trait_ref ( & mut self , tr : & ' hir TraitRef ) {
416
- self . insert ( tr. ref_id , Node :: TraitRef ( tr) ) ;
426
+ self . insert ( tr. path . span , tr . ref_id , Node :: TraitRef ( tr) ) ;
417
427
418
428
self . with_parent ( tr. ref_id , |this| {
419
429
intravisit:: walk_trait_ref ( this, tr) ;
@@ -427,21 +437,21 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
427
437
}
428
438
429
439
fn visit_block ( & mut self , block : & ' hir Block ) {
430
- self . insert ( block. id , Node :: Block ( block) ) ;
440
+ self . insert ( block. span , block . id , Node :: Block ( block) ) ;
431
441
self . with_parent ( block. id , |this| {
432
442
intravisit:: walk_block ( this, block) ;
433
443
} ) ;
434
444
}
435
445
436
446
fn visit_local ( & mut self , l : & ' hir Local ) {
437
- self . insert ( l. id , Node :: Local ( l) ) ;
447
+ self . insert ( l. span , l . id , Node :: Local ( l) ) ;
438
448
self . with_parent ( l. id , |this| {
439
449
intravisit:: walk_local ( this, l)
440
450
} )
441
451
}
442
452
443
453
fn visit_lifetime ( & mut self , lifetime : & ' hir Lifetime ) {
444
- self . insert ( lifetime. id , Node :: Lifetime ( lifetime) ) ;
454
+ self . insert ( lifetime. span , lifetime . id , Node :: Lifetime ( lifetime) ) ;
445
455
}
446
456
447
457
fn visit_vis ( & mut self , visibility : & ' hir Visibility ) {
@@ -450,7 +460,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
450
460
VisibilityKind :: Crate ( _) |
451
461
VisibilityKind :: Inherited => { }
452
462
VisibilityKind :: Restricted { id, .. } => {
453
- self . insert ( id, Node :: Visibility ( visibility) ) ;
463
+ self . insert ( visibility . span , id, Node :: Visibility ( visibility) ) ;
454
464
self . with_parent ( id, |this| {
455
465
intravisit:: walk_vis ( this, visibility) ;
456
466
} ) ;
@@ -462,20 +472,20 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
462
472
let def_index = self . definitions . opt_def_index ( macro_def. id ) . unwrap ( ) ;
463
473
464
474
self . with_dep_node_owner ( def_index, macro_def, |this| {
465
- this. insert ( macro_def. id , Node :: MacroDef ( macro_def) ) ;
475
+ this. insert ( macro_def. span , macro_def . id , Node :: MacroDef ( macro_def) ) ;
466
476
} ) ;
467
477
}
468
478
469
479
fn visit_variant ( & mut self , v : & ' hir Variant , g : & ' hir Generics , item_id : NodeId ) {
470
480
let id = v. node . data . id ( ) ;
471
- self . insert ( id, Node :: Variant ( v) ) ;
481
+ self . insert ( v . span , id, Node :: Variant ( v) ) ;
472
482
self . with_parent ( id, |this| {
473
483
intravisit:: walk_variant ( this, v, g, item_id) ;
474
484
} ) ;
475
485
}
476
486
477
487
fn visit_struct_field ( & mut self , field : & ' hir StructField ) {
478
- self . insert ( field. id , Node :: Field ( field) ) ;
488
+ self . insert ( field. span , field . id , Node :: Field ( field) ) ;
479
489
self . with_parent ( field. id , |this| {
480
490
intravisit:: walk_struct_field ( this, field) ;
481
491
} ) ;
0 commit comments