55#![ feature( let_chains) ]
66#![ feature( min_specialization) ]
77#![ feature( never_type) ]
8+ #![ feature( once_cell) ]
89#![ feature( rustc_attrs) ]
910#![ feature( stmt_expr_attributes) ]
1011#![ feature( trusted_step) ]
@@ -39,6 +40,7 @@ use rustc_span::{Span, Symbol};
3940
4041use either:: Either ;
4142use smallvec:: SmallVec ;
43+ use std:: cell:: OnceCell ;
4244use std:: cell:: RefCell ;
4345use std:: collections:: BTreeMap ;
4446use std:: rc:: Rc ;
@@ -333,7 +335,7 @@ fn do_mir_borrowck<'tcx>(
333335 used_mut : Default :: default ( ) ,
334336 used_mut_upvars : SmallVec :: new ( ) ,
335337 borrow_set : Rc :: clone ( & borrow_set) ,
336- dominators : Dominators :: dummy ( ) , // not used
338+ dominators : Default :: default ( ) ,
337339 upvars : Vec :: new ( ) ,
338340 local_names : IndexVec :: from_elem ( None , & promoted_body. local_decls ) ,
339341 region_names : RefCell :: default ( ) ,
@@ -346,8 +348,6 @@ fn do_mir_borrowck<'tcx>(
346348 } ;
347349 }
348350
349- let dominators = body. basic_blocks . dominators ( ) ;
350-
351351 let mut mbcx = MirBorrowckCtxt {
352352 infcx,
353353 param_env,
@@ -364,7 +364,7 @@ fn do_mir_borrowck<'tcx>(
364364 used_mut : Default :: default ( ) ,
365365 used_mut_upvars : SmallVec :: new ( ) ,
366366 borrow_set : Rc :: clone ( & borrow_set) ,
367- dominators,
367+ dominators : Default :: default ( ) ,
368368 upvars,
369369 local_names,
370370 region_names : RefCell :: default ( ) ,
@@ -534,7 +534,7 @@ struct MirBorrowckCtxt<'cx, 'tcx> {
534534 borrow_set : Rc < BorrowSet < ' tcx > > ,
535535
536536 /// Dominators for MIR
537- dominators : Dominators < BasicBlock > ,
537+ dominators : OnceCell < Dominators < BasicBlock > > ,
538538
539539 /// Information about upvars not necessarily preserved in types or MIR
540540 upvars : Vec < Upvar < ' tcx > > ,
@@ -1051,7 +1051,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
10511051
10521052 ( Read ( kind) , BorrowKind :: Unique | BorrowKind :: Mut { .. } ) => {
10531053 // Reading from mere reservations of mutable-borrows is OK.
1054- if !is_active ( & this. dominators , borrow, location) {
1054+ if !is_active ( this. dominators ( ) , borrow, location) {
10551055 assert ! ( allow_two_phase_borrow( borrow. kind) ) ;
10561056 return Control :: Continue ;
10571057 }
@@ -2219,6 +2219,10 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
22192219 fn is_upvar_field_projection ( & self , place_ref : PlaceRef < ' tcx > ) -> Option < Field > {
22202220 path_utils:: is_upvar_field_projection ( self . infcx . tcx , & self . upvars , place_ref, self . body ( ) )
22212221 }
2222+
2223+ fn dominators ( & self ) -> & Dominators < BasicBlock > {
2224+ self . dominators . get_or_init ( || self . body . basic_blocks . dominators ( ) )
2225+ }
22222226}
22232227
22242228mod error {
0 commit comments