@@ -136,7 +136,6 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>,
136
136
node_id : id,
137
137
move_data : & mdpe. move_data ,
138
138
param_env : param_env,
139
- fake_infer_ctxt : & infcx,
140
139
} ;
141
140
142
141
let mut state = InProgress :: new ( flow_borrows,
@@ -154,7 +153,6 @@ pub struct MirBorrowckCtxt<'cx, 'gcx: 'tcx, 'tcx: 'cx> {
154
153
node_id : ast:: NodeId ,
155
154
move_data : & ' cx MoveData < ' tcx > ,
156
155
param_env : ParamEnv < ' gcx > ,
157
- fake_infer_ctxt : & ' cx InferCtxt < ' cx , ' gcx , ' tcx > ,
158
156
}
159
157
160
158
// (forced to be `pub` due to its use as an associated type below.)
@@ -592,9 +590,20 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
592
590
lvalue_span : ( & Lvalue < ' tcx > , Span ) ,
593
591
flow_state : & InProgress < ' cx , ' gcx , ' tcx > ) {
594
592
let lvalue = lvalue_span. 0 ;
593
+
595
594
let ty = lvalue. ty ( self . mir , self . tcx ) . to_ty ( self . tcx ) ;
596
- let moves_by_default =
597
- self . fake_infer_ctxt . type_moves_by_default ( self . param_env , ty, DUMMY_SP ) ;
595
+
596
+ // Erase the regions in type before checking whether it moves by
597
+ // default. There are a few reasons to do this:
598
+ //
599
+ // - They should not affect the result.
600
+ // - It avoids adding new region constraints into the surrounding context,
601
+ // which would trigger an ICE, since the infcx will have been "frozen" by
602
+ // the NLL region context.
603
+ let gcx = self . tcx . global_tcx ( ) ;
604
+ let erased_ty = gcx. lift ( & self . tcx . erase_regions ( & ty) ) . unwrap ( ) ;
605
+ let moves_by_default = erased_ty. moves_by_default ( gcx, self . param_env , DUMMY_SP ) ;
606
+
598
607
if moves_by_default {
599
608
// move of lvalue: check if this is move of already borrowed path
600
609
self . access_lvalue ( context, lvalue_span, ( Deep , Write ( WriteKind :: Move ) ) , flow_state) ;
0 commit comments