@@ -76,9 +76,9 @@ use crate::check::dropck;
76
76
use crate :: check:: FnCtxt ;
77
77
use crate :: mem_categorization as mc;
78
78
use crate :: outlives:: outlives_bounds:: InferCtxtExt as _;
79
+ use hir:: def_id:: LocalDefId ;
79
80
use rustc_data_structures:: stable_set:: FxHashSet ;
80
81
use rustc_hir as hir;
81
- use rustc_hir:: def_id:: LocalDefId ;
82
82
use rustc_hir:: intravisit:: { self , Visitor } ;
83
83
use rustc_hir:: PatKind ;
84
84
use rustc_infer:: infer:: outlives:: env:: OutlivesEnvironment ;
@@ -149,19 +149,18 @@ impl<'tcx> OutlivesEnvironmentExt<'tcx> for OutlivesEnvironment<'tcx> {
149
149
// PUBLIC ENTRY POINTS
150
150
151
151
impl < ' 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 ) ;
156
155
157
156
// 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 ( ) ) ;
160
159
161
160
if !self . errors_reported_since_creation ( ) {
162
161
// regionck assumes typeck succeeded
163
162
rcx. visit_body ( body) ;
164
- rcx. visit_region_obligations ( id ) ;
163
+ rcx. visit_region_obligations ( rcx . body_id ( ) ) ;
165
164
}
166
165
// Checked by NLL
167
166
rcx. fcx . skip_region_resolution ( ) ;
@@ -171,10 +170,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
171
170
/// types from which we should derive implied bounds, if any.
172
171
#[ instrument( level = "debug" , skip( self ) ) ]
173
172
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 ) ;
176
175
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 ( ) ) ;
178
177
rcx. visit_region_obligations ( item_id) ;
179
178
rcx. resolve_regions_and_report_errors ( ) ;
180
179
}
@@ -195,9 +194,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
195
194
wf_tys : FxHashSet < Ty < ' tcx > > ,
196
195
) {
197
196
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 ) ;
201
199
// We need to add the implied bounds from the function signature
202
200
rcx. outlives_environment . add_implied_bounds ( self , wf_tys, fn_id, span) ;
203
201
rcx. outlives_environment . save_implied_bounds ( fn_id) ;
@@ -220,9 +218,6 @@ pub struct RegionCtxt<'a, 'tcx> {
220
218
221
219
outlives_environment : OutlivesEnvironment < ' tcx > ,
222
220
223
- // id of innermost fn body id
224
- body_id : hir:: HirId ,
225
- // TODO: is this always equal to `body_id`?
226
221
body_owner : LocalDefId ,
227
222
}
228
223
@@ -233,17 +228,21 @@ impl<'a, 'tcx> Deref for RegionCtxt<'a, 'tcx> {
233
228
}
234
229
}
235
230
236
- pub struct Subject ( LocalDefId ) ;
237
-
238
231
impl < ' a , ' tcx > RegionCtxt < ' a , ' tcx > {
239
232
pub fn new (
240
233
fcx : & ' a FnCtxt < ' a , ' tcx > ,
241
- initial_body_id : hir:: HirId ,
242
- Subject ( subject) : Subject ,
234
+ body_owner : LocalDefId ,
243
235
param_env : ty:: ParamEnv < ' tcx > ,
244
236
) -> RegionCtxt < ' a , ' tcx > {
245
237
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 )
247
246
}
248
247
249
248
/// 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> {
299
298
) {
300
299
// When we enter a function, we can derive
301
300
debug ! ( "visit_fn_body(id={:?})" , id) ;
302
-
303
301
let body_id = body. id ( ) ;
304
- self . body_id = body_id. hir_id ;
305
302
self . body_owner = self . tcx . hir ( ) . body_owner_def_id ( body_id) ;
306
303
307
304
let Some ( fn_sig) = self . typeck_results . borrow ( ) . liberated_fn_sigs ( ) . get ( id) else {
@@ -327,12 +324,10 @@ impl<'a, 'tcx> RegionCtxt<'a, 'tcx> {
327
324
debug ! ( "visit_inline_const(id={:?})" , id) ;
328
325
329
326
// Save state of current function. We will restore afterwards.
330
- let old_body_id = self . body_id ;
331
327
let old_body_owner = self . body_owner ;
332
328
let env_snapshot = self . outlives_environment . push_snapshot_pre_typeck_child ( ) ;
333
329
334
330
let body_id = body. id ( ) ;
335
- self . body_id = body_id. hir_id ;
336
331
self . body_owner = self . tcx . hir ( ) . body_owner_def_id ( body_id) ;
337
332
338
333
self . outlives_environment . save_implied_bounds ( body_id. hir_id ) ;
@@ -342,7 +337,6 @@ impl<'a, 'tcx> RegionCtxt<'a, 'tcx> {
342
337
343
338
// Restore state from previous function.
344
339
self . outlives_environment . pop_snapshot_post_typeck_child ( env_snapshot) ;
345
- self . body_id = old_body_id;
346
340
self . body_owner = old_body_owner;
347
341
}
348
342
@@ -398,7 +392,6 @@ impl<'a, 'tcx> Visitor<'tcx> for RegionCtxt<'a, 'tcx> {
398
392
399
393
// Save state of current function before invoking
400
394
// `visit_fn_body`. We will restore afterwards.
401
- let old_body_id = self . body_id ;
402
395
let old_body_owner = self . body_owner ;
403
396
let env_snapshot = self . outlives_environment . push_snapshot_pre_typeck_child ( ) ;
404
397
@@ -407,7 +400,6 @@ impl<'a, 'tcx> Visitor<'tcx> for RegionCtxt<'a, 'tcx> {
407
400
408
401
// Restore state from previous function.
409
402
self . outlives_environment . pop_snapshot_post_typeck_child ( env_snapshot) ;
410
- self . body_id = old_body_id;
411
403
self . body_owner = old_body_owner;
412
404
}
413
405
0 commit comments