Skip to content

Commit de77c74

Browse files
committed
Add MirBorrowckCtxt::new.
It is boilerplate-y , but it also factors out some icky duplication of field setting at the two call sites, so I think it's worth it.
1 parent 96803aa commit de77c74

File tree

1 file changed

+62
-37
lines changed
  • compiler/rustc_borrowck/src

1 file changed

+62
-37
lines changed

compiler/rustc_borrowck/src/lib.rs

Lines changed: 62 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -266,30 +266,21 @@ fn do_mir_borrowck<'tcx>(
266266
use rustc_middle::mir::visit::Visitor;
267267

268268
let promoted_body = &promoted[idx];
269-
let mut promoted_mbcx = MirBorrowckCtxt {
270-
infcx: &infcx,
269+
let mut promoted_mbcx = MirBorrowckCtxt::new(
270+
&infcx,
271271
param_env,
272-
body: promoted_body,
273-
move_data: &move_data,
274-
location_table: &location_table, // no need to create a real one for the promoted, it is not used
272+
promoted_body,
273+
&move_data,
274+
&location_table, // no need to create a real one for the promoted, it is not used
275275
movable_coroutine,
276-
fn_self_span_reported: Default::default(),
277276
locals_are_invalidated_at_exit,
278-
access_place_error_reported: Default::default(),
279-
reservation_error_reported: Default::default(),
280-
uninitialized_error_reported: Default::default(),
281-
regioncx: &regioncx,
282-
used_mut: Default::default(),
283-
used_mut_upvars: SmallVec::new(),
284-
borrow_set: &borrow_set,
285-
upvars: &[],
286-
local_names: IndexVec::from_elem(None, &promoted_body.local_decls),
287-
region_names: RefCell::default(),
288-
next_region_name: RefCell::new(1),
289-
polonius_output: None,
290-
move_errors: Vec::new(),
277+
&regioncx,
278+
&borrow_set,
279+
&[], // upvars
280+
IndexVec::from_elem(None, &promoted_body.local_decls), // local_names
281+
None, // polonius_output
291282
diags,
292-
};
283+
);
293284
MoveVisitor { ctxt: &mut promoted_mbcx }.visit_body(promoted_body);
294285
promoted_mbcx.report_move_errors();
295286
diags = promoted_mbcx.diags;
@@ -307,30 +298,21 @@ fn do_mir_borrowck<'tcx>(
307298
}
308299
}
309300

310-
let mut mbcx = MirBorrowckCtxt {
311-
infcx: &infcx,
301+
let mut mbcx = MirBorrowckCtxt::new(
302+
&infcx,
312303
param_env,
313304
body,
314-
move_data: &move_data,
315-
location_table: &location_table,
305+
&move_data,
306+
&location_table,
316307
movable_coroutine,
317308
locals_are_invalidated_at_exit,
318-
fn_self_span_reported: Default::default(),
319-
access_place_error_reported: Default::default(),
320-
reservation_error_reported: Default::default(),
321-
uninitialized_error_reported: Default::default(),
322-
regioncx: &regioncx,
323-
used_mut: Default::default(),
324-
used_mut_upvars: SmallVec::new(),
325-
borrow_set: &borrow_set,
326-
upvars: tcx.closure_captures(def),
309+
&regioncx,
310+
&borrow_set,
311+
tcx.closure_captures(def), // upvars
327312
local_names,
328-
region_names: RefCell::default(),
329-
next_region_name: RefCell::new(1),
330313
polonius_output,
331-
move_errors: Vec::new(),
332314
diags,
333-
};
315+
);
334316

335317
// Compute and report region errors, if any.
336318
mbcx.report_region_errors(nll_errors);
@@ -584,6 +566,49 @@ struct MirBorrowckCtxt<'a, 'infcx, 'tcx> {
584566
move_errors: Vec<MoveError<'tcx>>,
585567
}
586568

569+
impl<'a, 'infcx, 'tcx> MirBorrowckCtxt<'a, 'infcx, 'tcx> {
570+
fn new(
571+
infcx: &'infcx BorrowckInferCtxt<'tcx>,
572+
param_env: ParamEnv<'tcx>,
573+
body: &'a Body<'tcx>,
574+
move_data: &'a MoveData<'tcx>,
575+
location_table: &'a LocationTable,
576+
movable_coroutine: bool,
577+
locals_are_invalidated_at_exit: bool,
578+
regioncx: &'a RegionInferenceContext<'tcx>,
579+
borrow_set: &'a BorrowSet<'tcx>,
580+
upvars: &'tcx [&'tcx ty::CapturedPlace<'tcx>],
581+
local_names: IndexVec<Local, Option<Symbol>>,
582+
polonius_output: Option<Box<PoloniusOutput>>,
583+
diags: diags::BorrowckDiags<'infcx, 'tcx>,
584+
) -> Self {
585+
MirBorrowckCtxt {
586+
infcx,
587+
param_env,
588+
body,
589+
move_data,
590+
location_table,
591+
movable_coroutine,
592+
locals_are_invalidated_at_exit,
593+
access_place_error_reported: Default::default(),
594+
reservation_error_reported: Default::default(),
595+
fn_self_span_reported: Default::default(),
596+
uninitialized_error_reported: Default::default(),
597+
used_mut: Default::default(),
598+
used_mut_upvars: SmallVec::new(),
599+
regioncx,
600+
borrow_set,
601+
upvars,
602+
local_names,
603+
region_names: RefCell::default(),
604+
next_region_name: RefCell::new(1),
605+
polonius_output,
606+
diags,
607+
move_errors: Vec::new(),
608+
}
609+
}
610+
}
611+
587612
// Check that:
588613
// 1. assignments are always made to mutable locations (FIXME: does that still really go here?)
589614
// 2. loans made in overlapping scopes do not conflict

0 commit comments

Comments
 (0)