@@ -19,7 +19,6 @@ use std::cell::RefCell;
19
19
use std:: collections:: BTreeMap ;
20
20
use std:: marker:: PhantomData ;
21
21
use std:: ops:: Deref ;
22
- use std:: rc:: Rc ;
23
22
24
23
use consumers:: { BodyWithBorrowckFacts , ConsumerOptions } ;
25
24
use rustc_data_structures:: fx:: { FxIndexMap , FxIndexSet } ;
@@ -200,8 +199,7 @@ fn do_mir_borrowck<'tcx>(
200
199
. into_results_cursor ( body) ;
201
200
202
201
let locals_are_invalidated_at_exit = tcx. hir ( ) . body_owner_kind ( def) . is_fn_or_closure ( ) ;
203
- let borrow_set =
204
- Rc :: new ( BorrowSet :: build ( tcx, body, locals_are_invalidated_at_exit, & move_data) ) ;
202
+ let borrow_set = BorrowSet :: build ( tcx, body, locals_are_invalidated_at_exit, & move_data) ;
205
203
206
204
// Compute non-lexical lifetimes.
207
205
let nll:: NllOutput {
@@ -245,8 +243,6 @@ fn do_mir_borrowck<'tcx>(
245
243
// usage significantly on some benchmarks.
246
244
drop ( flow_inits) ;
247
245
248
- let regioncx = Rc :: new ( regioncx) ;
249
-
250
246
let flow_borrows = Borrows :: new ( tcx, body, & regioncx, & borrow_set)
251
247
. into_engine ( tcx, body)
252
248
. pass_name ( "borrowck" )
@@ -288,10 +284,10 @@ fn do_mir_borrowck<'tcx>(
288
284
access_place_error_reported : Default :: default ( ) ,
289
285
reservation_error_reported : Default :: default ( ) ,
290
286
uninitialized_error_reported : Default :: default ( ) ,
291
- regioncx : regioncx. clone ( ) ,
287
+ regioncx : & regioncx,
292
288
used_mut : Default :: default ( ) ,
293
289
used_mut_upvars : SmallVec :: new ( ) ,
294
- borrow_set : Rc :: clone ( & borrow_set) ,
290
+ borrow_set : & borrow_set,
295
291
upvars : & [ ] ,
296
292
local_names : IndexVec :: from_elem ( None , & promoted_body. local_decls ) ,
297
293
region_names : RefCell :: default ( ) ,
@@ -329,10 +325,10 @@ fn do_mir_borrowck<'tcx>(
329
325
access_place_error_reported : Default :: default ( ) ,
330
326
reservation_error_reported : Default :: default ( ) ,
331
327
uninitialized_error_reported : Default :: default ( ) ,
332
- regioncx : Rc :: clone ( & regioncx) ,
328
+ regioncx : & regioncx,
333
329
used_mut : Default :: default ( ) ,
334
330
used_mut_upvars : SmallVec :: new ( ) ,
335
- borrow_set : Rc :: clone ( & borrow_set) ,
331
+ borrow_set : & borrow_set,
336
332
upvars : tcx. closure_captures ( def) ,
337
333
local_names,
338
334
region_names : RefCell :: default ( ) ,
@@ -569,10 +565,10 @@ struct MirBorrowckCtxt<'a, 'infcx, 'tcx> {
569
565
used_mut_upvars : SmallVec < [ FieldIdx ; 8 ] > ,
570
566
/// Region inference context. This contains the results from region inference and lets us e.g.
571
567
/// find out which CFG points are contained in each borrow region.
572
- regioncx : Rc < RegionInferenceContext < ' tcx > > ,
568
+ regioncx : & ' a RegionInferenceContext < ' tcx > ,
573
569
574
570
/// The set of borrows extracted from the MIR
575
- borrow_set : Rc < BorrowSet < ' tcx > > ,
571
+ borrow_set : & ' a BorrowSet < ' tcx > ,
576
572
577
573
/// Information about upvars not necessarily preserved in types or MIR
578
574
upvars : & ' tcx [ & ' tcx ty:: CapturedPlace < ' tcx > ] ,
@@ -588,7 +584,7 @@ struct MirBorrowckCtxt<'a, 'infcx, 'tcx> {
588
584
next_region_name : RefCell < usize > ,
589
585
590
586
/// Results of Polonius analysis.
591
- polonius_output : Option < Rc < PoloniusOutput > > ,
587
+ polonius_output : Option < Box < PoloniusOutput > > ,
592
588
593
589
diags : diags:: BorrowckDiags < ' infcx , ' tcx > ,
594
590
move_errors : Vec < MoveError < ' tcx > > ,
@@ -800,9 +796,8 @@ impl<'a, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'a, 'tcx, R>
800
796
TerminatorKind :: Yield { value : _, resume : _, resume_arg : _, drop : _ } => {
801
797
if self . movable_coroutine {
802
798
// Look for any active borrows to locals
803
- let borrow_set = self . borrow_set . clone ( ) ;
804
799
for i in state. borrows . iter ( ) {
805
- let borrow = & borrow_set[ i] ;
800
+ let borrow = & self . borrow_set [ i] ;
806
801
self . check_for_local_borrow ( borrow, span) ;
807
802
}
808
803
}
@@ -816,9 +811,8 @@ impl<'a, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'a, 'tcx, R>
816
811
// Often, the storage will already have been killed by an explicit
817
812
// StorageDead, but we don't always emit those (notably on unwind paths),
818
813
// so this "extra check" serves as a kind of backup.
819
- let borrow_set = self . borrow_set . clone ( ) ;
820
814
for i in state. borrows . iter ( ) {
821
- let borrow = & borrow_set[ i] ;
815
+ let borrow = & self . borrow_set [ i] ;
822
816
self . check_for_invalidation_at_exit ( loc, borrow, span) ;
823
817
}
824
818
}
@@ -1037,13 +1031,12 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
1037
1031
state : & BorrowckDomain < ' a , ' tcx > ,
1038
1032
) -> bool {
1039
1033
let mut error_reported = false ;
1040
- let borrow_set = Rc :: clone ( & self . borrow_set ) ;
1041
1034
1042
1035
// Use polonius output if it has been enabled.
1043
1036
let mut polonius_output;
1044
1037
let borrows_in_scope = if let Some ( polonius) = & self . polonius_output {
1045
1038
let location = self . location_table . start_index ( location) ;
1046
- polonius_output = BitSet :: new_empty ( borrow_set. len ( ) ) ;
1039
+ polonius_output = BitSet :: new_empty ( self . borrow_set . len ( ) ) ;
1047
1040
for & idx in polonius. errors_at ( location) {
1048
1041
polonius_output. insert ( idx) ;
1049
1042
}
@@ -1057,7 +1050,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
1057
1050
self . infcx . tcx ,
1058
1051
self . body ,
1059
1052
( sd, place_span. 0 ) ,
1060
- & borrow_set,
1053
+ self . borrow_set ,
1061
1054
|borrow_index| borrows_in_scope. contains ( borrow_index) ,
1062
1055
|this, borrow_index, borrow| match ( rw, borrow. kind ) {
1063
1056
// Obviously an activation is compatible with its own
@@ -1580,9 +1573,8 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
1580
1573
// Two-phase borrow support: For each activation that is newly
1581
1574
// generated at this statement, check if it interferes with
1582
1575
// 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] ;
1576
+ for & borrow_index in self . borrow_set . activations_at_location ( location) {
1577
+ let borrow = & self . borrow_set [ borrow_index] ;
1586
1578
1587
1579
// only mutable borrows should be 2-phase
1588
1580
assert ! ( match borrow. kind {
0 commit comments