@@ -76,9 +76,9 @@ use crate::check::dropck;
7676use crate :: check:: FnCtxt ;
7777use crate :: mem_categorization as mc;
7878use crate :: outlives:: outlives_bounds:: InferCtxtExt as _;
79+ use hir:: def_id:: LocalDefId ;
7980use rustc_data_structures:: stable_set:: FxHashSet ;
8081use rustc_hir as hir;
81- use rustc_hir:: def_id:: LocalDefId ;
8282use rustc_hir:: intravisit:: { self , Visitor } ;
8383use rustc_hir:: PatKind ;
8484use rustc_infer:: infer:: outlives:: env:: OutlivesEnvironment ;
@@ -149,19 +149,18 @@ impl<'tcx> OutlivesEnvironmentExt<'tcx> for OutlivesEnvironment<'tcx> {
149149// PUBLIC ENTRY POINTS
150150
151151impl < ' a , ' tcx > FnCtxt < ' a , ' tcx > {
152- pub fn regionck_expr ( & self , body : & ' tcx hir:: Body < ' tcx > ) {
153- let subject = self . tcx . hir ( ) . body_owner_def_id ( body. id ( ) ) ;
154- let id = body. value . hir_id ;
155- let mut rcx = RegionCtxt :: new ( self , id, Subject ( subject) , self . param_env ) ;
152+ pub fn regionck_body ( & self , body : & ' tcx hir:: Body < ' tcx > ) {
153+ let body_owner = self . tcx . hir ( ) . body_owner_def_id ( body. id ( ) ) ;
154+ let mut rcx = RegionCtxt :: new ( self , body_owner, self . param_env ) ;
156155
157156 // There are no add'l implied bounds when checking a
158- // standalone expr (e.g., the `E` in a type like `[u32; E]`).
159- rcx. outlives_environment . save_implied_bounds ( id ) ;
157+ // standalone body (e.g., the `E` in a type like `[u32; E]`).
158+ rcx. outlives_environment . save_implied_bounds ( rcx . body_id ( ) ) ;
160159
161160 if !self . errors_reported_since_creation ( ) {
162161 // regionck assumes typeck succeeded
163162 rcx. visit_body ( body) ;
164- rcx. visit_region_obligations ( id ) ;
163+ rcx. visit_region_obligations ( rcx . body_id ( ) ) ;
165164 }
166165 // Checked by NLL
167166 rcx. fcx . skip_region_resolution ( ) ;
@@ -171,10 +170,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
171170 /// types from which we should derive implied bounds, if any.
172171 #[ instrument( level = "debug" , skip( self ) ) ]
173172 pub fn regionck_item ( & self , item_id : hir:: HirId , span : Span , wf_tys : FxHashSet < Ty < ' tcx > > ) {
174- let subject = self . tcx . hir ( ) . local_def_id ( item_id) ;
175- let mut rcx = RegionCtxt :: new ( self , item_id , Subject ( subject ) , self . param_env ) ;
173+ let body_owner = self . tcx . hir ( ) . local_def_id ( item_id) ;
174+ let mut rcx = RegionCtxt :: new ( self , body_owner , self . param_env ) ;
176175 rcx. outlives_environment . add_implied_bounds ( self , wf_tys, item_id, span) ;
177- rcx. outlives_environment . save_implied_bounds ( item_id ) ;
176+ rcx. outlives_environment . save_implied_bounds ( rcx . body_id ( ) ) ;
178177 rcx. visit_region_obligations ( item_id) ;
179178 rcx. resolve_regions_and_report_errors ( ) ;
180179 }
@@ -195,9 +194,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
195194 wf_tys : FxHashSet < Ty < ' tcx > > ,
196195 ) {
197196 debug ! ( "regionck_fn(id={})" , fn_id) ;
198- let subject = self . tcx . hir ( ) . body_owner_def_id ( body. id ( ) ) ;
199- let hir_id = body. value . hir_id ;
200- let mut rcx = RegionCtxt :: new ( self , hir_id, Subject ( subject) , self . param_env ) ;
197+ let body_owner = self . tcx . hir ( ) . body_owner_def_id ( body. id ( ) ) ;
198+ let mut rcx = RegionCtxt :: new ( self , body_owner, self . param_env ) ;
201199 // We need to add the implied bounds from the function signature
202200 rcx. outlives_environment . add_implied_bounds ( self , wf_tys, fn_id, span) ;
203201 rcx. outlives_environment . save_implied_bounds ( fn_id) ;
@@ -220,9 +218,6 @@ pub struct RegionCtxt<'a, 'tcx> {
220218
221219 outlives_environment : OutlivesEnvironment < ' tcx > ,
222220
223- // id of innermost fn body id
224- body_id : hir:: HirId ,
225- // TODO: is this always equal to `body_id`?
226221 body_owner : LocalDefId ,
227222}
228223
@@ -233,17 +228,21 @@ impl<'a, 'tcx> Deref for RegionCtxt<'a, 'tcx> {
233228 }
234229}
235230
236- pub struct Subject ( LocalDefId ) ;
237-
238231impl < ' a , ' tcx > RegionCtxt < ' a , ' tcx > {
239232 pub fn new (
240233 fcx : & ' a FnCtxt < ' a , ' tcx > ,
241- initial_body_id : hir:: HirId ,
242- Subject ( subject) : Subject ,
234+ body_owner : LocalDefId ,
243235 param_env : ty:: ParamEnv < ' tcx > ,
244236 ) -> RegionCtxt < ' a , ' tcx > {
245237 let outlives_environment = OutlivesEnvironment :: new ( param_env) ;
246- RegionCtxt { fcx, body_id : initial_body_id, body_owner : subject, outlives_environment }
238+ RegionCtxt { fcx, body_owner, outlives_environment }
239+ }
240+
241+ /// FIXME: Ideally all the callers would deal with
242+ /// `LocalDefId`s as well. Ah well, this code is going
243+ /// to be removed soon anyways 🤷
244+ pub fn body_id ( & self ) -> hir:: HirId {
245+ self . tcx . hir ( ) . local_def_id_to_hir_id ( self . body_owner )
247246 }
248247
249248 /// Try to resolve the type for the given node, returning `t_err` if an error results. Note that
@@ -299,9 +298,7 @@ impl<'a, 'tcx> RegionCtxt<'a, 'tcx> {
299298 ) {
300299 // When we enter a function, we can derive
301300 debug ! ( "visit_fn_body(id={:?})" , id) ;
302-
303301 let body_id = body. id ( ) ;
304- self . body_id = body_id. hir_id ;
305302 self . body_owner = self . tcx . hir ( ) . body_owner_def_id ( body_id) ;
306303
307304 let Some ( fn_sig) = self . typeck_results . borrow ( ) . liberated_fn_sigs ( ) . get ( id) else {
@@ -327,12 +324,10 @@ impl<'a, 'tcx> RegionCtxt<'a, 'tcx> {
327324 debug ! ( "visit_inline_const(id={:?})" , id) ;
328325
329326 // Save state of current function. We will restore afterwards.
330- let old_body_id = self . body_id ;
331327 let old_body_owner = self . body_owner ;
332328 let env_snapshot = self . outlives_environment . push_snapshot_pre_typeck_child ( ) ;
333329
334330 let body_id = body. id ( ) ;
335- self . body_id = body_id. hir_id ;
336331 self . body_owner = self . tcx . hir ( ) . body_owner_def_id ( body_id) ;
337332
338333 self . outlives_environment . save_implied_bounds ( body_id. hir_id ) ;
@@ -342,7 +337,6 @@ impl<'a, 'tcx> RegionCtxt<'a, 'tcx> {
342337
343338 // Restore state from previous function.
344339 self . outlives_environment . pop_snapshot_post_typeck_child ( env_snapshot) ;
345- self . body_id = old_body_id;
346340 self . body_owner = old_body_owner;
347341 }
348342
@@ -398,7 +392,6 @@ impl<'a, 'tcx> Visitor<'tcx> for RegionCtxt<'a, 'tcx> {
398392
399393 // Save state of current function before invoking
400394 // `visit_fn_body`. We will restore afterwards.
401- let old_body_id = self . body_id ;
402395 let old_body_owner = self . body_owner ;
403396 let env_snapshot = self . outlives_environment . push_snapshot_pre_typeck_child ( ) ;
404397
@@ -407,7 +400,6 @@ impl<'a, 'tcx> Visitor<'tcx> for RegionCtxt<'a, 'tcx> {
407400
408401 // Restore state from previous function.
409402 self . outlives_environment . pop_snapshot_post_typeck_child ( env_snapshot) ;
410- self . body_id = old_body_id;
411403 self . body_owner = old_body_owner;
412404 }
413405
0 commit comments