@@ -5,11 +5,10 @@ use rustc_data_structures::graph::dominators::Dominators;
55use rustc_errors:: { Applicability , Diagnostic , DiagnosticBuilder , ErrorReported } ;
66use rustc_hir as hir;
77use rustc_hir:: def_id:: LocalDefId ;
8- use rustc_hir:: { HirId , Node } ;
8+ use rustc_hir:: Node ;
99use rustc_index:: bit_set:: BitSet ;
1010use rustc_index:: vec:: IndexVec ;
1111use rustc_infer:: infer:: { InferCtxt , TyCtxtInferExt } ;
12- use rustc_middle:: hir:: place:: PlaceBase as HirPlaceBase ;
1312use rustc_middle:: mir:: {
1413 traversal, Body , ClearCrossCrate , Local , Location , Mutability , Operand , Place , PlaceElem ,
1514 PlaceRef , VarDebugInfoContents ,
@@ -18,7 +17,7 @@ use rustc_middle::mir::{AggregateKind, BasicBlock, BorrowCheckResult, BorrowKind
1817use rustc_middle:: mir:: { Field , ProjectionElem , Promoted , Rvalue , Statement , StatementKind } ;
1918use rustc_middle:: mir:: { InlineAsmOperand , Terminator , TerminatorKind } ;
2019use rustc_middle:: ty:: query:: Providers ;
21- use rustc_middle:: ty:: { self , ParamEnv , RegionVid , TyCtxt } ;
20+ use rustc_middle:: ty:: { self , CapturedPlace , ParamEnv , RegionVid , TyCtxt } ;
2221use rustc_session:: lint:: builtin:: { MUTABLE_BORROW_RESERVATION_CONFLICT , UNUSED_MUT } ;
2322use rustc_span:: { Span , Symbol , DUMMY_SP } ;
2423
@@ -73,16 +72,15 @@ crate use region_infer::RegionInferenceContext;
7372
7473// FIXME(eddyb) perhaps move this somewhere more centrally.
7574#[ 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.
7778 name : Symbol ,
7879
79- // FIXME(project-rfc-2229#8): This should use Place or something similar
80- var_hir_id : HirId ,
80+ place : CapturedPlace < ' tcx > ,
8181
8282 /// If true, the capture is behind a reference.
8383 by_ref : bool ,
84-
85- mutability : Mutability ,
8684}
8785
8886const DEREF_PROJECTION : & [ PlaceElem < ' _ > ; 1 ] = & [ ProjectionElem :: Deref ] ;
@@ -161,21 +159,13 @@ fn do_mir_borrowck<'a, 'tcx>(
161159 let upvars: Vec < _ > = tables
162160 . closure_min_captures_flattened ( def. did . to_def_id ( ) )
163161 . 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 ( ) ;
168163 let capture = captured_place. info . capture_kind ;
169164 let by_ref = match capture {
170165 ty:: UpvarCapture :: ByValue ( _) => false ,
171166 ty:: UpvarCapture :: ByRef ( ..) => true ,
172167 } ;
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 }
179169 } )
180170 . collect ( ) ;
181171
@@ -544,7 +534,7 @@ crate struct MirBorrowckCtxt<'cx, 'tcx> {
544534 dominators : Dominators < BasicBlock > ,
545535
546536 /// Information about upvars not necessarily preserved in types or MIR
547- upvars : Vec < Upvar > ,
537+ upvars : Vec < Upvar < ' tcx > > ,
548538
549539 /// Names of local (user) variables (extracted from `var_debug_info`).
550540 local_names : IndexVec < Local , Option < Symbol > > ,
@@ -2251,7 +2241,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
22512241 place={:?}",
22522242 upvar, is_local_mutation_allowed, place
22532243 ) ;
2254- match ( upvar. mutability , is_local_mutation_allowed) {
2244+ match ( upvar. place . mutability , is_local_mutation_allowed) {
22552245 (
22562246 Mutability :: Not ,
22572247 LocalMutationIsAllowed :: No
0 commit comments