3
3
use crate :: build:: expr:: category:: Category ;
4
4
use crate :: build:: ForGuard :: { OutsideGuard , RefWithinGuard } ;
5
5
use crate :: build:: { BlockAnd , BlockAndExtension , Builder } ;
6
- use rustc_hir:: def_id:: DefId ;
7
- use rustc_hir:: HirId ;
6
+ use rustc_hir:: def_id:: { DefId , LocalDefId } ;
8
7
use rustc_middle:: hir:: place:: Projection as HirProjection ;
9
8
use rustc_middle:: hir:: place:: ProjectionKind as HirProjectionKind ;
10
9
use rustc_middle:: middle:: region;
@@ -57,7 +56,7 @@ pub(crate) enum PlaceBase {
57
56
/// figure out that it is captured until all the `Field` projections are applied.
58
57
Upvar {
59
58
/// HirId of the upvar
60
- var_hir_id : HirId ,
59
+ var_hir_id : LocalVarId ,
61
60
/// DefId of the closure
62
61
closure_def_id : DefId ,
63
62
/// The trait closure implements, `Fn`, `FnMut`, `FnOnce`
@@ -151,12 +150,12 @@ fn is_ancestor_or_same_capture(
151
150
/// `ty::MinCaptureList` of the root variable `var_hir_id`.
152
151
fn compute_capture_idx < ' tcx > (
153
152
closure_min_captures : & ty:: RootVariableMinCaptureList < ' tcx > ,
154
- var_hir_id : HirId ,
153
+ var_hir_id : LocalVarId ,
155
154
root_var_idx : usize ,
156
155
) -> usize {
157
156
let mut res = 0 ;
158
157
for ( var_id, capture_list) in closure_min_captures {
159
- if * var_id == var_hir_id {
158
+ if * var_id == var_hir_id. 0 {
160
159
res += root_var_idx;
161
160
break ;
162
161
} else {
@@ -176,12 +175,12 @@ fn compute_capture_idx<'tcx>(
176
175
/// Returns None, when the ancestor is not found.
177
176
fn find_capture_matching_projections < ' a , ' tcx > (
178
177
typeck_results : & ' a ty:: TypeckResults < ' tcx > ,
179
- var_hir_id : HirId ,
178
+ var_hir_id : LocalVarId ,
180
179
closure_def_id : DefId ,
181
180
projections : & [ PlaceElem < ' tcx > ] ,
182
181
) -> Option < ( usize , & ' a ty:: CapturedPlace < ' tcx > ) > {
183
182
let closure_min_captures = typeck_results. closure_min_captures . get ( & closure_def_id) ?;
184
- let root_variable_min_captures = closure_min_captures. get ( & var_hir_id) ?;
183
+ let root_variable_min_captures = closure_min_captures. get ( & var_hir_id. 0 ) ?;
185
184
186
185
let hir_projections = convert_to_hir_projections_and_truncate_for_capture ( projections) ;
187
186
@@ -500,8 +499,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
500
499
source_info,
501
500
) ,
502
501
ExprKind :: UpvarRef { closure_def_id, var_hir_id } => {
503
- let upvar_id = ty:: UpvarId :: new ( var_hir_id, closure_def_id. expect_local ( ) ) ;
504
- this. lower_captured_upvar ( block, upvar_id)
502
+ this. lower_captured_upvar ( block, closure_def_id. expect_local ( ) , var_hir_id)
505
503
}
506
504
507
505
ExprKind :: VarRef { id } => {
@@ -627,11 +625,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
627
625
fn lower_captured_upvar (
628
626
& mut self ,
629
627
block : BasicBlock ,
630
- upvar_id : ty:: UpvarId ,
628
+ closure_expr_id : LocalDefId ,
629
+ var_hir_id : LocalVarId ,
631
630
) -> BlockAnd < PlaceBuilder < ' tcx > > {
632
- let closure_ty = self
633
- . typeck_results
634
- . node_type ( self . tcx . hir ( ) . local_def_id_to_hir_id ( upvar_id. closure_expr_id ) ) ;
631
+ let closure_ty =
632
+ self . typeck_results . node_type ( self . tcx . hir ( ) . local_def_id_to_hir_id ( closure_expr_id) ) ;
635
633
636
634
let closure_kind = if let ty:: Closure ( _, closure_substs) = closure_ty. kind ( ) {
637
635
self . infcx . closure_kind ( closure_substs) . unwrap ( )
@@ -641,8 +639,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
641
639
} ;
642
640
643
641
block. and ( PlaceBuilder :: from ( PlaceBase :: Upvar {
644
- var_hir_id : upvar_id . var_path . hir_id ,
645
- closure_def_id : upvar_id . closure_expr_id . to_def_id ( ) ,
642
+ var_hir_id,
643
+ closure_def_id : closure_expr_id. to_def_id ( ) ,
646
644
closure_kind,
647
645
} ) )
648
646
}
0 commit comments