@@ -16,9 +16,7 @@ use rustc_middle::mir::{
16
16
FakeReadCause , LocalDecl , LocalInfo , LocalKind , Location , Operand , Place , PlaceRef ,
17
17
ProjectionElem , Rvalue , Statement , StatementKind , Terminator , TerminatorKind , VarBindingForm ,
18
18
} ;
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 } ;
22
20
use rustc_mir_dataflow:: move_paths:: { InitKind , MoveOutIndex , MovePathIndex } ;
23
21
use rustc_span:: def_id:: LocalDefId ;
24
22
use rustc_span:: hygiene:: DesugaringKind ;
@@ -461,35 +459,37 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
461
459
let tcx = self . infcx . tcx ;
462
460
463
461
// 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 {
472
471
if Some ( pred. def_id ( ) ) == tcx. lang_items ( ) . fn_trait ( ) {
473
472
return Some ( hir:: Mutability :: Not ) ;
474
473
} else if Some ( pred. def_id ( ) ) == tcx. lang_items ( ) . fn_mut_trait ( ) {
475
474
return Some ( hir:: Mutability :: Mut ) ;
476
475
}
477
476
}
478
- None
479
- } )
480
- } ;
477
+ None
478
+ } )
479
+ } ;
481
480
482
481
// If the type is opaque/param/closure, and it is Fn or FnMut, let's suggest (mutably)
483
482
// borrowing the type, since `&mut F: FnMut` iff `F: FnMut` and similarly for `Fn`.
484
483
// These types seem reasonably opaque enough that they could be substituted with their
485
484
// borrowed variants in a function body when we see a move error.
486
485
let borrow_level = match ty. kind ( ) {
487
486
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 ) ,
489
489
None ,
490
490
) ,
491
491
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) )
493
493
}
494
494
ty:: Closure ( _, substs) => match substs. as_closure ( ) . kind ( ) {
495
495
ty:: ClosureKind :: Fn => Some ( hir:: Mutability :: Not ) ,
0 commit comments