@@ -513,32 +513,33 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
513
513
let id = id. expect_local ( ) ;
514
514
let tables = tcx. typeck ( id) ;
515
515
let hir_id = tcx. hir ( ) . local_def_id_to_hir_id ( id) ;
516
- let ( span, place) = & tables. closure_kind_origins ( ) [ hir_id] ;
517
- let reason = if let PlaceBase :: Upvar ( upvar_id) = place. base {
518
- let upvar = ty:: place_to_string_for_capture ( tcx, place) ;
519
- match tables. upvar_capture ( upvar_id) {
520
- ty:: UpvarCapture :: ByRef ( ty:: UpvarBorrow {
521
- kind : ty:: BorrowKind :: MutBorrow | ty:: BorrowKind :: UniqueImmBorrow ,
522
- ..
523
- } ) => {
524
- format ! ( "mutable borrow of `{}`" , upvar)
525
- }
526
- ty:: UpvarCapture :: ByValue ( _) => {
527
- format ! ( "possible mutation of `{}`" , upvar)
516
+ if let Some ( ( span, place) ) = tables. closure_kind_origins ( ) . get ( hir_id) {
517
+ let reason = if let PlaceBase :: Upvar ( upvar_id) = place. base {
518
+ let upvar = ty:: place_to_string_for_capture ( tcx, place) ;
519
+ match tables. upvar_capture ( upvar_id) {
520
+ ty:: UpvarCapture :: ByRef ( ty:: UpvarBorrow {
521
+ kind : ty:: BorrowKind :: MutBorrow | ty:: BorrowKind :: UniqueImmBorrow ,
522
+ ..
523
+ } ) => {
524
+ format ! ( "mutable borrow of `{}`" , upvar)
525
+ }
526
+ ty:: UpvarCapture :: ByValue ( _) => {
527
+ format ! ( "possible mutation of `{}`" , upvar)
528
+ }
529
+ val => bug ! ( "upvar `{}` borrowed, but not mutably: {:?}" , upvar, val) ,
528
530
}
529
- val => bug ! ( "upvar `{}` borrowed, but not mutably: {:?}" , upvar, val) ,
530
- }
531
- } else {
532
- bug ! ( "not an upvar" )
533
- } ;
534
- err. span_label (
535
- * span,
536
- format ! (
537
- "calling `{}` requires mutable binding due to {}" ,
538
- self . describe_place( the_place_err) . unwrap( ) ,
539
- reason
540
- ) ,
541
- ) ;
531
+ } else {
532
+ bug ! ( "not an upvar" )
533
+ } ;
534
+ err. span_label (
535
+ * span,
536
+ format ! (
537
+ "calling `{}` requires mutable binding due to {}" ,
538
+ self . describe_place( the_place_err) . unwrap( ) ,
539
+ reason
540
+ ) ,
541
+ ) ;
542
+ }
542
543
}
543
544
544
545
// Attempt to search similar mutable associated items for suggestion.
0 commit comments