@@ -35,7 +35,7 @@ use rustc_middle::mir::tcx::PlaceTy;
3535use rustc_middle:: mir:: * ;
3636use rustc_middle:: query:: Providers ;
3737use rustc_middle:: traits:: DefiningAnchor ;
38- use rustc_middle:: ty:: { self , CapturedPlace , ParamEnv , RegionVid , TyCtxt } ;
38+ use rustc_middle:: ty:: { self , ParamEnv , RegionVid , TyCtxt } ;
3939use rustc_session:: lint:: builtin:: UNUSED_MUT ;
4040use rustc_span:: { Span , Symbol } ;
4141use rustc_target:: abi:: FieldIdx ;
@@ -100,15 +100,6 @@ use renumber::RegionCtxt;
100100
101101fluent_messages ! { "../messages.ftl" }
102102
103- // FIXME(eddyb) perhaps move this somewhere more centrally.
104- #[ derive( Debug ) ]
105- struct Upvar < ' tcx > {
106- place : CapturedPlace < ' tcx > ,
107-
108- /// If true, the capture is behind a reference.
109- by_ref : bool ,
110- }
111-
112103/// Associate some local constants with the `'tcx` lifetime
113104struct TyCtxtConsts < ' tcx > ( TyCtxt < ' tcx > ) ;
114105impl < ' tcx > TyCtxtConsts < ' tcx > {
@@ -193,18 +184,6 @@ fn do_mir_borrowck<'tcx>(
193184 infcx. set_tainted_by_errors ( e) ;
194185 errors. set_tainted_by_errors ( e) ;
195186 }
196- let upvars: Vec < _ > = tcx
197- . closure_captures ( def)
198- . iter ( )
199- . map ( |& captured_place| {
200- let capture = captured_place. info . capture_kind ;
201- let by_ref = match capture {
202- ty:: UpvarCapture :: ByValue => false ,
203- ty:: UpvarCapture :: ByRef ( ..) => true ,
204- } ;
205- Upvar { place : captured_place. clone ( ) , by_ref }
206- } )
207- . collect ( ) ;
208187
209188 // Replace all regions with fresh inference variables. This
210189 // requires first making our own copy of the MIR. This copy will
@@ -254,7 +233,7 @@ fn do_mir_borrowck<'tcx>(
254233 & mut flow_inits,
255234 & mdpe. move_data ,
256235 & borrow_set,
257- & upvars ,
236+ tcx . closure_captures ( def ) ,
258237 consumer_options,
259238 ) ;
260239
@@ -324,7 +303,7 @@ fn do_mir_borrowck<'tcx>(
324303 used_mut : Default :: default ( ) ,
325304 used_mut_upvars : SmallVec :: new ( ) ,
326305 borrow_set : Rc :: clone ( & borrow_set) ,
327- upvars : Vec :: new ( ) ,
306+ upvars : & [ ] ,
328307 local_names : IndexVec :: from_elem ( None , & promoted_body. local_decls ) ,
329308 region_names : RefCell :: default ( ) ,
330309 next_region_name : RefCell :: new ( 1 ) ,
@@ -365,7 +344,7 @@ fn do_mir_borrowck<'tcx>(
365344 used_mut : Default :: default ( ) ,
366345 used_mut_upvars : SmallVec :: new ( ) ,
367346 borrow_set : Rc :: clone ( & borrow_set) ,
368- upvars,
347+ upvars : tcx . closure_captures ( def ) ,
369348 local_names,
370349 region_names : RefCell :: default ( ) ,
371350 next_region_name : RefCell :: new ( 1 ) ,
@@ -584,7 +563,7 @@ struct MirBorrowckCtxt<'cx, 'tcx> {
584563 borrow_set : Rc < BorrowSet < ' tcx > > ,
585564
586565 /// Information about upvars not necessarily preserved in types or MIR
587- upvars : Vec < Upvar < ' tcx > > ,
566+ upvars : & ' tcx [ & ' tcx ty :: CapturedPlace < ' tcx > ] ,
588567
589568 /// Names of local (user) variables (extracted from `var_debug_info`).
590569 local_names : IndexVec < Local , Option < Symbol > > ,
@@ -2294,7 +2273,9 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
22942273 // unique path to the `&mut`
22952274 hir:: Mutability :: Mut => {
22962275 let mode = match self . is_upvar_field_projection ( place) {
2297- Some ( field) if self . upvars [ field. index ( ) ] . by_ref => {
2276+ Some ( field)
2277+ if self . upvars [ field. index ( ) ] . is_by_ref ( ) =>
2278+ {
22982279 is_local_mutation_allowed
22992280 }
23002281 _ => LocalMutationIsAllowed :: Yes ,
@@ -2342,7 +2323,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
23422323 place={:?}, place_base={:?}",
23432324 upvar, is_local_mutation_allowed, place, place_base
23442325 ) ;
2345- match ( upvar. place . mutability , is_local_mutation_allowed) {
2326+ match ( upvar. mutability , is_local_mutation_allowed) {
23462327 (
23472328 Mutability :: Not ,
23482329 LocalMutationIsAllowed :: No
0 commit comments