5
5
#![ feature( let_chains) ]
6
6
#![ feature( min_specialization) ]
7
7
#![ feature( never_type) ]
8
+ #![ feature( once_cell) ]
8
9
#![ feature( rustc_attrs) ]
9
10
#![ feature( stmt_expr_attributes) ]
10
11
#![ feature( trusted_step) ]
@@ -39,6 +40,7 @@ use rustc_span::{Span, Symbol};
39
40
40
41
use either:: Either ;
41
42
use smallvec:: SmallVec ;
43
+ use std:: cell:: OnceCell ;
42
44
use std:: cell:: RefCell ;
43
45
use std:: collections:: BTreeMap ;
44
46
use std:: rc:: Rc ;
@@ -333,7 +335,7 @@ fn do_mir_borrowck<'tcx>(
333
335
used_mut : Default :: default ( ) ,
334
336
used_mut_upvars : SmallVec :: new ( ) ,
335
337
borrow_set : Rc :: clone ( & borrow_set) ,
336
- dominators : Dominators :: dummy ( ) , // not used
338
+ dominators : Default :: default ( ) ,
337
339
upvars : Vec :: new ( ) ,
338
340
local_names : IndexVec :: from_elem ( None , & promoted_body. local_decls ) ,
339
341
region_names : RefCell :: default ( ) ,
@@ -346,8 +348,6 @@ fn do_mir_borrowck<'tcx>(
346
348
} ;
347
349
}
348
350
349
- let dominators = body. basic_blocks . dominators ( ) ;
350
-
351
351
let mut mbcx = MirBorrowckCtxt {
352
352
infcx,
353
353
param_env,
@@ -364,7 +364,7 @@ fn do_mir_borrowck<'tcx>(
364
364
used_mut : Default :: default ( ) ,
365
365
used_mut_upvars : SmallVec :: new ( ) ,
366
366
borrow_set : Rc :: clone ( & borrow_set) ,
367
- dominators,
367
+ dominators : Default :: default ( ) ,
368
368
upvars,
369
369
local_names,
370
370
region_names : RefCell :: default ( ) ,
@@ -534,7 +534,7 @@ struct MirBorrowckCtxt<'cx, 'tcx> {
534
534
borrow_set : Rc < BorrowSet < ' tcx > > ,
535
535
536
536
/// Dominators for MIR
537
- dominators : Dominators < BasicBlock > ,
537
+ dominators : OnceCell < Dominators < BasicBlock > > ,
538
538
539
539
/// Information about upvars not necessarily preserved in types or MIR
540
540
upvars : Vec < Upvar < ' tcx > > ,
@@ -1051,7 +1051,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
1051
1051
1052
1052
( Read ( kind) , BorrowKind :: Unique | BorrowKind :: Mut { .. } ) => {
1053
1053
// 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) {
1055
1055
assert ! ( allow_two_phase_borrow( borrow. kind) ) ;
1056
1056
return Control :: Continue ;
1057
1057
}
@@ -2219,6 +2219,10 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
2219
2219
fn is_upvar_field_projection ( & self , place_ref : PlaceRef < ' tcx > ) -> Option < Field > {
2220
2220
path_utils:: is_upvar_field_projection ( self . infcx . tcx , & self . upvars , place_ref, self . body ( ) )
2221
2221
}
2222
+
2223
+ fn dominators ( & self ) -> & Dominators < BasicBlock > {
2224
+ self . dominators . get_or_init ( || self . body . basic_blocks . dominators ( ) )
2225
+ }
2222
2226
}
2223
2227
2224
2228
mod error {
0 commit comments