@@ -6,8 +6,8 @@ use crate::build::{BlockAnd, BlockAndExtension, Builder};
6
6
use crate :: thir:: * ;
7
7
use rustc_hir:: def_id:: DefId ;
8
8
use rustc_hir:: HirId ;
9
- use rustc_middle:: middle:: region;
10
9
use rustc_middle:: hir:: place:: ProjectionKind as HirProjectionKind ;
10
+ use rustc_middle:: middle:: region;
11
11
use rustc_middle:: mir:: AssertKind :: BoundsCheck ;
12
12
use rustc_middle:: mir:: * ;
13
13
use rustc_middle:: ty:: { self , CanonicalUserTypeAnnotation , Ty , TyCtxt , Variance } ;
@@ -57,7 +57,8 @@ crate enum PlaceBase {
57
57
/// DefId of the closure
58
58
closure_def_id : DefId ,
59
59
/// The trait closure implements, `Fn`, `FnMut`, `FnOnce`
60
- closure_kind : ty:: ClosureKind } ,
60
+ closure_kind : ty:: ClosureKind ,
61
+ } ,
61
62
}
62
63
63
64
/// `PlaceBuilder` is used to create places during MIR construction. It allows you to "build up" a
@@ -81,8 +82,7 @@ crate struct PlaceBuilder<'tcx> {
81
82
fn convert_to_hir_projections_and_truncate_for_capture < ' tcx > (
82
83
mir_projections : & [ PlaceElem < ' tcx > ] ,
83
84
) -> Vec < HirProjectionKind > {
84
-
85
- let mut hir_projections = Vec :: new ( ) ;
85
+ let mut hir_projections = Vec :: new ( ) ;
86
86
87
87
for mir_projection in mir_projections {
88
88
let hir_projection = match mir_projection {
@@ -91,20 +91,20 @@ fn convert_to_hir_projections_and_truncate_for_capture<'tcx>(
91
91
// We will never encouter this for multivariant enums,
92
92
// read the comment for `Downcast`.
93
93
HirProjectionKind :: Field ( field. index ( ) as u32 , VariantIdx :: new ( 0 ) )
94
- } ,
94
+ }
95
95
ProjectionElem :: Downcast ( ..) => {
96
96
// This projections exist only for enums that have
97
97
// multiple variants. Since such enums that are captured
98
98
// completely, we can stop here.
99
- break
100
- } ,
99
+ break ;
100
+ }
101
101
ProjectionElem :: Index ( ..)
102
102
| ProjectionElem :: ConstantIndex { .. }
103
103
| ProjectionElem :: Subslice { .. } => {
104
104
// We don't capture array-access projections.
105
105
// We can stop here as arrays are captured completely.
106
- break
107
- } ,
106
+ break ;
107
+ }
108
108
} ;
109
109
110
110
hir_projections. push ( hir_projection) ;
@@ -181,9 +181,9 @@ fn find_capture_matching_projections<'a, 'tcx>(
181
181
// If an ancestor is found, `idx` is the index within the list of captured places
182
182
// for root variable `var_hir_id` and `capture` is the `ty::CapturedPlace` itself.
183
183
let ( idx, capture) = root_variable_min_captures. iter ( ) . enumerate ( ) . find ( |( _, capture) | {
184
- let possible_ancestor_proj_kinds =
185
- capture. place . projections . iter ( ) . map ( |proj| proj. kind ) . collect ( ) ;
186
- is_ancestor_or_same_capture ( & possible_ancestor_proj_kinds, & hir_projections)
184
+ let possible_ancestor_proj_kinds =
185
+ capture. place . projections . iter ( ) . map ( |proj| proj. kind ) . collect ( ) ;
186
+ is_ancestor_or_same_capture ( & possible_ancestor_proj_kinds, & hir_projections)
187
187
} ) ?;
188
188
189
189
// Convert index to be from the presepective of the entire closure_min_captures map
@@ -213,35 +213,34 @@ fn to_upvars_resolved_place_builder<'a, 'tcx>(
213
213
ty:: ClosureKind :: FnOnce => { }
214
214
}
215
215
216
- let ( capture_index, capture) =
217
- if let Some ( capture_details ) = find_capture_matching_projections (
216
+ let ( capture_index, capture) = if let Some ( capture_details ) =
217
+ find_capture_matching_projections (
218
218
typeck_results,
219
219
var_hir_id,
220
220
closure_def_id,
221
221
& from_builder. projection ,
222
222
) {
223
- capture_details
224
- } else {
225
- if !tcx. features ( ) . capture_disjoint_fields {
226
- bug ! (
227
- "No associated capture found for {:?}[{:#?}] even though \
223
+ capture_details
224
+ } else {
225
+ if !tcx. features ( ) . capture_disjoint_fields {
226
+ bug ! (
227
+ "No associated capture found for {:?}[{:#?}] even though \
228
228
capture_disjoint_fields isn't enabled",
229
- var_hir_id,
230
- from_builder. projection
231
- )
232
- } else {
233
- // FIXME(project-rfc-2229#24): Handle this case properly
234
- debug ! (
235
- "No associated capture found for {:?}[{:#?}]" ,
236
- var_hir_id,
237
- from_builder. projection,
238
- ) ;
239
- }
240
- return Err ( var_hir_id) ;
241
- } ;
229
+ var_hir_id,
230
+ from_builder. projection
231
+ )
232
+ } else {
233
+ // FIXME(project-rfc-2229#24): Handle this case properly
234
+ debug ! (
235
+ "No associated capture found for {:?}[{:#?}]" ,
236
+ var_hir_id, from_builder. projection,
237
+ ) ;
238
+ }
239
+ return Err ( var_hir_id) ;
240
+ } ;
242
241
243
- let closure_ty =
244
- typeck_results . node_type ( tcx. hir ( ) . local_def_id_to_hir_id ( closure_def_id. expect_local ( ) ) ) ;
242
+ let closure_ty = typeck_results
243
+ . node_type ( tcx. hir ( ) . local_def_id_to_hir_id ( closure_def_id. expect_local ( ) ) ) ;
245
244
246
245
let substs = match closure_ty. kind ( ) {
247
246
ty:: Closure ( _, substs) => ty:: UpvarSubsts :: Closure ( substs) ,
@@ -256,7 +255,8 @@ fn to_upvars_resolved_place_builder<'a, 'tcx>(
256
255
// we know that the capture exists and is the `capture_index`-th capture.
257
256
let var_ty = substs. tupled_upvars_ty ( ) . tuple_element_ty ( capture_index) . unwrap ( ) ;
258
257
259
- upvar_resolved_place_builder = upvar_resolved_place_builder. field ( Field :: new ( capture_index) , var_ty) ;
258
+ upvar_resolved_place_builder =
259
+ upvar_resolved_place_builder. field ( Field :: new ( capture_index) , var_ty) ;
260
260
261
261
// If the variable is captured via ByRef(Immutable/Mutable) Borrow,
262
262
// we need to deref it
@@ -270,8 +270,9 @@ fn to_upvars_resolved_place_builder<'a, 'tcx>(
270
270
271
271
// We used some of the projections to build the capture itself,
272
272
// now we apply the remaining to the upvar resolved place.
273
- upvar_resolved_place_builder. projection . extend (
274
- curr_projections. drain ( next_projection..) ) ;
273
+ upvar_resolved_place_builder
274
+ . projection
275
+ . extend ( curr_projections. drain ( next_projection..) ) ;
275
276
276
277
Ok ( upvar_resolved_place_builder)
277
278
}
@@ -356,7 +357,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
356
357
357
358
/// This is used when constructing a compound `Place`, so that we can avoid creating
358
359
/// intermediate `Place` values until we know the full set of projections.
359
- crate fn as_place_builder < M > ( & mut self , block : BasicBlock , expr : M ) -> BlockAnd < PlaceBuilder < ' tcx > >
360
+ crate fn as_place_builder < M > (
361
+ & mut self ,
362
+ block : BasicBlock ,
363
+ expr : M ,
364
+ ) -> BlockAnd < PlaceBuilder < ' tcx > >
360
365
where
361
366
M : Mirror < ' tcx , Output = Expr < ' tcx > > ,
362
367
{
@@ -627,7 +632,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
627
632
if is_outermost_index {
628
633
self . read_fake_borrows ( block, fake_borrow_temps, source_info)
629
634
} else {
630
- base_place = base_place. expect_upvars_resolved ( self . hir . tcx ( ) , self . hir . typeck_results ( ) ) ;
635
+ base_place =
636
+ base_place. expect_upvars_resolved ( self . hir . tcx ( ) , self . hir . typeck_results ( ) ) ;
631
637
self . add_fake_borrows_of_base (
632
638
& base_place,
633
639
block,
@@ -679,7 +685,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
679
685
let tcx = self . hir . tcx ( ) ;
680
686
let local = match base_place. base {
681
687
PlaceBase :: Local ( local) => local,
682
- PlaceBase :: Upvar { .. } => bug ! ( "Expected PlacseBase::Local found Upvar" )
688
+ PlaceBase :: Upvar { .. } => bug ! ( "Expected PlacseBase::Local found Upvar" ) ,
683
689
} ;
684
690
685
691
let place_ty = Place :: ty_from ( local, & base_place. projection , & self . local_decls , tcx) ;
0 commit comments