@@ -201,8 +201,7 @@ fn do_mir_borrowck<'tcx>(
201201 . into_results_cursor ( body) ;
202202
203203 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) ;
206205
207206 // Compute non-lexical lifetimes.
208207 let nll:: NllOutput {
@@ -246,8 +245,6 @@ fn do_mir_borrowck<'tcx>(
246245 // usage significantly on some benchmarks.
247246 drop ( flow_inits) ;
248247
249- let regioncx = Rc :: new ( regioncx) ;
250-
251248 let flow_borrows = Borrows :: new ( tcx, body, & regioncx, & borrow_set)
252249 . into_engine ( tcx, body)
253250 . pass_name ( "borrowck" )
@@ -289,10 +286,10 @@ fn do_mir_borrowck<'tcx>(
289286 access_place_error_reported : Default :: default ( ) ,
290287 reservation_error_reported : Default :: default ( ) ,
291288 uninitialized_error_reported : Default :: default ( ) ,
292- regioncx : regioncx. clone ( ) ,
289+ regioncx : & regioncx,
293290 used_mut : Default :: default ( ) ,
294291 used_mut_upvars : SmallVec :: new ( ) ,
295- borrow_set : Rc :: clone ( & borrow_set) ,
292+ borrow_set : & borrow_set,
296293 upvars : & [ ] ,
297294 local_names : IndexVec :: from_elem ( None , & promoted_body. local_decls ) ,
298295 region_names : RefCell :: default ( ) ,
@@ -330,10 +327,10 @@ fn do_mir_borrowck<'tcx>(
330327 access_place_error_reported : Default :: default ( ) ,
331328 reservation_error_reported : Default :: default ( ) ,
332329 uninitialized_error_reported : Default :: default ( ) ,
333- regioncx : Rc :: clone ( & regioncx) ,
330+ regioncx : & regioncx,
334331 used_mut : Default :: default ( ) ,
335332 used_mut_upvars : SmallVec :: new ( ) ,
336- borrow_set : Rc :: clone ( & borrow_set) ,
333+ borrow_set : & borrow_set,
337334 upvars : tcx. closure_captures ( def) ,
338335 local_names,
339336 region_names : RefCell :: default ( ) ,
@@ -423,8 +420,8 @@ fn do_mir_borrowck<'tcx>(
423420 Some ( Box :: new ( BodyWithBorrowckFacts {
424421 body : body_owned,
425422 promoted,
426- borrow_set,
427- region_inference_context : regioncx,
423+ borrow_set : Rc :: new ( borrow_set ) ,
424+ region_inference_context : Rc :: new ( regioncx) ,
428425 location_table : polonius_input. as_ref ( ) . map ( |_| location_table) ,
429426 input_facts : polonius_input,
430427 output_facts,
@@ -570,10 +567,10 @@ struct MirBorrowckCtxt<'a, 'infcx, 'tcx> {
570567 used_mut_upvars : SmallVec < [ FieldIdx ; 8 ] > ,
571568 /// Region inference context. This contains the results from region inference and lets us e.g.
572569 /// find out which CFG points are contained in each borrow region.
573- regioncx : Rc < RegionInferenceContext < ' tcx > > ,
570+ regioncx : & ' a RegionInferenceContext < ' tcx > ,
574571
575572 /// The set of borrows extracted from the MIR
576- borrow_set : Rc < BorrowSet < ' tcx > > ,
573+ borrow_set : & ' a BorrowSet < ' tcx > ,
577574
578575 /// Information about upvars not necessarily preserved in types or MIR
579576 upvars : & ' tcx [ & ' tcx ty:: CapturedPlace < ' tcx > ] ,
@@ -800,9 +797,8 @@ impl<'a, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'a, 'tcx, R>
800797 TerminatorKind :: Yield { value : _, resume : _, resume_arg : _, drop : _ } => {
801798 if self . movable_coroutine {
802799 // Look for any active borrows to locals
803- let borrow_set = self . borrow_set . clone ( ) ;
804800 for i in state. borrows . iter ( ) {
805- let borrow = & borrow_set[ i] ;
801+ let borrow = & self . borrow_set [ i] ;
806802 self . check_for_local_borrow ( borrow, span) ;
807803 }
808804 }
@@ -816,9 +812,8 @@ impl<'a, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'a, 'tcx, R>
816812 // Often, the storage will already have been killed by an explicit
817813 // StorageDead, but we don't always emit those (notably on unwind paths),
818814 // so this "extra check" serves as a kind of backup.
819- let borrow_set = self . borrow_set . clone ( ) ;
820815 for i in state. borrows . iter ( ) {
821- let borrow = & borrow_set[ i] ;
816+ let borrow = & self . borrow_set [ i] ;
822817 self . check_for_invalidation_at_exit ( loc, borrow, span) ;
823818 }
824819 }
@@ -1037,13 +1032,12 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
10371032 state : & BorrowckDomain < ' a , ' tcx > ,
10381033 ) -> bool {
10391034 let mut error_reported = false ;
1040- let borrow_set = Rc :: clone ( & self . borrow_set ) ;
10411035
10421036 // Use polonius output if it has been enabled.
10431037 let mut polonius_output;
10441038 let borrows_in_scope = if let Some ( polonius) = & self . polonius_output {
10451039 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 ( ) ) ;
10471041 for & idx in polonius. errors_at ( location) {
10481042 polonius_output. insert ( idx) ;
10491043 }
@@ -1057,7 +1051,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
10571051 self . infcx . tcx ,
10581052 self . body ,
10591053 ( sd, place_span. 0 ) ,
1060- & borrow_set,
1054+ self . borrow_set ,
10611055 |borrow_index| borrows_in_scope. contains ( borrow_index) ,
10621056 |this, borrow_index, borrow| match ( rw, borrow. kind ) {
10631057 // Obviously an activation is compatible with its own
@@ -1580,9 +1574,8 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
15801574 // Two-phase borrow support: For each activation that is newly
15811575 // generated at this statement, check if it interferes with
15821576 // 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] ;
15861579
15871580 // only mutable borrows should be 2-phase
15881581 assert ! ( match borrow. kind {
0 commit comments