@@ -188,7 +188,7 @@ pub struct CommonConsts<'tcx> {
188188}
189189
190190pub struct LocalTableInContext < ' a , V > {
191- hir_owner : Option < LocalDefId > ,
191+ hir_owner : LocalDefId ,
192192 data : & ' a ItemLocalMap < V > ,
193193}
194194
@@ -199,42 +199,27 @@ pub struct LocalTableInContext<'a, V> {
199199/// would be in a different frame of reference and using its `local_id`
200200/// would result in lookup errors, or worse, in silently wrong data being
201201/// 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+ } ) ;
227212 }
228213}
229214
230215impl < ' a , V > LocalTableInContext < ' a , V > {
231216 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) ;
233218 self . data . contains_key ( & id. local_id )
234219 }
235220
236221 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) ;
238223 self . data . get ( & id. local_id )
239224 }
240225
@@ -252,28 +237,28 @@ impl<'a, V> ::std::ops::Index<hir::HirId> for LocalTableInContext<'a, V> {
252237}
253238
254239pub struct LocalTableInContextMut < ' a , V > {
255- hir_owner : Option < LocalDefId > ,
240+ hir_owner : LocalDefId ,
256241 data : & ' a mut ItemLocalMap < V > ,
257242}
258243
259244impl < ' a , V > LocalTableInContextMut < ' a , V > {
260245 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) ;
262247 self . data . get_mut ( & id. local_id )
263248 }
264249
265250 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) ;
267252 self . data . entry ( id. local_id )
268253 }
269254
270255 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) ;
272257 self . data . insert ( id. local_id , val)
273258 }
274259
275260 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) ;
277262 self . data . remove ( & id. local_id )
278263 }
279264}
@@ -324,7 +309,7 @@ pub struct GeneratorInteriorTypeCause<'tcx> {
324309#[ derive( RustcEncodable , RustcDecodable , Debug ) ]
325310pub struct TypeckTables < ' tcx > {
326311 /// The `HirId::owner` all `ItemLocalId`s in this table are relative to.
327- pub hir_owner : Option < LocalDefId > ,
312+ pub hir_owner : LocalDefId ,
328313
329314 /// Resolved definitions for `<T>::X` associated paths and
330315 /// method calls, including those of overloaded operators.
@@ -432,7 +417,7 @@ pub struct TypeckTables<'tcx> {
432417}
433418
434419impl < ' tcx > TypeckTables < ' tcx > {
435- pub fn empty ( hir_owner : Option < LocalDefId > ) -> TypeckTables < ' tcx > {
420+ pub fn new ( hir_owner : LocalDefId ) -> TypeckTables < ' tcx > {
436421 TypeckTables {
437422 hir_owner,
438423 type_dependent_defs : Default :: default ( ) ,
@@ -474,7 +459,7 @@ impl<'tcx> TypeckTables<'tcx> {
474459 }
475460
476461 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) ;
478463 self . type_dependent_defs . get ( & id. local_id ) . cloned ( ) . and_then ( |r| r. ok ( ) )
479464 }
480465
@@ -521,7 +506,7 @@ impl<'tcx> TypeckTables<'tcx> {
521506 }
522507
523508 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) ;
525510 self . node_types . get ( & id. local_id ) . cloned ( )
526511 }
527512
@@ -530,12 +515,12 @@ impl<'tcx> TypeckTables<'tcx> {
530515 }
531516
532517 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) ;
534519 self . node_substs . get ( & id. local_id ) . cloned ( ) . unwrap_or_else ( || InternalSubsts :: empty ( ) )
535520 }
536521
537522 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) ;
539524 self . node_substs . get ( & id. local_id ) . cloned ( )
540525 }
541526
@@ -578,7 +563,7 @@ impl<'tcx> TypeckTables<'tcx> {
578563 }
579564
580565 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 ) ;
582567 self . adjustments . get ( & expr. hir_id . local_id ) . map_or ( & [ ] , |a| & a[ ..] )
583568 }
584569
@@ -657,7 +642,7 @@ impl<'tcx> TypeckTables<'tcx> {
657642 }
658643
659644 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) ;
661646 self . coercion_casts . contains ( & hir_id. local_id )
662647 }
663648
@@ -710,7 +695,7 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for TypeckTables<'tcx> {
710695 hash_stable_hashmap ( hcx, hasher, upvar_capture_map, |up_var_id, hcx| {
711696 let ty:: UpvarId { var_path, closure_expr_id } = * up_var_id;
712697
713- assert_eq ! ( Some ( var_path. hir_id. owner) , hir_owner) ;
698+ assert_eq ! ( var_path. hir_id. owner, hir_owner) ;
714699
715700 (
716701 hcx. local_def_path_hash ( var_path. hir_id . owner ) ,
0 commit comments