Skip to content

Commit 73c9854

Browse files
committed
erase regions in MIR borrowck when checking if type moves by default
1 parent ee19f2c commit 73c9854

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/librustc_mir/borrow_check.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>,
136136
node_id: id,
137137
move_data: &mdpe.move_data,
138138
param_env: param_env,
139-
fake_infer_ctxt: &infcx,
140139
};
141140

142141
let mut state = InProgress::new(flow_borrows,
@@ -153,7 +152,6 @@ pub struct MirBorrowckCtxt<'cx, 'gcx: 'tcx, 'tcx: 'cx> {
153152
node_id: ast::NodeId,
154153
move_data: &'cx MoveData<'tcx>,
155154
param_env: ParamEnv<'gcx>,
156-
fake_infer_ctxt: &'cx InferCtxt<'cx, 'gcx, 'tcx>,
157155
}
158156

159157
// (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> {
583581
lvalue_span: (&Lvalue<'tcx>, Span),
584582
flow_state: &InProgress<'cx, 'gcx, 'tcx>) {
585583
let lvalue = lvalue_span.0;
584+
586585
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+
589598
if moves_by_default {
590599
// move of lvalue: check if this is move of already borrowed path
591600
self.access_lvalue(context, lvalue_span, (Deep, Write(WriteKind::Move)), flow_state);

0 commit comments

Comments
 (0)