@@ -19,7 +19,6 @@ use std::cell::RefCell;
1919use std:: collections:: BTreeMap ;
2020use std:: marker:: PhantomData ;
2121use std:: ops:: Deref ;
22- use std:: rc:: Rc ;
2322
2423use consumers:: { BodyWithBorrowckFacts , ConsumerOptions } ;
2524use rustc_data_structures:: fx:: { FxIndexMap , FxIndexSet } ;
@@ -200,8 +199,7 @@ fn do_mir_borrowck<'tcx>(
200199 . into_results_cursor ( body) ;
201200
202201 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) ;
205203
206204 // Compute non-lexical lifetimes.
207205 let nll:: NllOutput {
@@ -245,8 +243,6 @@ fn do_mir_borrowck<'tcx>(
245243 // usage significantly on some benchmarks.
246244 drop ( flow_inits) ;
247245
248- let regioncx = Rc :: new ( regioncx) ;
249-
250246 let flow_borrows = Borrows :: new ( tcx, body, & regioncx, & borrow_set)
251247 . into_engine ( tcx, body)
252248 . pass_name ( "borrowck" )
@@ -288,10 +284,10 @@ fn do_mir_borrowck<'tcx>(
288284 access_place_error_reported : Default :: default ( ) ,
289285 reservation_error_reported : Default :: default ( ) ,
290286 uninitialized_error_reported : Default :: default ( ) ,
291- regioncx : regioncx. clone ( ) ,
287+ regioncx : & regioncx,
292288 used_mut : Default :: default ( ) ,
293289 used_mut_upvars : SmallVec :: new ( ) ,
294- borrow_set : Rc :: clone ( & borrow_set) ,
290+ borrow_set : & borrow_set,
295291 upvars : & [ ] ,
296292 local_names : IndexVec :: from_elem ( None , & promoted_body. local_decls ) ,
297293 region_names : RefCell :: default ( ) ,
@@ -329,10 +325,10 @@ fn do_mir_borrowck<'tcx>(
329325 access_place_error_reported : Default :: default ( ) ,
330326 reservation_error_reported : Default :: default ( ) ,
331327 uninitialized_error_reported : Default :: default ( ) ,
332- regioncx : Rc :: clone ( & regioncx) ,
328+ regioncx : & regioncx,
333329 used_mut : Default :: default ( ) ,
334330 used_mut_upvars : SmallVec :: new ( ) ,
335- borrow_set : Rc :: clone ( & borrow_set) ,
331+ borrow_set : & borrow_set,
336332 upvars : tcx. closure_captures ( def) ,
337333 local_names,
338334 region_names : RefCell :: default ( ) ,
@@ -569,10 +565,10 @@ struct MirBorrowckCtxt<'a, 'infcx, 'tcx> {
569565 used_mut_upvars : SmallVec < [ FieldIdx ; 8 ] > ,
570566 /// Region inference context. This contains the results from region inference and lets us e.g.
571567 /// find out which CFG points are contained in each borrow region.
572- regioncx : Rc < RegionInferenceContext < ' tcx > > ,
568+ regioncx : & ' a RegionInferenceContext < ' tcx > ,
573569
574570 /// The set of borrows extracted from the MIR
575- borrow_set : Rc < BorrowSet < ' tcx > > ,
571+ borrow_set : & ' a BorrowSet < ' tcx > ,
576572
577573 /// Information about upvars not necessarily preserved in types or MIR
578574 upvars : & ' tcx [ & ' tcx ty:: CapturedPlace < ' tcx > ] ,
@@ -588,7 +584,7 @@ struct MirBorrowckCtxt<'a, 'infcx, 'tcx> {
588584 next_region_name : RefCell < usize > ,
589585
590586 /// Results of Polonius analysis.
591- polonius_output : Option < Rc < PoloniusOutput > > ,
587+ polonius_output : Option < Box < PoloniusOutput > > ,
592588
593589 diags : diags:: BorrowckDiags < ' infcx , ' tcx > ,
594590 move_errors : Vec < MoveError < ' tcx > > ,
@@ -800,9 +796,8 @@ impl<'a, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'a, 'tcx, R>
800796 TerminatorKind :: Yield { value : _, resume : _, resume_arg : _, drop : _ } => {
801797 if self . movable_coroutine {
802798 // Look for any active borrows to locals
803- let borrow_set = self . borrow_set . clone ( ) ;
804799 for i in state. borrows . iter ( ) {
805- let borrow = & borrow_set[ i] ;
800+ let borrow = & self . borrow_set [ i] ;
806801 self . check_for_local_borrow ( borrow, span) ;
807802 }
808803 }
@@ -816,9 +811,8 @@ impl<'a, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'a, 'tcx, R>
816811 // Often, the storage will already have been killed by an explicit
817812 // StorageDead, but we don't always emit those (notably on unwind paths),
818813 // so this "extra check" serves as a kind of backup.
819- let borrow_set = self . borrow_set . clone ( ) ;
820814 for i in state. borrows . iter ( ) {
821- let borrow = & borrow_set[ i] ;
815+ let borrow = & self . borrow_set [ i] ;
822816 self . check_for_invalidation_at_exit ( loc, borrow, span) ;
823817 }
824818 }
@@ -1037,13 +1031,12 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
10371031 state : & BorrowckDomain < ' a , ' tcx > ,
10381032 ) -> bool {
10391033 let mut error_reported = false ;
1040- let borrow_set = Rc :: clone ( & self . borrow_set ) ;
10411034
10421035 // Use polonius output if it has been enabled.
10431036 let mut polonius_output;
10441037 let borrows_in_scope = if let Some ( polonius) = & self . polonius_output {
10451038 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 ( ) ) ;
10471040 for & idx in polonius. errors_at ( location) {
10481041 polonius_output. insert ( idx) ;
10491042 }
@@ -1057,7 +1050,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
10571050 self . infcx . tcx ,
10581051 self . body ,
10591052 ( sd, place_span. 0 ) ,
1060- & borrow_set,
1053+ self . borrow_set ,
10611054 |borrow_index| borrows_in_scope. contains ( borrow_index) ,
10621055 |this, borrow_index, borrow| match ( rw, borrow. kind ) {
10631056 // Obviously an activation is compatible with its own
@@ -1580,9 +1573,8 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
15801573 // Two-phase borrow support: For each activation that is newly
15811574 // generated at this statement, check if it interferes with
15821575 // 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] ;
15861578
15871579 // only mutable borrows should be 2-phase
15881580 assert ! ( match borrow. kind {
0 commit comments