@@ -628,15 +628,17 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
628
628
if let Some ( parent_trait_pred) = parent_trait_pred {
629
629
real_trait_pred = parent_trait_pred;
630
630
}
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 ( ) ;
634
634
635
635
if let ty:: Ref ( region, base_ty, mutbl) = * real_ty. kind ( ) {
636
636
let mut autoderef = Autoderef :: new ( self , param_env, body_id, span, base_ty, span) ;
637
637
if let Some ( steps) = autoderef. find_map ( |( ty, steps) | {
638
638
// Re-add the `&`
639
639
let ty = self . tcx . mk_ref ( region, TypeAndMut { ty, mutbl } ) ;
640
+
641
+ // Remapping bound vars here
640
642
let real_trait_pred_and_ty =
641
643
real_trait_pred. map_bound ( |inner_trait_pred| ( inner_trait_pred, ty) ) ;
642
644
let obligation = self
@@ -661,6 +663,8 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
661
663
}
662
664
} else if real_trait_pred != trait_pred {
663
665
// This branch addresses #87437.
666
+
667
+ // Remapping bound vars here
664
668
let real_trait_pred_and_base_ty =
665
669
real_trait_pred. map_bound ( |inner_trait_pred| ( inner_trait_pred, base_ty) ) ;
666
670
let obligation = self . mk_trait_obligation_with_new_self_ty (
@@ -723,6 +727,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
723
727
err : & mut Diagnostic ,
724
728
trait_pred : ty:: PolyTraitPredicate < ' tcx > ,
725
729
) -> bool {
730
+ // Skipping binder here, remapping below
726
731
let self_ty = trait_pred. self_ty ( ) . skip_binder ( ) ;
727
732
728
733
let ( def_id, output_ty, callable) = match * self_ty. kind ( ) {
@@ -732,8 +737,11 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
732
737
} ;
733
738
let msg = format ! ( "use parentheses to call the {}" , callable) ;
734
739
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"
735
742
let output_ty = self . tcx . liberate_late_bound_regions ( def_id, output_ty) ;
736
743
744
+ // Remapping bound vars here
737
745
let trait_pred_and_self = trait_pred. map_bound ( |trait_pred| ( trait_pred, output_ty) ) ;
738
746
739
747
let new_obligation =
@@ -876,12 +884,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
876
884
// Because of this, we modify the error to refer to the original obligation and
877
885
// return early in the caller.
878
886
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) ;
885
888
if has_custom_message {
886
889
err. note ( & msg) ;
887
890
} else {
@@ -997,7 +1000,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
997
1000
return false ;
998
1001
}
999
1002
1000
- // We skip binder here
1003
+ // Skipping binder here, remapping below
1001
1004
let mut suggested_ty = trait_pred. self_ty ( ) . skip_binder ( ) ;
1002
1005
1003
1006
for refs_remaining in 0 ..refs_number {
@@ -1006,7 +1009,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
1006
1009
} ;
1007
1010
suggested_ty = * inner_ty;
1008
1011
1009
- // We remap bounds here
1012
+ // Remapping bound vars here
1010
1013
let trait_pred_and_suggested_ty =
1011
1014
trait_pred. map_bound ( |trait_pred| ( trait_pred, suggested_ty) ) ;
1012
1015
@@ -1132,22 +1135,15 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
1132
1135
return ;
1133
1136
}
1134
1137
1138
+ // Skipping binder here, remapping below
1135
1139
if let ty:: Ref ( region, t_type, mutability) = * trait_pred. skip_binder ( ) . self_ty ( ) . kind ( )
1136
1140
{
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
-
1146
1141
let suggested_ty = match mutability {
1147
1142
hir:: Mutability :: Mut => self . tcx . mk_imm_ref ( region, t_type) ,
1148
1143
hir:: Mutability :: Not => self . tcx . mk_mut_ref ( region, t_type) ,
1149
1144
} ;
1150
1145
1146
+ // Remapping bound vars here
1151
1147
let trait_pred_and_suggested_ty =
1152
1148
trait_pred. map_bound ( |trait_pred| ( trait_pred, suggested_ty) ) ;
1153
1149
0 commit comments