@@ -28,6 +28,10 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher, StableHashe
2828pub ( super ) struct NodeCollector < ' a , ' hir > {
2929 /// The crate
3030 krate : & ' hir Crate ,
31+
32+ /// Source map
33+ source_map : & ' a SourceMap ,
34+
3135 /// The node map
3236 map : Vec < Option < Entry < ' hir > > > ,
3337 /// The parent of this node
@@ -54,7 +58,8 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
5458 pub ( super ) fn root ( krate : & ' hir Crate ,
5559 dep_graph : & ' a DepGraph ,
5660 definitions : & ' a definitions:: Definitions ,
57- hcx : StableHashingContext < ' a > )
61+ hcx : StableHashingContext < ' a > ,
62+ source_map : & ' a SourceMap )
5863 -> NodeCollector < ' a , ' hir > {
5964 let root_mod_def_path_hash = definitions. def_path_hash ( CRATE_DEF_INDEX ) ;
6065
@@ -102,6 +107,7 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
102107
103108 let mut collector = NodeCollector {
104109 krate,
110+ source_map,
105111 map : vec ! [ ] ,
106112 parent_node : CRATE_NODE_ID ,
107113 current_signature_dep_index : root_mod_sig_dep_index,
@@ -125,7 +131,6 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
125131 pub ( super ) fn finalize_and_compute_crate_hash ( mut self ,
126132 crate_disambiguator : CrateDisambiguator ,
127133 cstore : & dyn CrateStore ,
128- source_map : & SourceMap ,
129134 commandline_args_hash : u64 )
130135 -> ( Vec < Option < Entry < ' hir > > > , Svh )
131136 {
@@ -154,7 +159,8 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
154159 // If we included the full mapping in the SVH, we could only have
155160 // reproducible builds by compiling from the same directory. So we just
156161 // 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
158164 . files ( )
159165 . iter ( )
160166 . filter ( |source_file| CrateNum :: from_u32 ( source_file. crate_of_origin ) == LOCAL_CRATE )
@@ -186,7 +192,7 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
186192 self . map [ id. as_usize ( ) ] = Some ( entry) ;
187193 }
188194
189- fn insert ( & mut self , id : NodeId , node : Node < ' hir > ) {
195+ fn insert ( & mut self , span : Span , id : NodeId , node : Node < ' hir > ) {
190196 let entry = Entry {
191197 parent : self . parent_node ,
192198 dep_node : if self . currently_in_body {
@@ -216,16 +222,20 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
216222 String :: new ( )
217223 } ;
218224
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) ,
221230 node_str,
222231 self . definitions
223232 . def_path( self . current_dep_node_owner)
224233 . to_string_no_crate( ) ,
225234 self . current_dep_node_owner,
226235 self . definitions. def_path( hir_id. owner) . to_string_no_crate( ) ,
227236 hir_id. owner,
228- forgot_str)
237+ forgot_str,
238+ )
229239 }
230240 }
231241
@@ -309,12 +319,12 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
309319 debug_assert_eq ! ( i. hir_id. owner,
310320 self . definitions. opt_def_index( i. id) . unwrap( ) ) ;
311321 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) ) ;
313323 this. with_parent ( i. id , |this| {
314324 if let ItemKind :: Struct ( ref struct_def, _) = i. node {
315325 // If this is a tuple-like struct, register the constructor.
316326 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) ) ;
318328 }
319329 }
320330 intravisit:: walk_item ( this, i) ;
@@ -323,23 +333,23 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
323333 }
324334
325335 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) ) ;
327337
328338 self . with_parent ( foreign_item. id , |this| {
329339 intravisit:: walk_foreign_item ( this, foreign_item) ;
330340 } ) ;
331341 }
332342
333343 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) ) ;
335345 intravisit:: walk_generic_param ( self , param) ;
336346 }
337347
338348 fn visit_trait_item ( & mut self , ti : & ' hir TraitItem ) {
339349 debug_assert_eq ! ( ti. hir_id. owner,
340350 self . definitions. opt_def_index( ti. id) . unwrap( ) ) ;
341351 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) ) ;
343353
344354 this. with_parent ( ti. id , |this| {
345355 intravisit:: walk_trait_item ( this, ti) ;
@@ -351,7 +361,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
351361 debug_assert_eq ! ( ii. hir_id. owner,
352362 self . definitions. opt_def_index( ii. id) . unwrap( ) ) ;
353363 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) ) ;
355365
356366 this. with_parent ( ii. id , |this| {
357367 intravisit:: walk_impl_item ( this, ii) ;
@@ -365,23 +375,23 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
365375 } else {
366376 Node :: Pat ( pat)
367377 } ;
368- self . insert ( pat. id , node) ;
378+ self . insert ( pat. span , pat . id , node) ;
369379
370380 self . with_parent ( pat. id , |this| {
371381 intravisit:: walk_pat ( this, pat) ;
372382 } ) ;
373383 }
374384
375385 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) ) ;
377387
378388 self . with_parent ( constant. id , |this| {
379389 intravisit:: walk_anon_const ( this, constant) ;
380390 } ) ;
381391 }
382392
383393 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) ) ;
385395
386396 self . with_parent ( expr. id , |this| {
387397 intravisit:: walk_expr ( this, expr) ;
@@ -390,7 +400,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
390400
391401 fn visit_stmt ( & mut self , stmt : & ' hir Stmt ) {
392402 let id = stmt. node . id ( ) ;
393- self . insert ( id, Node :: Stmt ( stmt) ) ;
403+ self . insert ( stmt . span , id, Node :: Stmt ( stmt) ) ;
394404
395405 self . with_parent ( id, |this| {
396406 intravisit:: walk_stmt ( this, stmt) ;
@@ -399,21 +409,21 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
399409
400410 fn visit_path_segment ( & mut self , path_span : Span , path_segment : & ' hir PathSegment ) {
401411 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) ) ;
403413 }
404414 intravisit:: walk_path_segment ( self , path_span, path_segment) ;
405415 }
406416
407417 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) ) ;
409419
410420 self . with_parent ( ty. id , |this| {
411421 intravisit:: walk_ty ( this, ty) ;
412422 } ) ;
413423 }
414424
415425 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) ) ;
417427
418428 self . with_parent ( tr. ref_id , |this| {
419429 intravisit:: walk_trait_ref ( this, tr) ;
@@ -427,21 +437,21 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
427437 }
428438
429439 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) ) ;
431441 self . with_parent ( block. id , |this| {
432442 intravisit:: walk_block ( this, block) ;
433443 } ) ;
434444 }
435445
436446 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) ) ;
438448 self . with_parent ( l. id , |this| {
439449 intravisit:: walk_local ( this, l)
440450 } )
441451 }
442452
443453 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) ) ;
445455 }
446456
447457 fn visit_vis ( & mut self , visibility : & ' hir Visibility ) {
@@ -450,7 +460,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
450460 VisibilityKind :: Crate ( _) |
451461 VisibilityKind :: Inherited => { }
452462 VisibilityKind :: Restricted { id, .. } => {
453- self . insert ( id, Node :: Visibility ( visibility) ) ;
463+ self . insert ( visibility . span , id, Node :: Visibility ( visibility) ) ;
454464 self . with_parent ( id, |this| {
455465 intravisit:: walk_vis ( this, visibility) ;
456466 } ) ;
@@ -462,20 +472,20 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
462472 let def_index = self . definitions . opt_def_index ( macro_def. id ) . unwrap ( ) ;
463473
464474 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) ) ;
466476 } ) ;
467477 }
468478
469479 fn visit_variant ( & mut self , v : & ' hir Variant , g : & ' hir Generics , item_id : NodeId ) {
470480 let id = v. node . data . id ( ) ;
471- self . insert ( id, Node :: Variant ( v) ) ;
481+ self . insert ( v . span , id, Node :: Variant ( v) ) ;
472482 self . with_parent ( id, |this| {
473483 intravisit:: walk_variant ( this, v, g, item_id) ;
474484 } ) ;
475485 }
476486
477487 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) ) ;
479489 self . with_parent ( field. id , |this| {
480490 intravisit:: walk_struct_field ( this, field) ;
481491 } ) ;
0 commit comments