@@ -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,
@@ -153,7 +152,6 @@ pub struct MirBorrowckCtxt<'cx, 'gcx: 'tcx, 'tcx: 'cx> {
153
152
node_id : ast:: NodeId ,
154
153
move_data : & ' cx MoveData < ' tcx > ,
155
154
param_env : ParamEnv < ' gcx > ,
156
- fake_infer_ctxt : & ' cx InferCtxt < ' cx , ' gcx , ' tcx > ,
157
155
}
158
156
159
157
// (forced to be `pub` due to its use as an associated type below.)
@@ -583,9 +581,20 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
583
581
lvalue_span : ( & Lvalue < ' tcx > , Span ) ,
584
582
flow_state : & InProgress < ' cx , ' gcx , ' tcx > ) {
585
583
let lvalue = lvalue_span. 0 ;
584
+
586
585
let ty = lvalue. ty ( self . mir , self . tcx ) . to_ty ( self . tcx ) ;
587
- let moves_by_default =
588
- self . fake_infer_ctxt . type_moves_by_default ( self . param_env , ty, DUMMY_SP ) ;
586
+
587
+ // Erase the regions in type before checking whether it moves by
588
+ // default. There are a few reasons to do this:
589
+ //
590
+ // - They should not affect the result.
591
+ // - It avoids adding new region constraints into the surrounding context,
592
+ // which would trigger an ICE, since the infcx will have been "frozen" by
593
+ // the NLL region context.
594
+ let gcx = self . tcx . global_tcx ( ) ;
595
+ let erased_ty = gcx. lift ( & self . tcx . erase_regions ( & ty) ) . unwrap ( ) ;
596
+ let moves_by_default = erased_ty. moves_by_default ( gcx, self . param_env , DUMMY_SP ) ;
597
+
589
598
if moves_by_default {
590
599
// move of lvalue: check if this is move of already borrowed path
591
600
self . access_lvalue ( context, lvalue_span, ( Deep , Write ( WriteKind :: Move ) ) , flow_state) ;
0 commit comments