@@ -27,7 +27,7 @@ use rustc_middle::mir::{
27
27
} ;
28
28
use rustc_middle:: ty:: print:: PrintTraitRefExt as _;
29
29
use rustc_middle:: ty:: {
30
- self , ClauseKind , PredicateKind , Ty , TyCtxt , TypeSuperVisitable , TypeVisitor , Upcast ,
30
+ self , PredicateKind , Ty , TyCtxt , TypeSuperVisitable , TypeVisitor , Upcast ,
31
31
suggest_constraining_type_params,
32
32
} ;
33
33
use rustc_middle:: util:: CallKind ;
@@ -649,11 +649,11 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
649
649
) -> Option < ty:: Mutability > {
650
650
let tcx = self . infcx . tcx ;
651
651
let sig = tcx. fn_sig ( callee_did) . instantiate_identity ( ) . skip_binder ( ) ;
652
- let clauses = tcx. predicates_of ( callee_did) . instantiate_identity ( self . infcx . tcx ) . predicates ;
652
+ let clauses = tcx. predicates_of ( callee_did) ;
653
653
654
654
// First, is there at least one method on one of `param`'s trait bounds?
655
655
// This keeps us from suggesting borrowing the argument to `mem::drop`, e.g.
656
- if !clauses. iter ( ) . any ( |clause| {
656
+ if !clauses. instantiate_identity ( tcx ) . predicates . iter ( ) . any ( |clause| {
657
657
clause. as_trait_clause ( ) . is_some_and ( |tc| {
658
658
tc. self_ty ( ) . skip_binder ( ) . is_param ( param. index )
659
659
&& tc. polarity ( ) == ty:: PredicatePolarity :: Positive
@@ -682,8 +682,12 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
682
682
// Normalize before comparing to see through type aliases and projections.
683
683
let old_ty = ty:: EarlyBinder :: bind ( ty) . instantiate ( tcx, generic_args) ;
684
684
let new_ty = ty:: EarlyBinder :: bind ( ty) . instantiate ( tcx, new_args) ;
685
- if let Ok ( old_ty) = tcx. try_normalize_erasing_regions ( self . param_env , old_ty)
686
- && let Ok ( new_ty) = tcx. try_normalize_erasing_regions ( self . param_env , new_ty)
685
+ if let Ok ( old_ty) =
686
+ tcx. try_normalize_erasing_regions ( self . infcx . typing_env ( self . param_env ) , old_ty)
687
+ && let Ok ( new_ty) = tcx. try_normalize_erasing_regions (
688
+ self . infcx . typing_env ( self . param_env ) ,
689
+ new_ty,
690
+ )
687
691
{
688
692
old_ty == new_ty
689
693
} else {
@@ -700,23 +704,19 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
700
704
return false ;
701
705
}
702
706
703
- // Test the callee's predicates, substituting a reference in for the self ty
704
- // in bounds on `param`.
705
- clauses. iter ( ) . all ( |& clause| {
706
- let clause_for_ref = clause. kind ( ) . map_bound ( |kind| match kind {
707
- ClauseKind :: Trait ( c) if c. self_ty ( ) . is_param ( param. index ) => {
708
- ClauseKind :: Trait ( c. with_self_ty ( tcx, ref_ty) )
709
- }
710
- ClauseKind :: Projection ( c) if c. self_ty ( ) . is_param ( param. index ) => {
711
- ClauseKind :: Projection ( c. with_self_ty ( tcx, ref_ty) )
712
- }
713
- _ => kind,
714
- } ) ;
707
+ // Test the callee's predicates, substituting in `ref_ty` for the moved argument type.
708
+ clauses. instantiate ( tcx, new_args) . predicates . iter ( ) . all ( |& ( mut clause) | {
709
+ // Normalize before testing to see through type aliases and projections.
710
+ if let Ok ( normalized) =
711
+ tcx. try_normalize_erasing_regions ( self . infcx . typing_env ( self . param_env ) , clause)
712
+ {
713
+ clause = normalized;
714
+ }
715
715
self . infcx . predicate_must_hold_modulo_regions ( & Obligation :: new (
716
716
tcx,
717
717
ObligationCause :: dummy ( ) ,
718
718
self . param_env ,
719
- ty :: EarlyBinder :: bind ( clause_for_ref ) . instantiate ( tcx , generic_args ) ,
719
+ clause ,
720
720
) )
721
721
} )
722
722
} ) {
@@ -3837,11 +3837,16 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
3837
3837
if tcx. is_diagnostic_item ( sym:: deref_method, method_did) {
3838
3838
let deref_target =
3839
3839
tcx. get_diagnostic_item ( sym:: deref_target) . and_then ( |deref_target| {
3840
- Instance :: try_resolve ( tcx, self . param_env , deref_target, method_args)
3841
- . transpose ( )
3840
+ Instance :: try_resolve (
3841
+ tcx,
3842
+ self . infcx . typing_env ( self . param_env ) ,
3843
+ deref_target,
3844
+ method_args,
3845
+ )
3846
+ . transpose ( )
3842
3847
} ) ;
3843
3848
if let Some ( Ok ( instance) ) = deref_target {
3844
- let deref_target_ty = instance. ty ( tcx, self . param_env ) ;
3849
+ let deref_target_ty = instance. ty ( tcx, self . infcx . typing_env ( self . param_env ) ) ;
3845
3850
err. note ( format ! ( "borrow occurs due to deref coercion to `{deref_target_ty}`" ) ) ;
3846
3851
err. span_note ( tcx. def_span ( instance. def_id ( ) ) , "deref defined here" ) ;
3847
3852
}
0 commit comments