@@ -201,8 +201,7 @@ fn do_mir_borrowck<'tcx>(
201
201
. into_results_cursor ( body) ;
202
202
203
203
let locals_are_invalidated_at_exit = tcx. hir ( ) . body_owner_kind ( def) . is_fn_or_closure ( ) ;
204
- let borrow_set =
205
- Rc :: new ( BorrowSet :: build ( tcx, body, locals_are_invalidated_at_exit, & move_data) ) ;
204
+ let borrow_set = BorrowSet :: build ( tcx, body, locals_are_invalidated_at_exit, & move_data) ;
206
205
207
206
// Compute non-lexical lifetimes.
208
207
let nll:: NllOutput {
@@ -246,8 +245,6 @@ fn do_mir_borrowck<'tcx>(
246
245
// usage significantly on some benchmarks.
247
246
drop ( flow_inits) ;
248
247
249
- let regioncx = Rc :: new ( regioncx) ;
250
-
251
248
let flow_borrows = Borrows :: new ( tcx, body, & regioncx, & borrow_set)
252
249
. into_engine ( tcx, body)
253
250
. pass_name ( "borrowck" )
@@ -289,10 +286,10 @@ fn do_mir_borrowck<'tcx>(
289
286
access_place_error_reported : Default :: default ( ) ,
290
287
reservation_error_reported : Default :: default ( ) ,
291
288
uninitialized_error_reported : Default :: default ( ) ,
292
- regioncx : regioncx. clone ( ) ,
289
+ regioncx : & regioncx,
293
290
used_mut : Default :: default ( ) ,
294
291
used_mut_upvars : SmallVec :: new ( ) ,
295
- borrow_set : Rc :: clone ( & borrow_set) ,
292
+ borrow_set : & borrow_set,
296
293
upvars : & [ ] ,
297
294
local_names : IndexVec :: from_elem ( None , & promoted_body. local_decls ) ,
298
295
region_names : RefCell :: default ( ) ,
@@ -330,10 +327,10 @@ fn do_mir_borrowck<'tcx>(
330
327
access_place_error_reported : Default :: default ( ) ,
331
328
reservation_error_reported : Default :: default ( ) ,
332
329
uninitialized_error_reported : Default :: default ( ) ,
333
- regioncx : Rc :: clone ( & regioncx) ,
330
+ regioncx : & regioncx,
334
331
used_mut : Default :: default ( ) ,
335
332
used_mut_upvars : SmallVec :: new ( ) ,
336
- borrow_set : Rc :: clone ( & borrow_set) ,
333
+ borrow_set : & borrow_set,
337
334
upvars : tcx. closure_captures ( def) ,
338
335
local_names,
339
336
region_names : RefCell :: default ( ) ,
@@ -423,8 +420,8 @@ fn do_mir_borrowck<'tcx>(
423
420
Some ( Box :: new ( BodyWithBorrowckFacts {
424
421
body : body_owned,
425
422
promoted,
426
- borrow_set,
427
- region_inference_context : regioncx,
423
+ borrow_set : Rc :: new ( borrow_set ) ,
424
+ region_inference_context : Rc :: new ( regioncx) ,
428
425
location_table : polonius_input. as_ref ( ) . map ( |_| location_table) ,
429
426
input_facts : polonius_input,
430
427
output_facts,
@@ -570,10 +567,10 @@ struct MirBorrowckCtxt<'a, 'infcx, 'tcx> {
570
567
used_mut_upvars : SmallVec < [ FieldIdx ; 8 ] > ,
571
568
/// Region inference context. This contains the results from region inference and lets us e.g.
572
569
/// find out which CFG points are contained in each borrow region.
573
- regioncx : Rc < RegionInferenceContext < ' tcx > > ,
570
+ regioncx : & ' a RegionInferenceContext < ' tcx > ,
574
571
575
572
/// The set of borrows extracted from the MIR
576
- borrow_set : Rc < BorrowSet < ' tcx > > ,
573
+ borrow_set : & ' a BorrowSet < ' tcx > ,
577
574
578
575
/// Information about upvars not necessarily preserved in types or MIR
579
576
upvars : & ' tcx [ & ' tcx ty:: CapturedPlace < ' tcx > ] ,
@@ -800,9 +797,8 @@ impl<'a, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'a, 'tcx, R>
800
797
TerminatorKind :: Yield { value : _, resume : _, resume_arg : _, drop : _ } => {
801
798
if self . movable_coroutine {
802
799
// Look for any active borrows to locals
803
- let borrow_set = self . borrow_set . clone ( ) ;
804
800
for i in state. borrows . iter ( ) {
805
- let borrow = & borrow_set[ i] ;
801
+ let borrow = & self . borrow_set [ i] ;
806
802
self . check_for_local_borrow ( borrow, span) ;
807
803
}
808
804
}
@@ -816,9 +812,8 @@ impl<'a, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'a, 'tcx, R>
816
812
// Often, the storage will already have been killed by an explicit
817
813
// StorageDead, but we don't always emit those (notably on unwind paths),
818
814
// so this "extra check" serves as a kind of backup.
819
- let borrow_set = self . borrow_set . clone ( ) ;
820
815
for i in state. borrows . iter ( ) {
821
- let borrow = & borrow_set[ i] ;
816
+ let borrow = & self . borrow_set [ i] ;
822
817
self . check_for_invalidation_at_exit ( loc, borrow, span) ;
823
818
}
824
819
}
@@ -1037,13 +1032,12 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
1037
1032
state : & BorrowckDomain < ' a , ' tcx > ,
1038
1033
) -> bool {
1039
1034
let mut error_reported = false ;
1040
- let borrow_set = Rc :: clone ( & self . borrow_set ) ;
1041
1035
1042
1036
// Use polonius output if it has been enabled.
1043
1037
let mut polonius_output;
1044
1038
let borrows_in_scope = if let Some ( polonius) = & self . polonius_output {
1045
1039
let location = self . location_table . start_index ( location) ;
1046
- polonius_output = BitSet :: new_empty ( borrow_set. len ( ) ) ;
1040
+ polonius_output = BitSet :: new_empty ( self . borrow_set . len ( ) ) ;
1047
1041
for & idx in polonius. errors_at ( location) {
1048
1042
polonius_output. insert ( idx) ;
1049
1043
}
@@ -1057,7 +1051,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
1057
1051
self . infcx . tcx ,
1058
1052
self . body ,
1059
1053
( sd, place_span. 0 ) ,
1060
- & borrow_set,
1054
+ self . borrow_set ,
1061
1055
|borrow_index| borrows_in_scope. contains ( borrow_index) ,
1062
1056
|this, borrow_index, borrow| match ( rw, borrow. kind ) {
1063
1057
// Obviously an activation is compatible with its own
@@ -1580,9 +1574,8 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
1580
1574
// Two-phase borrow support: For each activation that is newly
1581
1575
// generated at this statement, check if it interferes with
1582
1576
// another borrow.
1583
- let borrow_set = self . borrow_set . clone ( ) ;
1584
- for & borrow_index in borrow_set. activations_at_location ( location) {
1585
- let borrow = & borrow_set[ borrow_index] ;
1577
+ for & borrow_index in self . borrow_set . activations_at_location ( location) {
1578
+ let borrow = & self . borrow_set [ borrow_index] ;
1586
1579
1587
1580
// only mutable borrows should be 2-phase
1588
1581
assert ! ( match borrow. kind {
0 commit comments