@@ -5,11 +5,10 @@ use rustc_data_structures::graph::dominators::Dominators;
5
5
use rustc_errors:: { Applicability , Diagnostic , DiagnosticBuilder , ErrorReported } ;
6
6
use rustc_hir as hir;
7
7
use rustc_hir:: def_id:: LocalDefId ;
8
- use rustc_hir:: { HirId , Node } ;
8
+ use rustc_hir:: Node ;
9
9
use rustc_index:: bit_set:: BitSet ;
10
10
use rustc_index:: vec:: IndexVec ;
11
11
use rustc_infer:: infer:: { InferCtxt , TyCtxtInferExt } ;
12
- use rustc_middle:: hir:: place:: PlaceBase as HirPlaceBase ;
13
12
use rustc_middle:: mir:: {
14
13
traversal, Body , ClearCrossCrate , Local , Location , Mutability , Operand , Place , PlaceElem ,
15
14
PlaceRef , VarDebugInfoContents ,
@@ -18,7 +17,7 @@ use rustc_middle::mir::{AggregateKind, BasicBlock, BorrowCheckResult, BorrowKind
18
17
use rustc_middle:: mir:: { Field , ProjectionElem , Promoted , Rvalue , Statement , StatementKind } ;
19
18
use rustc_middle:: mir:: { InlineAsmOperand , Terminator , TerminatorKind } ;
20
19
use rustc_middle:: ty:: query:: Providers ;
21
- use rustc_middle:: ty:: { self , ParamEnv , RegionVid , TyCtxt } ;
20
+ use rustc_middle:: ty:: { self , CapturedPlace , ParamEnv , RegionVid , TyCtxt } ;
22
21
use rustc_session:: lint:: builtin:: { MUTABLE_BORROW_RESERVATION_CONFLICT , UNUSED_MUT } ;
23
22
use rustc_span:: { Span , Symbol , DUMMY_SP } ;
24
23
@@ -73,16 +72,15 @@ crate use region_infer::RegionInferenceContext;
73
72
74
73
// FIXME(eddyb) perhaps move this somewhere more centrally.
75
74
#[ derive( Debug ) ]
76
- crate struct Upvar {
75
+ crate struct Upvar < ' tcx > {
76
+ // FIXME(project-rfc-2229#8): ty::CapturePlace should have a to_string(), or similar
77
+ // then this should not be needed.
77
78
name : Symbol ,
78
79
79
- // FIXME(project-rfc-2229#8): This should use Place or something similar
80
- var_hir_id : HirId ,
80
+ place : CapturedPlace < ' tcx > ,
81
81
82
82
/// If true, the capture is behind a reference.
83
83
by_ref : bool ,
84
-
85
- mutability : Mutability ,
86
84
}
87
85
88
86
const DEREF_PROJECTION : & [ PlaceElem < ' _ > ; 1 ] = & [ ProjectionElem :: Deref ] ;
@@ -161,21 +159,13 @@ fn do_mir_borrowck<'a, 'tcx>(
161
159
let upvars: Vec < _ > = tables
162
160
. closure_min_captures_flattened ( def. did . to_def_id ( ) )
163
161
. map ( |captured_place| {
164
- let var_hir_id = match captured_place. place . base {
165
- HirPlaceBase :: Upvar ( upvar_id) => upvar_id. var_path . hir_id ,
166
- _ => bug ! ( "Expected upvar" ) ,
167
- } ;
162
+ let var_hir_id = captured_place. get_root_variable ( ) ;
168
163
let capture = captured_place. info . capture_kind ;
169
164
let by_ref = match capture {
170
165
ty:: UpvarCapture :: ByValue ( _) => false ,
171
166
ty:: UpvarCapture :: ByRef ( ..) => true ,
172
167
} ;
173
- Upvar {
174
- name : tcx. hir ( ) . name ( var_hir_id) ,
175
- var_hir_id,
176
- by_ref,
177
- mutability : captured_place. mutability ,
178
- }
168
+ Upvar { name : tcx. hir ( ) . name ( var_hir_id) , place : captured_place. clone ( ) , by_ref }
179
169
} )
180
170
. collect ( ) ;
181
171
@@ -544,7 +534,7 @@ crate struct MirBorrowckCtxt<'cx, 'tcx> {
544
534
dominators : Dominators < BasicBlock > ,
545
535
546
536
/// Information about upvars not necessarily preserved in types or MIR
547
- upvars : Vec < Upvar > ,
537
+ upvars : Vec < Upvar < ' tcx > > ,
548
538
549
539
/// Names of local (user) variables (extracted from `var_debug_info`).
550
540
local_names : IndexVec < Local , Option < Symbol > > ,
@@ -2251,7 +2241,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
2251
2241
place={:?}",
2252
2242
upvar, is_local_mutation_allowed, place
2253
2243
) ;
2254
- match ( upvar. mutability , is_local_mutation_allowed) {
2244
+ match ( upvar. place . mutability , is_local_mutation_allowed) {
2255
2245
(
2256
2246
Mutability :: Not ,
2257
2247
LocalMutationIsAllowed :: No
0 commit comments