@@ -524,74 +524,59 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
524
524
return ( false , None ) ;
525
525
}
526
526
let hir_map = self . infcx . tcx . hir ( ) ;
527
- let my_hir = hir_map. local_def_id_to_hir_id (
528
- self . body . source . def_id ( ) . as_local ( ) . unwrap ( ) ,
529
- ) ;
530
- match hir_map. find ( hir_map. get_parent_node ( my_hir) ) {
531
- Some ( Node :: Item ( hir:: Item {
532
- kind :
533
- hir:: ItemKind :: Impl ( hir:: Impl {
534
- of_trait :
535
- Some ( hir:: TraitRef {
536
- path :
537
- hir:: Path {
538
- res :
539
- hir:: def:: Res :: Def ( _, td) ,
527
+ let my_def = self . body . source . def_id ( ) ;
528
+ let my_hir = hir_map. local_def_id_to_hir_id ( my_def. as_local ( ) . unwrap ( ) ) ;
529
+ let td = if let Some ( a) = self . infcx . tcx . impl_of_method ( my_def) . and_then ( |x| {
530
+ self . infcx . tcx . trait_id_of_impl ( x)
531
+ } ) {
532
+ a
533
+ } else {
534
+ return ( false , None ) ;
535
+ } ;
536
+ ( true , td. as_local ( ) . and_then ( |tld| {
537
+ let h = hir_map. local_def_id_to_hir_id ( tld) ;
538
+ match hir_map. find ( h) {
539
+ Some ( Node :: Item ( hir:: Item {
540
+ kind : hir:: ItemKind :: Trait (
541
+ _, _, _, _,
542
+ items
543
+ ) ,
544
+ ..
545
+ } ) ) => {
546
+ let mut f_in_trait_opt = None ;
547
+ for hir:: TraitItemRef { id : fi, kind : k, .. } in * items {
548
+ let hi = fi. hir_id ( ) ;
549
+ if !matches ! ( k, hir:: AssocItemKind :: Fn { .. } ) {
550
+ continue ;
551
+ }
552
+ if hir_map. name ( hi) != hir_map. name ( my_hir) {
553
+ continue ;
554
+ }
555
+ f_in_trait_opt = Some ( hi) ;
556
+ break ;
557
+ }
558
+ f_in_trait_opt. and_then ( |f_in_trait| {
559
+ match hir_map. find ( f_in_trait) {
560
+ Some ( Node :: TraitItem ( hir:: TraitItem {
561
+ kind : hir:: TraitItemKind :: Fn ( hir:: FnSig {
562
+ decl : hir:: FnDecl {
563
+ inputs,
540
564
..
541
565
} ,
566
+ ..
567
+ } , _) ,
542
568
..
543
- } ) ,
544
- ..
545
- } ) ,
546
- ..
547
- } ) ) => {
548
- ( true , td. as_local ( ) . and_then ( |tld| {
549
- let h = hir_map. local_def_id_to_hir_id ( tld) ;
550
- match hir_map. find ( h) {
551
- Some ( Node :: Item ( hir:: Item {
552
- kind : hir:: ItemKind :: Trait (
553
- _, _, _, _,
554
- items
555
- ) ,
556
- ..
557
- } ) ) => {
558
- let mut f_in_trait_opt = None ;
559
- for hir:: TraitItemRef { id : fi, kind : k, .. } in * items {
560
- let hi = fi. hir_id ( ) ;
561
- if !matches ! ( k, hir:: AssocItemKind :: Fn { .. } ) {
562
- continue ;
563
- }
564
- if hir_map. name ( hi) != hir_map. name ( my_hir) {
565
- continue ;
566
- }
567
- f_in_trait_opt = Some ( hi) ;
568
- break ;
569
- }
570
- f_in_trait_opt. and_then ( |f_in_trait| {
571
- match hir_map. find ( f_in_trait) {
572
- Some ( Node :: TraitItem ( hir:: TraitItem {
573
- kind : hir:: TraitItemKind :: Fn ( hir:: FnSig {
574
- decl : hir:: FnDecl {
575
- inputs,
576
- ..
577
- } ,
578
- ..
579
- } , _) ,
580
- ..
581
- } ) ) => {
582
- let hir:: Ty { span, .. } = inputs[ local. index ( ) - 1 ] ;
583
- Some ( span)
584
- } ,
585
- _ => None ,
586
- }
587
- } )
569
+ } ) ) => {
570
+ let hir:: Ty { span, .. } = inputs[ local. index ( ) - 1 ] ;
571
+ Some ( span)
572
+ } ,
573
+ _ => None ,
588
574
}
589
- _ => None
590
- }
591
- } ) )
575
+ } )
576
+ }
577
+ _ => None
592
578
}
593
- _ => ( false , None ) ,
594
- }
579
+ } ) )
595
580
}
596
581
597
582
// point to span of upvar making closure call require mutable borrow
0 commit comments