@@ -532,14 +532,13 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
532
532
} ;
533
533
let msg = format ! ( "use parentheses to call the {}" , callable) ;
534
534
535
- let obligation = self . mk_obligation_for_def_id (
536
- trait_ref. def_id ( ) ,
537
- output_ty. skip_binder ( ) ,
538
- obligation. cause . clone ( ) ,
535
+ let new_obligation = self . mk_trait_obligation_with_new_self_ty (
539
536
obligation. param_env ,
537
+ trait_ref,
538
+ output_ty. skip_binder ( ) ,
540
539
) ;
541
540
542
- match self . evaluate_obligation ( & obligation ) {
541
+ match self . evaluate_obligation ( & new_obligation ) {
543
542
Ok (
544
543
EvaluationResult :: EvaluatedToOk
545
544
| EvaluationResult :: EvaluatedToOkModuloRegions
@@ -694,7 +693,6 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
694
693
err : & mut DiagnosticBuilder < ' _ > ,
695
694
trait_ref : & ty:: Binder < ty:: TraitRef < ' tcx > > ,
696
695
) {
697
- let trait_ref = trait_ref. skip_binder ( ) ;
698
696
let span = obligation. cause . span ;
699
697
700
698
if let Ok ( snippet) = self . tcx . sess . source_map ( ) . span_to_snippet ( span) {
@@ -705,17 +703,16 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
705
703
return ;
706
704
}
707
705
708
- let mut trait_type = trait_ref. self_ty ( ) ;
706
+ let mut suggested_ty = trait_ref. self_ty ( ) ;
709
707
710
708
for refs_remaining in 0 ..refs_number {
711
- if let ty:: Ref ( _, t_type , _) = trait_type . kind {
712
- trait_type = t_type ;
709
+ if let ty:: Ref ( _, inner_ty , _) = suggested_ty . kind {
710
+ suggested_ty = inner_ty ;
713
711
714
- let new_obligation = self . mk_obligation_for_def_id (
715
- trait_ref. def_id ,
716
- trait_type,
717
- ObligationCause :: dummy ( ) ,
712
+ let new_obligation = self . mk_trait_obligation_with_new_self_ty (
718
713
obligation. param_env ,
714
+ trait_ref,
715
+ suggested_ty,
719
716
) ;
720
717
721
718
if self . predicate_may_hold ( & new_obligation) {
@@ -782,20 +779,20 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
782
779
return ;
783
780
}
784
781
785
- let trait_type = match mutability {
782
+ let suggested_ty = match mutability {
786
783
hir:: Mutability :: Mut => self . tcx . mk_imm_ref ( region, t_type) ,
787
784
hir:: Mutability :: Not => self . tcx . mk_mut_ref ( region, t_type) ,
788
785
} ;
789
786
790
- let new_obligation = self . mk_obligation_for_def_id (
791
- trait_ref. skip_binder ( ) . def_id ,
792
- trait_type,
793
- ObligationCause :: dummy ( ) ,
787
+ let new_obligation = self . mk_trait_obligation_with_new_self_ty (
794
788
obligation. param_env ,
789
+ & trait_ref,
790
+ suggested_ty,
795
791
) ;
796
-
797
- if self . evaluate_obligation_no_overflow ( & new_obligation) . must_apply_modulo_regions ( )
798
- {
792
+ let suggested_ty_would_satisfy_obligation = self
793
+ . evaluate_obligation_no_overflow ( & new_obligation)
794
+ . must_apply_modulo_regions ( ) ;
795
+ if suggested_ty_would_satisfy_obligation {
799
796
let sp = self
800
797
. tcx
801
798
. sess
@@ -812,7 +809,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
812
809
err. note ( & format ! (
813
810
"`{}` is implemented for `{:?}`, but not for `{:?}`" ,
814
811
trait_ref. print_only_trait_path( ) ,
815
- trait_type ,
812
+ suggested_ty ,
816
813
trait_ref. skip_binder( ) . self_ty( ) ,
817
814
) ) ;
818
815
}
0 commit comments