@@ -266,30 +266,21 @@ fn do_mir_borrowck<'tcx>(
266
266
use rustc_middle:: mir:: visit:: Visitor ;
267
267
268
268
let promoted_body = & promoted[ idx] ;
269
- let mut promoted_mbcx = MirBorrowckCtxt {
270
- infcx : & infcx,
269
+ let mut promoted_mbcx = MirBorrowckCtxt :: new (
270
+ & infcx,
271
271
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
275
275
movable_coroutine,
276
- fn_self_span_reported : Default :: default ( ) ,
277
276
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
291
282
diags,
292
- } ;
283
+ ) ;
293
284
MoveVisitor { ctxt : & mut promoted_mbcx } . visit_body ( promoted_body) ;
294
285
promoted_mbcx. report_move_errors ( ) ;
295
286
diags = promoted_mbcx. diags ;
@@ -307,30 +298,21 @@ fn do_mir_borrowck<'tcx>(
307
298
}
308
299
}
309
300
310
- let mut mbcx = MirBorrowckCtxt {
311
- infcx : & infcx,
301
+ let mut mbcx = MirBorrowckCtxt :: new (
302
+ & infcx,
312
303
param_env,
313
304
body,
314
- move_data : & move_data,
315
- location_table : & location_table,
305
+ & move_data,
306
+ & location_table,
316
307
movable_coroutine,
317
308
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
327
312
local_names,
328
- region_names : RefCell :: default ( ) ,
329
- next_region_name : RefCell :: new ( 1 ) ,
330
313
polonius_output,
331
- move_errors : Vec :: new ( ) ,
332
314
diags,
333
- } ;
315
+ ) ;
334
316
335
317
// Compute and report region errors, if any.
336
318
mbcx. report_region_errors ( nll_errors) ;
@@ -584,6 +566,49 @@ struct MirBorrowckCtxt<'a, 'infcx, 'tcx> {
584
566
move_errors : Vec < MoveError < ' tcx > > ,
585
567
}
586
568
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
+
587
612
// Check that:
588
613
// 1. assignments are always made to mutable locations (FIXME: does that still really go here?)
589
614
// 2. loans made in overlapping scopes do not conflict
0 commit comments