@@ -147,6 +147,14 @@ impl Display for RegionName {
147
147
}
148
148
149
149
impl < ' tcx > MirBorrowckCtxt < ' _ , ' tcx > {
150
+ crate fn mir_def_id ( & self ) -> hir:: def_id:: LocalDefId {
151
+ self . body . source . def_id ( ) . as_local ( ) . unwrap ( )
152
+ }
153
+
154
+ crate fn mir_hir_id ( & self ) -> hir:: HirId {
155
+ self . infcx . tcx . hir ( ) . local_def_id_to_hir_id ( self . mir_def_id ( ) )
156
+ }
157
+
150
158
/// Generate a synthetic region named `'N`, where `N` is the next value of the counter. Then,
151
159
/// increment the counter.
152
160
///
@@ -266,12 +274,11 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
266
274
}
267
275
268
276
ty:: BoundRegion :: BrEnv => {
269
- let mir_hir_id = self . infcx . tcx . hir ( ) . local_def_id_to_hir_id ( self . mir_def_id ) ;
270
277
let def_ty = self . regioncx . universal_regions ( ) . defining_ty ;
271
278
272
279
if let DefiningTy :: Closure ( _, substs) = def_ty {
273
280
let args_span = if let hir:: ExprKind :: Closure ( _, _, _, span, _) =
274
- tcx. hir ( ) . expect_expr ( mir_hir_id) . kind
281
+ tcx. hir ( ) . expect_expr ( self . mir_hir_id ( ) ) . kind
275
282
{
276
283
span
277
284
} else {
@@ -361,8 +368,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
361
368
& self ,
362
369
argument_index : usize ,
363
370
) -> Option < & hir:: Ty < ' tcx > > {
364
- let mir_hir_id = self . infcx . tcx . hir ( ) . local_def_id_to_hir_id ( self . mir_def_id ) ;
365
- let fn_decl = self . infcx . tcx . hir ( ) . fn_decl_by_hir_id ( mir_hir_id) ?;
371
+ let fn_decl = self . infcx . tcx . hir ( ) . fn_decl_by_hir_id ( self . mir_hir_id ( ) ) ?;
366
372
let argument_hir_ty: & hir:: Ty < ' _ > = fn_decl. inputs . get ( argument_index) ?;
367
373
match argument_hir_ty. kind {
368
374
// This indicates a variable with no type annotation, like
@@ -649,9 +655,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
649
655
let type_name =
650
656
self . infcx . extract_inference_diagnostics_data ( return_ty. into ( ) , Some ( highlight) ) . name ;
651
657
652
- let mir_hir_id = tcx. hir ( ) . local_def_id_to_hir_id ( self . mir_def_id ) ;
653
-
654
- let ( return_span, mir_description) = match tcx. hir ( ) . get ( mir_hir_id) {
658
+ let ( return_span, mir_description) = match tcx. hir ( ) . get ( self . mir_hir_id ( ) ) {
655
659
hir:: Node :: Expr ( hir:: Expr {
656
660
kind : hir:: ExprKind :: Closure ( _, return_ty, _, span, gen_move) ,
657
661
..
@@ -702,9 +706,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
702
706
let type_name =
703
707
self . infcx . extract_inference_diagnostics_data ( yield_ty. into ( ) , Some ( highlight) ) . name ;
704
708
705
- let mir_hir_id = tcx. hir ( ) . local_def_id_to_hir_id ( self . mir_def_id ) ;
706
-
707
- let yield_span = match tcx. hir ( ) . get ( mir_hir_id) {
709
+ let yield_span = match tcx. hir ( ) . get ( self . mir_hir_id ( ) ) {
708
710
hir:: Node :: Expr ( hir:: Expr {
709
711
kind : hir:: ExprKind :: Closure ( _, _, _, span, _) , ..
710
712
} ) => ( tcx. sess . source_map ( ) . end_point ( * span) ) ,
0 commit comments