@@ -428,7 +428,6 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
428
428
) -> BlockAnd < Operand < ' tcx > > {
429
429
let this = self ;
430
430
431
- let tcx = this. hir . tcx ( ) ;
432
431
let source_info = this. source_info ( upvar_span) ;
433
432
let temp = this. local_decls . push ( LocalDecl :: new_temp ( upvar_ty, upvar_span) ) ;
434
433
@@ -439,26 +438,32 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
439
438
440
439
let arg_place = unpack ! ( block = this. as_place( block, arg) ) ;
441
440
442
- let mutability = if let ( base_place, Some ( projection) ) = arg_place. final_projection ( tcx) {
443
- match projection {
444
- ProjectionElem :: Deref => {
445
- if let PlaceBase :: Local ( local) = base_place. base {
446
- debug_assert ! (
447
- if let Some ( ClearCrossCrate :: Set ( BindingForm :: RefForGuard ) )
448
- = this. local_decls[ local] . is_user_variable {
449
- true
450
- } else {
451
- false
452
- } ,
453
- "Unexpected capture place" ,
454
- ) ;
455
- this. local_decls [ local] . mutability
456
- } else if let ( base_place, Some ( projection) ) = base_place. final_projection ( tcx)
457
- {
458
- if let ProjectionElem :: Field ( upvar_index, _) = projection {
441
+ let mut mutability = if let PlaceBase :: Local ( local) = arg_place. base {
442
+ this. local_decls [ local] . mutability
443
+ } else {
444
+ bug ! ( "Unexpected capture place" ) ;
445
+ } ;
446
+ if !arg_place. has_no_projection ( ) {
447
+ let mut proj_iter = arg_place. elems . iter ( ) . cloned ( ) . rev ( ) ;
448
+ if let Some ( projection) = proj_iter. next ( ) {
449
+ match projection {
450
+ ProjectionElem :: Deref => {
451
+ if let PlaceBase :: Local ( local) = arg_place. base {
452
+ debug_assert ! (
453
+ if let Some ( ClearCrossCrate :: Set ( BindingForm :: RefForGuard ) )
454
+ = this. local_decls[ local] . is_user_variable {
455
+ true
456
+ } else {
457
+ false
458
+ } ,
459
+ "Unexpected capture place" ,
460
+ ) ;
461
+ }
462
+
463
+ if let Some ( ProjectionElem :: Field ( upvar_index, _) ) = proj_iter. next ( ) {
459
464
// Not projected from the implicit `self` in a closure.
460
465
debug_assert ! (
461
- match base_place . base {
466
+ match arg_place . base {
462
467
PlaceBase :: Local ( local) => local == Local :: new( 1 ) ,
463
468
_ => false ,
464
469
} ,
@@ -469,41 +474,34 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
469
474
this. upvar_decls. len( ) > upvar_index. index( ) ,
470
475
"Unexpected capture place"
471
476
) ;
472
- this. upvar_decls [ upvar_index. index ( ) ] . mutability
477
+ mutability = this. upvar_decls [ upvar_index. index ( ) ] . mutability ;
473
478
} else {
474
479
bug ! ( "Unexpected capture place" ) ;
475
480
}
476
- } else {
481
+ } ,
482
+ ProjectionElem :: Field ( upvar_index, _) => {
483
+ // Not projected from the implicit `self` in a closure.
484
+ debug_assert ! (
485
+ match arg_place. base {
486
+ PlaceBase :: Local ( local) => local == Local :: new( 1 ) ,
487
+ _ => false ,
488
+ } ,
489
+ "Unexpected capture place"
490
+ ) ;
491
+ // Not in a closure
492
+ debug_assert ! (
493
+ this. upvar_decls. len( ) > upvar_index. index( ) ,
494
+ "Unexpected capture place"
495
+ ) ;
496
+ mutability = this. upvar_decls [ upvar_index. index ( ) ] . mutability ;
497
+ } ,
498
+ _ => {
477
499
bug ! ( "Unexpected capture place" ) ;
478
500
}
479
- } ,
480
- ProjectionElem :: Field ( upvar_index, _) => {
481
- // Not projected from the implicit `self` in a closure.
482
- debug_assert ! (
483
- match base_place. base {
484
- PlaceBase :: Local ( local) => local == Local :: new( 1 ) ,
485
- _ => false ,
486
- } ,
487
- "Unexpected capture place"
488
- ) ;
489
- // Not in a closure
490
- debug_assert ! (
491
- this. upvar_decls. len( ) > upvar_index. index( ) ,
492
- "Unexpected capture place"
493
- ) ;
494
- this. upvar_decls [ upvar_index. index ( ) ] . mutability
495
- }
496
- _ => {
497
- bug ! ( "Unexpected capture place" ) ;
498
501
}
499
502
}
500
- } else {
501
- if let PlaceBase :: Local ( local) = arg_place. base {
502
- this. local_decls [ local] . mutability
503
- } else {
504
- bug ! ( "Unexpected capture place" ) ;
505
- }
506
- } ;
503
+ }
504
+
507
505
let borrow_kind = match mutability {
508
506
Mutability :: Not => BorrowKind :: Unique ,
509
507
Mutability :: Mut => BorrowKind :: Mut { allow_two_phase_borrow : false } ,
0 commit comments