@@ -35,7 +35,7 @@ use rustc_middle::mir::tcx::PlaceTy;
35
35
use rustc_middle:: mir:: * ;
36
36
use rustc_middle:: query:: Providers ;
37
37
use rustc_middle:: traits:: DefiningAnchor ;
38
- use rustc_middle:: ty:: { self , CapturedPlace , ParamEnv , RegionVid , TyCtxt } ;
38
+ use rustc_middle:: ty:: { self , ParamEnv , RegionVid , TyCtxt } ;
39
39
use rustc_session:: lint:: builtin:: UNUSED_MUT ;
40
40
use rustc_span:: { Span , Symbol } ;
41
41
use rustc_target:: abi:: FieldIdx ;
@@ -100,15 +100,6 @@ use renumber::RegionCtxt;
100
100
101
101
fluent_messages ! { "../messages.ftl" }
102
102
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
-
112
103
/// Associate some local constants with the `'tcx` lifetime
113
104
struct TyCtxtConsts < ' tcx > ( TyCtxt < ' tcx > ) ;
114
105
impl < ' tcx > TyCtxtConsts < ' tcx > {
@@ -193,18 +184,6 @@ fn do_mir_borrowck<'tcx>(
193
184
infcx. set_tainted_by_errors ( e) ;
194
185
errors. set_tainted_by_errors ( e) ;
195
186
}
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 ( ) ;
208
187
209
188
// Replace all regions with fresh inference variables. This
210
189
// requires first making our own copy of the MIR. This copy will
@@ -254,7 +233,7 @@ fn do_mir_borrowck<'tcx>(
254
233
& mut flow_inits,
255
234
& mdpe. move_data ,
256
235
& borrow_set,
257
- & upvars ,
236
+ tcx . closure_captures ( def ) ,
258
237
consumer_options,
259
238
) ;
260
239
@@ -324,7 +303,7 @@ fn do_mir_borrowck<'tcx>(
324
303
used_mut : Default :: default ( ) ,
325
304
used_mut_upvars : SmallVec :: new ( ) ,
326
305
borrow_set : Rc :: clone ( & borrow_set) ,
327
- upvars : Vec :: new ( ) ,
306
+ upvars : & [ ] ,
328
307
local_names : IndexVec :: from_elem ( None , & promoted_body. local_decls ) ,
329
308
region_names : RefCell :: default ( ) ,
330
309
next_region_name : RefCell :: new ( 1 ) ,
@@ -365,7 +344,7 @@ fn do_mir_borrowck<'tcx>(
365
344
used_mut : Default :: default ( ) ,
366
345
used_mut_upvars : SmallVec :: new ( ) ,
367
346
borrow_set : Rc :: clone ( & borrow_set) ,
368
- upvars,
347
+ upvars : tcx . closure_captures ( def ) ,
369
348
local_names,
370
349
region_names : RefCell :: default ( ) ,
371
350
next_region_name : RefCell :: new ( 1 ) ,
@@ -584,7 +563,7 @@ struct MirBorrowckCtxt<'cx, 'tcx> {
584
563
borrow_set : Rc < BorrowSet < ' tcx > > ,
585
564
586
565
/// Information about upvars not necessarily preserved in types or MIR
587
- upvars : Vec < Upvar < ' tcx > > ,
566
+ upvars : & ' tcx [ & ' tcx ty :: CapturedPlace < ' tcx > ] ,
588
567
589
568
/// Names of local (user) variables (extracted from `var_debug_info`).
590
569
local_names : IndexVec < Local , Option < Symbol > > ,
@@ -2294,7 +2273,9 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
2294
2273
// unique path to the `&mut`
2295
2274
hir:: Mutability :: Mut => {
2296
2275
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
+ {
2298
2279
is_local_mutation_allowed
2299
2280
}
2300
2281
_ => LocalMutationIsAllowed :: Yes ,
@@ -2342,7 +2323,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
2342
2323
place={:?}, place_base={:?}",
2343
2324
upvar, is_local_mutation_allowed, place, place_base
2344
2325
) ;
2345
- match ( upvar. place . mutability , is_local_mutation_allowed) {
2326
+ match ( upvar. mutability , is_local_mutation_allowed) {
2346
2327
(
2347
2328
Mutability :: Not ,
2348
2329
LocalMutationIsAllowed :: No
0 commit comments