@@ -16,9 +16,7 @@ use rustc_middle::mir::{
1616 FakeReadCause , LocalDecl , LocalInfo , LocalKind , Location , Operand , Place , PlaceRef ,
1717 ProjectionElem , Rvalue , Statement , StatementKind , Terminator , TerminatorKind , VarBindingForm ,
1818} ;
19- use rustc_middle:: ty:: {
20- self , subst:: Subst , suggest_constraining_type_params, EarlyBinder , PredicateKind , Ty ,
21- } ;
19+ use rustc_middle:: ty:: { self , subst:: Subst , suggest_constraining_type_params, PredicateKind , Ty } ;
2220use rustc_mir_dataflow:: move_paths:: { InitKind , MoveOutIndex , MovePathIndex } ;
2321use rustc_span:: def_id:: LocalDefId ;
2422use rustc_span:: hygiene:: DesugaringKind ;
@@ -461,35 +459,37 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
461459 let tcx = self . infcx . tcx ;
462460
463461 // Find out if the predicates show that the type is a Fn or FnMut
464- let find_fn_kind_from_did = |predicates : & [ ( ty:: Predicate < ' tcx > , Span ) ] , substs| {
465- predicates. iter ( ) . find_map ( |( pred, _) | {
466- let pred = if let Some ( substs) = substs {
467- EarlyBinder ( * pred) . subst ( tcx, substs) . kind ( ) . skip_binder ( )
468- } else {
469- pred. kind ( ) . skip_binder ( )
470- } ;
471- if let ty:: PredicateKind :: Trait ( pred) = pred && pred. self_ty ( ) == ty {
462+ let find_fn_kind_from_did =
463+ |predicates : ty:: EarlyBinder < & [ ( ty:: Predicate < ' tcx > , Span ) ] > , substs| {
464+ predicates. 0 . iter ( ) . find_map ( |( pred, _) | {
465+ let pred = if let Some ( substs) = substs {
466+ predicates. rebind ( * pred) . subst ( tcx, substs) . kind ( ) . skip_binder ( )
467+ } else {
468+ pred. kind ( ) . skip_binder ( )
469+ } ;
470+ if let ty:: PredicateKind :: Trait ( pred) = pred && pred. self_ty ( ) == ty {
472471 if Some ( pred. def_id ( ) ) == tcx. lang_items ( ) . fn_trait ( ) {
473472 return Some ( hir:: Mutability :: Not ) ;
474473 } else if Some ( pred. def_id ( ) ) == tcx. lang_items ( ) . fn_mut_trait ( ) {
475474 return Some ( hir:: Mutability :: Mut ) ;
476475 }
477476 }
478- None
479- } )
480- } ;
477+ None
478+ } )
479+ } ;
481480
482481 // If the type is opaque/param/closure, and it is Fn or FnMut, let's suggest (mutably)
483482 // borrowing the type, since `&mut F: FnMut` iff `F: FnMut` and similarly for `Fn`.
484483 // These types seem reasonably opaque enough that they could be substituted with their
485484 // borrowed variants in a function body when we see a move error.
486485 let borrow_level = match ty. kind ( ) {
487486 ty:: Param ( _) => find_fn_kind_from_did (
488- tcx. explicit_predicates_of ( self . mir_def_id ( ) . to_def_id ( ) ) . predicates ,
487+ tcx. bound_explicit_predicates_of ( self . mir_def_id ( ) . to_def_id ( ) )
488+ . map_bound ( |p| p. predicates ) ,
489489 None ,
490490 ) ,
491491 ty:: Opaque ( did, substs) => {
492- find_fn_kind_from_did ( tcx. explicit_item_bounds ( * did) , Some ( * substs) )
492+ find_fn_kind_from_did ( tcx. bound_explicit_item_bounds ( * did) , Some ( * substs) )
493493 }
494494 ty:: Closure ( _, substs) => match substs. as_closure ( ) . kind ( ) {
495495 ty:: ClosureKind :: Fn => Some ( hir:: Mutability :: Not ) ,
0 commit comments