@@ -628,15 +628,17 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
628628 if let Some ( parent_trait_pred) = parent_trait_pred {
629629 real_trait_pred = parent_trait_pred;
630630 }
631- let Some ( real_ty ) = real_trait_pred . self_ty ( ) . no_bound_vars ( ) else {
632- continue ;
633- } ;
631+
632+ // Skipping binder here, remapping below
633+ let real_ty = real_trait_pred . self_ty ( ) . skip_binder ( ) ;
634634
635635 if let ty:: Ref ( region, base_ty, mutbl) = * real_ty. kind ( ) {
636636 let mut autoderef = Autoderef :: new ( self , param_env, body_id, span, base_ty, span) ;
637637 if let Some ( steps) = autoderef. find_map ( |( ty, steps) | {
638638 // Re-add the `&`
639639 let ty = self . tcx . mk_ref ( region, TypeAndMut { ty, mutbl } ) ;
640+
641+ // Remapping bound vars here
640642 let real_trait_pred_and_ty =
641643 real_trait_pred. map_bound ( |inner_trait_pred| ( inner_trait_pred, ty) ) ;
642644 let obligation = self
@@ -661,6 +663,8 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
661663 }
662664 } else if real_trait_pred != trait_pred {
663665 // This branch addresses #87437.
666+
667+ // Remapping bound vars here
664668 let real_trait_pred_and_base_ty =
665669 real_trait_pred. map_bound ( |inner_trait_pred| ( inner_trait_pred, base_ty) ) ;
666670 let obligation = self . mk_trait_obligation_with_new_self_ty (
@@ -723,6 +727,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
723727 err : & mut Diagnostic ,
724728 trait_pred : ty:: PolyTraitPredicate < ' tcx > ,
725729 ) -> bool {
730+ // Skipping binder here, remapping below
726731 let self_ty = trait_pred. self_ty ( ) . skip_binder ( ) ;
727732
728733 let ( def_id, output_ty, callable) = match * self_ty. kind ( ) {
@@ -732,8 +737,11 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
732737 } ;
733738 let msg = format ! ( "use parentheses to call the {}" , callable) ;
734739
740+ // "We should really create a single list of bound vars from the combined vars
741+ // from the predicate and function, but instead we just liberate the function bound vars"
735742 let output_ty = self . tcx . liberate_late_bound_regions ( def_id, output_ty) ;
736743
744+ // Remapping bound vars here
737745 let trait_pred_and_self = trait_pred. map_bound ( |trait_pred| ( trait_pred, output_ty) ) ;
738746
739747 let new_obligation =
@@ -876,12 +884,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
876884 // Because of this, we modify the error to refer to the original obligation and
877885 // return early in the caller.
878886
879- let msg = format ! (
880- "the trait bound `{}: {}` is not satisfied" ,
881- // Safe to skip binder here
882- old_pred. self_ty( ) . skip_binder( ) ,
883- old_pred. print_modifiers_and_trait_path( ) ,
884- ) ;
887+ let msg = format ! ( "the trait bound `{}` is not satisfied" , old_pred) ;
885888 if has_custom_message {
886889 err. note ( & msg) ;
887890 } else {
@@ -997,7 +1000,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
9971000 return false ;
9981001 }
9991002
1000- // We skip binder here
1003+ // Skipping binder here, remapping below
10011004 let mut suggested_ty = trait_pred. self_ty ( ) . skip_binder ( ) ;
10021005
10031006 for refs_remaining in 0 ..refs_number {
@@ -1006,7 +1009,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
10061009 } ;
10071010 suggested_ty = * inner_ty;
10081011
1009- // We remap bounds here
1012+ // Remapping bound vars here
10101013 let trait_pred_and_suggested_ty =
10111014 trait_pred. map_bound ( |trait_pred| ( trait_pred, suggested_ty) ) ;
10121015
@@ -1132,22 +1135,15 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
11321135 return ;
11331136 }
11341137
1138+ // Skipping binder here, remapping below
11351139 if let ty:: Ref ( region, t_type, mutability) = * trait_pred. skip_binder ( ) . self_ty ( ) . kind ( )
11361140 {
1137- if region. is_late_bound ( ) || t_type. has_escaping_bound_vars ( ) {
1138- // Avoid debug assertion in `mk_obligation_for_def_id`.
1139- //
1140- // If the self type has escaping bound vars then it's not
1141- // going to be the type of an expression, so the suggestion
1142- // probably won't apply anyway.
1143- return ;
1144- }
1145-
11461141 let suggested_ty = match mutability {
11471142 hir:: Mutability :: Mut => self . tcx . mk_imm_ref ( region, t_type) ,
11481143 hir:: Mutability :: Not => self . tcx . mk_mut_ref ( region, t_type) ,
11491144 } ;
11501145
1146+ // Remapping bound vars here
11511147 let trait_pred_and_suggested_ty =
11521148 trait_pred. map_bound ( |trait_pred| ( trait_pred, suggested_ty) ) ;
11531149
0 commit comments