@@ -188,37 +188,37 @@ pub struct CommonConsts<'tcx> {
188
188
}
189
189
190
190
pub struct LocalTableInContext < ' a , V > {
191
- local_id_root : Option < DefId > ,
191
+ hir_owner : Option < LocalDefId > ,
192
192
data : & ' a ItemLocalMap < V > ,
193
193
}
194
194
195
195
/// Validate that the given HirId (respectively its `local_id` part) can be
196
196
/// safely used as a key in the tables of a TypeckTable. For that to be
197
197
/// the case, the HirId must have the same `owner` as all the other IDs in
198
- /// this table (signified by `local_id_root `). Otherwise the HirId
198
+ /// this table (signified by `hir_owner `). Otherwise the HirId
199
199
/// would be in a different frame of reference and using its `local_id`
200
200
/// would result in lookup errors, or worse, in silently wrong data being
201
201
/// stored/returned.
202
202
fn validate_hir_id_for_typeck_tables (
203
- local_id_root : Option < DefId > ,
203
+ hir_owner : Option < LocalDefId > ,
204
204
hir_id : hir:: HirId ,
205
205
mut_access : bool ,
206
206
) {
207
- if let Some ( local_id_root ) = local_id_root {
208
- if hir_id. owner . to_def_id ( ) != local_id_root {
207
+ if let Some ( hir_owner ) = hir_owner {
208
+ if hir_id. owner != hir_owner {
209
209
ty:: tls:: with ( |tcx| {
210
210
bug ! (
211
211
"node {} with HirId::owner {:?} cannot be placed in \
212
- TypeckTables with local_id_root {:?}",
212
+ TypeckTables with hir_owner {:?}",
213
213
tcx. hir( ) . node_to_string( hir_id) ,
214
214
hir_id. owner,
215
- local_id_root
215
+ hir_owner
216
216
)
217
217
} ) ;
218
218
}
219
219
} else {
220
220
// We use "Null Object" TypeckTables in some of the analysis passes.
221
- // These are just expected to be empty and their `local_id_root ` is
221
+ // These are just expected to be empty and their `hir_owner ` is
222
222
// `None`. Therefore we cannot verify whether a given `HirId` would
223
223
// be a valid key for the given table. Instead we make sure that
224
224
// nobody tries to write to such a Null Object table.
@@ -230,12 +230,12 @@ fn validate_hir_id_for_typeck_tables(
230
230
231
231
impl < ' a , V > LocalTableInContext < ' a , V > {
232
232
pub fn contains_key ( & self , id : hir:: HirId ) -> bool {
233
- validate_hir_id_for_typeck_tables ( self . local_id_root , id, false ) ;
233
+ validate_hir_id_for_typeck_tables ( self . hir_owner , id, false ) ;
234
234
self . data . contains_key ( & id. local_id )
235
235
}
236
236
237
237
pub fn get ( & self , id : hir:: HirId ) -> Option < & V > {
238
- validate_hir_id_for_typeck_tables ( self . local_id_root , id, false ) ;
238
+ validate_hir_id_for_typeck_tables ( self . hir_owner , id, false ) ;
239
239
self . data . get ( & id. local_id )
240
240
}
241
241
@@ -253,28 +253,28 @@ impl<'a, V> ::std::ops::Index<hir::HirId> for LocalTableInContext<'a, V> {
253
253
}
254
254
255
255
pub struct LocalTableInContextMut < ' a , V > {
256
- local_id_root : Option < DefId > ,
256
+ hir_owner : Option < LocalDefId > ,
257
257
data : & ' a mut ItemLocalMap < V > ,
258
258
}
259
259
260
260
impl < ' a , V > LocalTableInContextMut < ' a , V > {
261
261
pub fn get_mut ( & mut self , id : hir:: HirId ) -> Option < & mut V > {
262
- validate_hir_id_for_typeck_tables ( self . local_id_root , id, true ) ;
262
+ validate_hir_id_for_typeck_tables ( self . hir_owner , id, true ) ;
263
263
self . data . get_mut ( & id. local_id )
264
264
}
265
265
266
266
pub fn entry ( & mut self , id : hir:: HirId ) -> Entry < ' _ , hir:: ItemLocalId , V > {
267
- validate_hir_id_for_typeck_tables ( self . local_id_root , id, true ) ;
267
+ validate_hir_id_for_typeck_tables ( self . hir_owner , id, true ) ;
268
268
self . data . entry ( id. local_id )
269
269
}
270
270
271
271
pub fn insert ( & mut self , id : hir:: HirId , val : V ) -> Option < V > {
272
- validate_hir_id_for_typeck_tables ( self . local_id_root , id, true ) ;
272
+ validate_hir_id_for_typeck_tables ( self . hir_owner , id, true ) ;
273
273
self . data . insert ( id. local_id , val)
274
274
}
275
275
276
276
pub fn remove ( & mut self , id : hir:: HirId ) -> Option < V > {
277
- validate_hir_id_for_typeck_tables ( self . local_id_root , id, true ) ;
277
+ validate_hir_id_for_typeck_tables ( self . hir_owner , id, true ) ;
278
278
self . data . remove ( & id. local_id )
279
279
}
280
280
}
@@ -322,8 +322,8 @@ pub struct GeneratorInteriorTypeCause<'tcx> {
322
322
323
323
#[ derive( RustcEncodable , RustcDecodable , Debug ) ]
324
324
pub struct TypeckTables < ' tcx > {
325
- /// The HirId::owner all ItemLocalIds in this table are relative to.
326
- pub local_id_root : Option < DefId > ,
325
+ /// The ` HirId::owner` all `ItemLocalId`s in this table are relative to.
326
+ pub hir_owner : Option < LocalDefId > ,
327
327
328
328
/// Resolved definitions for `<T>::X` associated paths and
329
329
/// method calls, including those of overloaded operators.
@@ -431,9 +431,9 @@ pub struct TypeckTables<'tcx> {
431
431
}
432
432
433
433
impl < ' tcx > TypeckTables < ' tcx > {
434
- pub fn empty ( local_id_root : Option < DefId > ) -> TypeckTables < ' tcx > {
434
+ pub fn empty ( hir_owner : Option < LocalDefId > ) -> TypeckTables < ' tcx > {
435
435
TypeckTables {
436
- local_id_root ,
436
+ hir_owner ,
437
437
type_dependent_defs : Default :: default ( ) ,
438
438
field_indices : Default :: default ( ) ,
439
439
user_provided_types : Default :: default ( ) ,
@@ -469,11 +469,11 @@ impl<'tcx> TypeckTables<'tcx> {
469
469
pub fn type_dependent_defs (
470
470
& self ,
471
471
) -> LocalTableInContext < ' _ , Result < ( DefKind , DefId ) , ErrorReported > > {
472
- LocalTableInContext { local_id_root : self . local_id_root , data : & self . type_dependent_defs }
472
+ LocalTableInContext { hir_owner : self . hir_owner , data : & self . type_dependent_defs }
473
473
}
474
474
475
475
pub fn type_dependent_def ( & self , id : HirId ) -> Option < ( DefKind , DefId ) > {
476
- validate_hir_id_for_typeck_tables ( self . local_id_root , id, false ) ;
476
+ validate_hir_id_for_typeck_tables ( self . hir_owner , id, false ) ;
477
477
self . type_dependent_defs . get ( & id. local_id ) . cloned ( ) . and_then ( |r| r. ok ( ) )
478
478
}
479
479
@@ -484,39 +484,33 @@ impl<'tcx> TypeckTables<'tcx> {
484
484
pub fn type_dependent_defs_mut (
485
485
& mut self ,
486
486
) -> LocalTableInContextMut < ' _ , Result < ( DefKind , DefId ) , ErrorReported > > {
487
- LocalTableInContextMut {
488
- local_id_root : self . local_id_root ,
489
- data : & mut self . type_dependent_defs ,
490
- }
487
+ LocalTableInContextMut { hir_owner : self . hir_owner , data : & mut self . type_dependent_defs }
491
488
}
492
489
493
490
pub fn field_indices ( & self ) -> LocalTableInContext < ' _ , usize > {
494
- LocalTableInContext { local_id_root : self . local_id_root , data : & self . field_indices }
491
+ LocalTableInContext { hir_owner : self . hir_owner , data : & self . field_indices }
495
492
}
496
493
497
494
pub fn field_indices_mut ( & mut self ) -> LocalTableInContextMut < ' _ , usize > {
498
- LocalTableInContextMut { local_id_root : self . local_id_root , data : & mut self . field_indices }
495
+ LocalTableInContextMut { hir_owner : self . hir_owner , data : & mut self . field_indices }
499
496
}
500
497
501
498
pub fn user_provided_types ( & self ) -> LocalTableInContext < ' _ , CanonicalUserType < ' tcx > > {
502
- LocalTableInContext { local_id_root : self . local_id_root , data : & self . user_provided_types }
499
+ LocalTableInContext { hir_owner : self . hir_owner , data : & self . user_provided_types }
503
500
}
504
501
505
502
pub fn user_provided_types_mut (
506
503
& mut self ,
507
504
) -> LocalTableInContextMut < ' _ , CanonicalUserType < ' tcx > > {
508
- LocalTableInContextMut {
509
- local_id_root : self . local_id_root ,
510
- data : & mut self . user_provided_types ,
511
- }
505
+ LocalTableInContextMut { hir_owner : self . hir_owner , data : & mut self . user_provided_types }
512
506
}
513
507
514
508
pub fn node_types ( & self ) -> LocalTableInContext < ' _ , Ty < ' tcx > > {
515
- LocalTableInContext { local_id_root : self . local_id_root , data : & self . node_types }
509
+ LocalTableInContext { hir_owner : self . hir_owner , data : & self . node_types }
516
510
}
517
511
518
512
pub fn node_types_mut ( & mut self ) -> LocalTableInContextMut < ' _ , Ty < ' tcx > > {
519
- LocalTableInContextMut { local_id_root : self . local_id_root , data : & mut self . node_types }
513
+ LocalTableInContextMut { hir_owner : self . hir_owner , data : & mut self . node_types }
520
514
}
521
515
522
516
pub fn node_type ( & self , id : hir:: HirId ) -> Ty < ' tcx > {
@@ -526,21 +520,21 @@ impl<'tcx> TypeckTables<'tcx> {
526
520
}
527
521
528
522
pub fn node_type_opt ( & self , id : hir:: HirId ) -> Option < Ty < ' tcx > > {
529
- validate_hir_id_for_typeck_tables ( self . local_id_root , id, false ) ;
523
+ validate_hir_id_for_typeck_tables ( self . hir_owner , id, false ) ;
530
524
self . node_types . get ( & id. local_id ) . cloned ( )
531
525
}
532
526
533
527
pub fn node_substs_mut ( & mut self ) -> LocalTableInContextMut < ' _ , SubstsRef < ' tcx > > {
534
- LocalTableInContextMut { local_id_root : self . local_id_root , data : & mut self . node_substs }
528
+ LocalTableInContextMut { hir_owner : self . hir_owner , data : & mut self . node_substs }
535
529
}
536
530
537
531
pub fn node_substs ( & self , id : hir:: HirId ) -> SubstsRef < ' tcx > {
538
- validate_hir_id_for_typeck_tables ( self . local_id_root , id, false ) ;
532
+ validate_hir_id_for_typeck_tables ( self . hir_owner , id, false ) ;
539
533
self . node_substs . get ( & id. local_id ) . cloned ( ) . unwrap_or_else ( || InternalSubsts :: empty ( ) )
540
534
}
541
535
542
536
pub fn node_substs_opt ( & self , id : hir:: HirId ) -> Option < SubstsRef < ' tcx > > {
543
- validate_hir_id_for_typeck_tables ( self . local_id_root , id, false ) ;
537
+ validate_hir_id_for_typeck_tables ( self . hir_owner , id, false ) ;
544
538
self . node_substs . get ( & id. local_id ) . cloned ( )
545
539
}
546
540
@@ -573,17 +567,17 @@ impl<'tcx> TypeckTables<'tcx> {
573
567
}
574
568
575
569
pub fn adjustments ( & self ) -> LocalTableInContext < ' _ , Vec < ty:: adjustment:: Adjustment < ' tcx > > > {
576
- LocalTableInContext { local_id_root : self . local_id_root , data : & self . adjustments }
570
+ LocalTableInContext { hir_owner : self . hir_owner , data : & self . adjustments }
577
571
}
578
572
579
573
pub fn adjustments_mut (
580
574
& mut self ,
581
575
) -> LocalTableInContextMut < ' _ , Vec < ty:: adjustment:: Adjustment < ' tcx > > > {
582
- LocalTableInContextMut { local_id_root : self . local_id_root , data : & mut self . adjustments }
576
+ LocalTableInContextMut { hir_owner : self . hir_owner , data : & mut self . adjustments }
583
577
}
584
578
585
579
pub fn expr_adjustments ( & self , expr : & hir:: Expr < ' _ > ) -> & [ ty:: adjustment:: Adjustment < ' tcx > ] {
586
- validate_hir_id_for_typeck_tables ( self . local_id_root , expr. hir_id , false ) ;
580
+ validate_hir_id_for_typeck_tables ( self . hir_owner , expr. hir_id , false ) ;
587
581
self . adjustments . get ( & expr. hir_id . local_id ) . map_or ( & [ ] , |a| & a[ ..] )
588
582
}
589
583
@@ -618,66 +612,51 @@ impl<'tcx> TypeckTables<'tcx> {
618
612
}
619
613
620
614
pub fn pat_binding_modes ( & self ) -> LocalTableInContext < ' _ , BindingMode > {
621
- LocalTableInContext { local_id_root : self . local_id_root , data : & self . pat_binding_modes }
615
+ LocalTableInContext { hir_owner : self . hir_owner , data : & self . pat_binding_modes }
622
616
}
623
617
624
618
pub fn pat_binding_modes_mut ( & mut self ) -> LocalTableInContextMut < ' _ , BindingMode > {
625
- LocalTableInContextMut {
626
- local_id_root : self . local_id_root ,
627
- data : & mut self . pat_binding_modes ,
628
- }
619
+ LocalTableInContextMut { hir_owner : self . hir_owner , data : & mut self . pat_binding_modes }
629
620
}
630
621
631
622
pub fn pat_adjustments ( & self ) -> LocalTableInContext < ' _ , Vec < Ty < ' tcx > > > {
632
- LocalTableInContext { local_id_root : self . local_id_root , data : & self . pat_adjustments }
623
+ LocalTableInContext { hir_owner : self . hir_owner , data : & self . pat_adjustments }
633
624
}
634
625
635
626
pub fn pat_adjustments_mut ( & mut self ) -> LocalTableInContextMut < ' _ , Vec < Ty < ' tcx > > > {
636
- LocalTableInContextMut {
637
- local_id_root : self . local_id_root ,
638
- data : & mut self . pat_adjustments ,
639
- }
627
+ LocalTableInContextMut { hir_owner : self . hir_owner , data : & mut self . pat_adjustments }
640
628
}
641
629
642
630
pub fn upvar_capture ( & self , upvar_id : ty:: UpvarId ) -> ty:: UpvarCapture < ' tcx > {
643
631
self . upvar_capture_map [ & upvar_id]
644
632
}
645
633
646
634
pub fn closure_kind_origins ( & self ) -> LocalTableInContext < ' _ , ( Span , ast:: Name ) > {
647
- LocalTableInContext { local_id_root : self . local_id_root , data : & self . closure_kind_origins }
635
+ LocalTableInContext { hir_owner : self . hir_owner , data : & self . closure_kind_origins }
648
636
}
649
637
650
638
pub fn closure_kind_origins_mut ( & mut self ) -> LocalTableInContextMut < ' _ , ( Span , ast:: Name ) > {
651
- LocalTableInContextMut {
652
- local_id_root : self . local_id_root ,
653
- data : & mut self . closure_kind_origins ,
654
- }
639
+ LocalTableInContextMut { hir_owner : self . hir_owner , data : & mut self . closure_kind_origins }
655
640
}
656
641
657
642
pub fn liberated_fn_sigs ( & self ) -> LocalTableInContext < ' _ , ty:: FnSig < ' tcx > > {
658
- LocalTableInContext { local_id_root : self . local_id_root , data : & self . liberated_fn_sigs }
643
+ LocalTableInContext { hir_owner : self . hir_owner , data : & self . liberated_fn_sigs }
659
644
}
660
645
661
646
pub fn liberated_fn_sigs_mut ( & mut self ) -> LocalTableInContextMut < ' _ , ty:: FnSig < ' tcx > > {
662
- LocalTableInContextMut {
663
- local_id_root : self . local_id_root ,
664
- data : & mut self . liberated_fn_sigs ,
665
- }
647
+ LocalTableInContextMut { hir_owner : self . hir_owner , data : & mut self . liberated_fn_sigs }
666
648
}
667
649
668
650
pub fn fru_field_types ( & self ) -> LocalTableInContext < ' _ , Vec < Ty < ' tcx > > > {
669
- LocalTableInContext { local_id_root : self . local_id_root , data : & self . fru_field_types }
651
+ LocalTableInContext { hir_owner : self . hir_owner , data : & self . fru_field_types }
670
652
}
671
653
672
654
pub fn fru_field_types_mut ( & mut self ) -> LocalTableInContextMut < ' _ , Vec < Ty < ' tcx > > > {
673
- LocalTableInContextMut {
674
- local_id_root : self . local_id_root ,
675
- data : & mut self . fru_field_types ,
676
- }
655
+ LocalTableInContextMut { hir_owner : self . hir_owner , data : & mut self . fru_field_types }
677
656
}
678
657
679
658
pub fn is_coercion_cast ( & self , hir_id : hir:: HirId ) -> bool {
680
- validate_hir_id_for_typeck_tables ( self . local_id_root , hir_id, true ) ;
659
+ validate_hir_id_for_typeck_tables ( self . hir_owner , hir_id, true ) ;
681
660
self . coercion_casts . contains ( & hir_id. local_id )
682
661
}
683
662
@@ -693,7 +672,7 @@ impl<'tcx> TypeckTables<'tcx> {
693
672
impl < ' a , ' tcx > HashStable < StableHashingContext < ' a > > for TypeckTables < ' tcx > {
694
673
fn hash_stable ( & self , hcx : & mut StableHashingContext < ' a > , hasher : & mut StableHasher ) {
695
674
let ty:: TypeckTables {
696
- local_id_root ,
675
+ hir_owner ,
697
676
ref type_dependent_defs,
698
677
ref field_indices,
699
678
ref user_provided_types,
@@ -730,18 +709,12 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for TypeckTables<'tcx> {
730
709
hash_stable_hashmap ( hcx, hasher, upvar_capture_map, |up_var_id, hcx| {
731
710
let ty:: UpvarId { var_path, closure_expr_id } = * up_var_id;
732
711
733
- let local_id_root = local_id_root . expect ( "trying to hash invalid TypeckTables" ) ;
712
+ assert_eq ! ( Some ( var_path . hir_id . owner ) , hir_owner ) ;
734
713
735
- let var_owner_def_id = DefId {
736
- krate : local_id_root. krate ,
737
- index : var_path. hir_id . owner . local_def_index ,
738
- } ;
739
- let closure_def_id =
740
- DefId { krate : local_id_root. krate , index : closure_expr_id. local_def_index } ;
741
714
(
742
- hcx. def_path_hash ( var_owner_def_id ) ,
715
+ hcx. local_def_path_hash ( var_path . hir_id . owner ) ,
743
716
var_path. hir_id . local_id ,
744
- hcx. def_path_hash ( closure_def_id ) ,
717
+ hcx. local_def_path_hash ( closure_expr_id ) ,
745
718
)
746
719
} ) ;
747
720
0 commit comments