@@ -188,7 +188,7 @@ pub struct CommonConsts<'tcx> {
188
188
}
189
189
190
190
pub struct LocalTableInContext < ' a , V > {
191
- hir_owner : Option < LocalDefId > ,
191
+ hir_owner : LocalDefId ,
192
192
data : & ' a ItemLocalMap < V > ,
193
193
}
194
194
@@ -199,42 +199,27 @@ pub struct LocalTableInContext<'a, V> {
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
- fn validate_hir_id_for_typeck_tables (
203
- hir_owner : Option < LocalDefId > ,
204
- hir_id : hir:: HirId ,
205
- mut_access : bool ,
206
- ) {
207
- if let Some ( hir_owner) = hir_owner {
208
- if hir_id. owner != hir_owner {
209
- ty:: tls:: with ( |tcx| {
210
- bug ! (
211
- "node {} with HirId::owner {:?} cannot be placed in TypeckTables with hir_owner {:?}" ,
212
- tcx. hir( ) . node_to_string( hir_id) ,
213
- hir_id. owner,
214
- hir_owner
215
- )
216
- } ) ;
217
- }
218
- } else {
219
- // We use "Null Object" TypeckTables in some of the analysis passes.
220
- // These are just expected to be empty and their `hir_owner` is
221
- // `None`. Therefore we cannot verify whether a given `HirId` would
222
- // be a valid key for the given table. Instead we make sure that
223
- // nobody tries to write to such a Null Object table.
224
- if mut_access {
225
- bug ! ( "access to invalid TypeckTables" )
226
- }
202
+ fn validate_hir_id_for_typeck_tables ( hir_owner : LocalDefId , hir_id : hir:: HirId ) {
203
+ if hir_id. owner != hir_owner {
204
+ ty:: tls:: with ( |tcx| {
205
+ bug ! (
206
+ "node {} with HirId::owner {:?} cannot be placed in TypeckTables with hir_owner {:?}" ,
207
+ tcx. hir( ) . node_to_string( hir_id) ,
208
+ hir_id. owner,
209
+ hir_owner
210
+ )
211
+ } ) ;
227
212
}
228
213
}
229
214
230
215
impl < ' a , V > LocalTableInContext < ' a , V > {
231
216
pub fn contains_key ( & self , id : hir:: HirId ) -> bool {
232
- validate_hir_id_for_typeck_tables ( self . hir_owner , id, false ) ;
217
+ validate_hir_id_for_typeck_tables ( self . hir_owner , id) ;
233
218
self . data . contains_key ( & id. local_id )
234
219
}
235
220
236
221
pub fn get ( & self , id : hir:: HirId ) -> Option < & V > {
237
- validate_hir_id_for_typeck_tables ( self . hir_owner , id, false ) ;
222
+ validate_hir_id_for_typeck_tables ( self . hir_owner , id) ;
238
223
self . data . get ( & id. local_id )
239
224
}
240
225
@@ -252,28 +237,28 @@ impl<'a, V> ::std::ops::Index<hir::HirId> for LocalTableInContext<'a, V> {
252
237
}
253
238
254
239
pub struct LocalTableInContextMut < ' a , V > {
255
- hir_owner : Option < LocalDefId > ,
240
+ hir_owner : LocalDefId ,
256
241
data : & ' a mut ItemLocalMap < V > ,
257
242
}
258
243
259
244
impl < ' a , V > LocalTableInContextMut < ' a , V > {
260
245
pub fn get_mut ( & mut self , id : hir:: HirId ) -> Option < & mut V > {
261
- validate_hir_id_for_typeck_tables ( self . hir_owner , id, true ) ;
246
+ validate_hir_id_for_typeck_tables ( self . hir_owner , id) ;
262
247
self . data . get_mut ( & id. local_id )
263
248
}
264
249
265
250
pub fn entry ( & mut self , id : hir:: HirId ) -> Entry < ' _ , hir:: ItemLocalId , V > {
266
- validate_hir_id_for_typeck_tables ( self . hir_owner , id, true ) ;
251
+ validate_hir_id_for_typeck_tables ( self . hir_owner , id) ;
267
252
self . data . entry ( id. local_id )
268
253
}
269
254
270
255
pub fn insert ( & mut self , id : hir:: HirId , val : V ) -> Option < V > {
271
- validate_hir_id_for_typeck_tables ( self . hir_owner , id, true ) ;
256
+ validate_hir_id_for_typeck_tables ( self . hir_owner , id) ;
272
257
self . data . insert ( id. local_id , val)
273
258
}
274
259
275
260
pub fn remove ( & mut self , id : hir:: HirId ) -> Option < V > {
276
- validate_hir_id_for_typeck_tables ( self . hir_owner , id, true ) ;
261
+ validate_hir_id_for_typeck_tables ( self . hir_owner , id) ;
277
262
self . data . remove ( & id. local_id )
278
263
}
279
264
}
@@ -324,7 +309,7 @@ pub struct GeneratorInteriorTypeCause<'tcx> {
324
309
#[ derive( RustcEncodable , RustcDecodable , Debug ) ]
325
310
pub struct TypeckTables < ' tcx > {
326
311
/// The `HirId::owner` all `ItemLocalId`s in this table are relative to.
327
- pub hir_owner : Option < LocalDefId > ,
312
+ pub hir_owner : LocalDefId ,
328
313
329
314
/// Resolved definitions for `<T>::X` associated paths and
330
315
/// method calls, including those of overloaded operators.
@@ -432,7 +417,7 @@ pub struct TypeckTables<'tcx> {
432
417
}
433
418
434
419
impl < ' tcx > TypeckTables < ' tcx > {
435
- pub fn empty ( hir_owner : Option < LocalDefId > ) -> TypeckTables < ' tcx > {
420
+ pub fn new ( hir_owner : LocalDefId ) -> TypeckTables < ' tcx > {
436
421
TypeckTables {
437
422
hir_owner,
438
423
type_dependent_defs : Default :: default ( ) ,
@@ -474,7 +459,7 @@ impl<'tcx> TypeckTables<'tcx> {
474
459
}
475
460
476
461
pub fn type_dependent_def ( & self , id : HirId ) -> Option < ( DefKind , DefId ) > {
477
- validate_hir_id_for_typeck_tables ( self . hir_owner , id, false ) ;
462
+ validate_hir_id_for_typeck_tables ( self . hir_owner , id) ;
478
463
self . type_dependent_defs . get ( & id. local_id ) . cloned ( ) . and_then ( |r| r. ok ( ) )
479
464
}
480
465
@@ -521,7 +506,7 @@ impl<'tcx> TypeckTables<'tcx> {
521
506
}
522
507
523
508
pub fn node_type_opt ( & self , id : hir:: HirId ) -> Option < Ty < ' tcx > > {
524
- validate_hir_id_for_typeck_tables ( self . hir_owner , id, false ) ;
509
+ validate_hir_id_for_typeck_tables ( self . hir_owner , id) ;
525
510
self . node_types . get ( & id. local_id ) . cloned ( )
526
511
}
527
512
@@ -530,12 +515,12 @@ impl<'tcx> TypeckTables<'tcx> {
530
515
}
531
516
532
517
pub fn node_substs ( & self , id : hir:: HirId ) -> SubstsRef < ' tcx > {
533
- validate_hir_id_for_typeck_tables ( self . hir_owner , id, false ) ;
518
+ validate_hir_id_for_typeck_tables ( self . hir_owner , id) ;
534
519
self . node_substs . get ( & id. local_id ) . cloned ( ) . unwrap_or_else ( || InternalSubsts :: empty ( ) )
535
520
}
536
521
537
522
pub fn node_substs_opt ( & self , id : hir:: HirId ) -> Option < SubstsRef < ' tcx > > {
538
- validate_hir_id_for_typeck_tables ( self . hir_owner , id, false ) ;
523
+ validate_hir_id_for_typeck_tables ( self . hir_owner , id) ;
539
524
self . node_substs . get ( & id. local_id ) . cloned ( )
540
525
}
541
526
@@ -578,7 +563,7 @@ impl<'tcx> TypeckTables<'tcx> {
578
563
}
579
564
580
565
pub fn expr_adjustments ( & self , expr : & hir:: Expr < ' _ > ) -> & [ ty:: adjustment:: Adjustment < ' tcx > ] {
581
- validate_hir_id_for_typeck_tables ( self . hir_owner , expr. hir_id , false ) ;
566
+ validate_hir_id_for_typeck_tables ( self . hir_owner , expr. hir_id ) ;
582
567
self . adjustments . get ( & expr. hir_id . local_id ) . map_or ( & [ ] , |a| & a[ ..] )
583
568
}
584
569
@@ -657,7 +642,7 @@ impl<'tcx> TypeckTables<'tcx> {
657
642
}
658
643
659
644
pub fn is_coercion_cast ( & self , hir_id : hir:: HirId ) -> bool {
660
- validate_hir_id_for_typeck_tables ( self . hir_owner , hir_id, true ) ;
645
+ validate_hir_id_for_typeck_tables ( self . hir_owner , hir_id) ;
661
646
self . coercion_casts . contains ( & hir_id. local_id )
662
647
}
663
648
@@ -710,7 +695,7 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for TypeckTables<'tcx> {
710
695
hash_stable_hashmap ( hcx, hasher, upvar_capture_map, |up_var_id, hcx| {
711
696
let ty:: UpvarId { var_path, closure_expr_id } = * up_var_id;
712
697
713
- assert_eq ! ( Some ( var_path. hir_id. owner) , hir_owner) ;
698
+ assert_eq ! ( var_path. hir_id. owner, hir_owner) ;
714
699
715
700
(
716
701
hcx. local_def_path_hash ( var_path. hir_id . owner ) ,
0 commit comments