@@ -34,7 +34,7 @@ use rustc_middle::mir::tcx::PlaceTy;
3434use rustc_middle:: mir:: * ;
3535use rustc_middle:: query:: Providers ;
3636use rustc_middle:: traits:: DefiningAnchor ;
37- use rustc_middle:: ty:: { self , CapturedPlace , ParamEnv , RegionVid , TyCtxt } ;
37+ use rustc_middle:: ty:: { self , ParamEnv , RegionVid , TyCtxt } ;
3838use rustc_session:: lint:: builtin:: UNUSED_MUT ;
3939use rustc_span:: { Span , Symbol } ;
4040use rustc_target:: abi:: FieldIdx ;
@@ -99,15 +99,6 @@ use renumber::RegionCtxt;
9999
100100rustc_fluent_macro:: fluent_messages! { "../messages.ftl" }
101101
102- // FIXME(eddyb) perhaps move this somewhere more centrally.
103- #[ derive( Debug ) ]
104- struct Upvar < ' tcx > {
105- place : CapturedPlace < ' tcx > ,
106-
107- /// If true, the capture is behind a reference.
108- by_ref : bool ,
109- }
110-
111102/// Associate some local constants with the `'tcx` lifetime
112103struct TyCtxtConsts < ' tcx > ( TyCtxt < ' tcx > ) ;
113104impl < ' tcx > TyCtxtConsts < ' tcx > {
@@ -192,18 +183,6 @@ fn do_mir_borrowck<'tcx>(
192183 infcx. set_tainted_by_errors ( e) ;
193184 errors. set_tainted_by_errors ( e) ;
194185 }
195- let upvars: Vec < _ > = tcx
196- . closure_captures ( def)
197- . iter ( )
198- . map ( |& captured_place| {
199- let capture = captured_place. info . capture_kind ;
200- let by_ref = match capture {
201- ty:: UpvarCapture :: ByValue => false ,
202- ty:: UpvarCapture :: ByRef ( ..) => true ,
203- } ;
204- Upvar { place : captured_place. clone ( ) , by_ref }
205- } )
206- . collect ( ) ;
207186
208187 // Replace all regions with fresh inference variables. This
209188 // requires first making our own copy of the MIR. This copy will
@@ -253,7 +232,7 @@ fn do_mir_borrowck<'tcx>(
253232 & mut flow_inits,
254233 & mdpe. move_data ,
255234 & borrow_set,
256- & upvars ,
235+ tcx . closure_captures ( def ) ,
257236 consumer_options,
258237 ) ;
259238
@@ -323,7 +302,7 @@ fn do_mir_borrowck<'tcx>(
323302 used_mut : Default :: default ( ) ,
324303 used_mut_upvars : SmallVec :: new ( ) ,
325304 borrow_set : Rc :: clone ( & borrow_set) ,
326- upvars : Vec :: new ( ) ,
305+ upvars : & [ ] ,
327306 local_names : IndexVec :: from_elem ( None , & promoted_body. local_decls ) ,
328307 region_names : RefCell :: default ( ) ,
329308 next_region_name : RefCell :: new ( 1 ) ,
@@ -364,7 +343,7 @@ fn do_mir_borrowck<'tcx>(
364343 used_mut : Default :: default ( ) ,
365344 used_mut_upvars : SmallVec :: new ( ) ,
366345 borrow_set : Rc :: clone ( & borrow_set) ,
367- upvars,
346+ upvars : tcx . closure_captures ( def ) ,
368347 local_names,
369348 region_names : RefCell :: default ( ) ,
370349 next_region_name : RefCell :: new ( 1 ) ,
@@ -583,7 +562,7 @@ struct MirBorrowckCtxt<'cx, 'tcx> {
583562 borrow_set : Rc < BorrowSet < ' tcx > > ,
584563
585564 /// Information about upvars not necessarily preserved in types or MIR
586- upvars : Vec < Upvar < ' tcx > > ,
565+ upvars : & ' tcx [ & ' tcx ty :: CapturedPlace < ' tcx > ] ,
587566
588567 /// Names of local (user) variables (extracted from `var_debug_info`).
589568 local_names : IndexVec < Local , Option < Symbol > > ,
@@ -2293,7 +2272,9 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
22932272 // unique path to the `&mut`
22942273 hir:: Mutability :: Mut => {
22952274 let mode = match self . is_upvar_field_projection ( place) {
2296- Some ( field) if self . upvars [ field. index ( ) ] . by_ref => {
2275+ Some ( field)
2276+ if self . upvars [ field. index ( ) ] . is_by_ref ( ) =>
2277+ {
22972278 is_local_mutation_allowed
22982279 }
22992280 _ => LocalMutationIsAllowed :: Yes ,
@@ -2341,7 +2322,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
23412322 place={:?}, place_base={:?}",
23422323 upvar, is_local_mutation_allowed, place, place_base
23432324 ) ;
2344- match ( upvar. place . mutability , is_local_mutation_allowed) {
2325+ match ( upvar. mutability , is_local_mutation_allowed) {
23452326 (
23462327 Mutability :: Not ,
23472328 LocalMutationIsAllowed :: No
0 commit comments