@@ -673,40 +673,34 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
673673 let tcx = self . infcx . tcx ;
674674
675675 // Find out if the predicates show that the type is a Fn or FnMut
676- let find_fn_kind_from_did = |predicates : ty:: EarlyBinder <
677- & [ ( ty:: Predicate < ' tcx > , Span ) ] ,
678- > ,
679- substs| {
680- predicates. 0 . iter ( ) . find_map ( |( pred, _) | {
681- let pred = if let Some ( substs) = substs {
682- predicates. rebind ( * pred) . subst ( tcx, substs) . kind ( ) . skip_binder ( )
683- } else {
684- pred. kind ( ) . skip_binder ( )
685- } ;
686- if let ty:: PredicateKind :: Clause ( ty:: Clause :: Trait ( pred) ) = pred && pred. self_ty ( ) == ty {
687- if Some ( pred. def_id ( ) ) == tcx. lang_items ( ) . fn_trait ( ) {
688- return Some ( hir:: Mutability :: Not ) ;
689- } else if Some ( pred. def_id ( ) ) == tcx. lang_items ( ) . fn_mut_trait ( ) {
690- return Some ( hir:: Mutability :: Mut ) ;
691- }
676+ let find_fn_kind_from_did = |( pred, _) : ( ty:: Predicate < ' tcx > , _ ) | {
677+ if let ty:: PredicateKind :: Clause ( ty:: Clause :: Trait ( pred) ) = pred. kind ( ) . skip_binder ( )
678+ && pred. self_ty ( ) == ty
679+ {
680+ if Some ( pred. def_id ( ) ) == tcx. lang_items ( ) . fn_trait ( ) {
681+ return Some ( hir:: Mutability :: Not ) ;
682+ } else if Some ( pred. def_id ( ) ) == tcx. lang_items ( ) . fn_mut_trait ( ) {
683+ return Some ( hir:: Mutability :: Mut ) ;
692684 }
693- None
694- } )
685+ }
686+ None
695687 } ;
696688
697689 // If the type is opaque/param/closure, and it is Fn or FnMut, let's suggest (mutably)
698690 // borrowing the type, since `&mut F: FnMut` iff `F: FnMut` and similarly for `Fn`.
699691 // These types seem reasonably opaque enough that they could be substituted with their
700692 // borrowed variants in a function body when we see a move error.
701- let borrow_level = match ty. kind ( ) {
702- ty:: Param ( _) => find_fn_kind_from_did (
703- tcx. bound_explicit_predicates_of ( self . mir_def_id ( ) . to_def_id ( ) )
704- . map_bound ( |p| p. predicates ) ,
705- None ,
706- ) ,
707- ty:: Alias ( ty:: Opaque , ty:: AliasTy { def_id, substs, .. } ) => {
708- find_fn_kind_from_did ( tcx. bound_explicit_item_bounds ( * def_id) , Some ( * substs) )
709- }
693+ let borrow_level = match * ty. kind ( ) {
694+ ty:: Param ( _) => tcx
695+ . explicit_predicates_of ( self . mir_def_id ( ) . to_def_id ( ) )
696+ . predicates
697+ . iter ( )
698+ . copied ( )
699+ . find_map ( find_fn_kind_from_did) ,
700+ ty:: Alias ( ty:: Opaque , ty:: AliasTy { def_id, substs, .. } ) => tcx
701+ . bound_explicit_item_bounds ( def_id)
702+ . subst_iter_copied ( tcx, substs)
703+ . find_map ( find_fn_kind_from_did) ,
710704 ty:: Closure ( _, substs) => match substs. as_closure ( ) . kind ( ) {
711705 ty:: ClosureKind :: Fn => Some ( hir:: Mutability :: Not ) ,
712706 ty:: ClosureKind :: FnMut => Some ( hir:: Mutability :: Mut ) ,
0 commit comments