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