Skip to content

Commit fae7da3

Browse files
committed
erase regions in MIR borrowck when checking if type moves by default
1 parent 4cf1117 commit fae7da3

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/librustc_mir/borrow_check.rs

+13-4
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,
@@ -154,7 +153,6 @@ pub struct MirBorrowckCtxt<'cx, 'gcx: 'tcx, 'tcx: 'cx> {
154153
node_id: ast::NodeId,
155154
move_data: &'cx MoveData<'tcx>,
156155
param_env: ParamEnv<'gcx>,
157-
fake_infer_ctxt: &'cx InferCtxt<'cx, 'gcx, 'tcx>,
158156
}
159157

160158
// (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> {
592590
lvalue_span: (&Lvalue<'tcx>, Span),
593591
flow_state: &InProgress<'cx, 'gcx, 'tcx>) {
594592
let lvalue = lvalue_span.0;
593+
595594
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+
598607
if moves_by_default {
599608
// move of lvalue: check if this is move of already borrowed path
600609
self.access_lvalue(context, lvalue_span, (Deep, Write(WriteKind::Move)), flow_state);

0 commit comments

Comments
 (0)