@@ -532,14 +532,17 @@ 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 ( ) ,
539
- obligation. param_env ,
540
- ) ;
535
+ // `mk_trait_obligation_with_new_self_ty` only works for types with no escaping bound
536
+ // variables, so bail out if we have any.
537
+ let output_ty = match output_ty. no_bound_vars ( ) {
538
+ Some ( ty) => ty,
539
+ None => return ,
540
+ } ;
541
+
542
+ let new_obligation =
543
+ self . mk_trait_obligation_with_new_self_ty ( obligation. param_env , trait_ref, output_ty) ;
541
544
542
- match self . evaluate_obligation ( & obligation ) {
545
+ match self . evaluate_obligation ( & new_obligation ) {
543
546
Ok (
544
547
EvaluationResult :: EvaluatedToOk
545
548
| EvaluationResult :: EvaluatedToOkModuloRegions
@@ -694,7 +697,6 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
694
697
err : & mut DiagnosticBuilder < ' _ > ,
695
698
trait_ref : & ty:: Binder < ty:: TraitRef < ' tcx > > ,
696
699
) {
697
- let trait_ref = trait_ref. skip_binder ( ) ;
698
700
let span = obligation. cause . span ;
699
701
700
702
if let Ok ( snippet) = self . tcx . sess . source_map ( ) . span_to_snippet ( span) {
@@ -705,17 +707,16 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
705
707
return ;
706
708
}
707
709
708
- let mut trait_type = trait_ref. self_ty ( ) ;
710
+ let mut suggested_ty = trait_ref. self_ty ( ) ;
709
711
710
712
for refs_remaining in 0 ..refs_number {
711
- if let ty:: Ref ( _, t_type , _) = trait_type . kind {
712
- trait_type = t_type ;
713
+ if let ty:: Ref ( _, inner_ty , _) = suggested_ty . kind {
714
+ suggested_ty = inner_ty ;
713
715
714
- let new_obligation = self . mk_obligation_for_def_id (
715
- trait_ref. def_id ,
716
- trait_type,
717
- ObligationCause :: dummy ( ) ,
716
+ let new_obligation = self . mk_trait_obligation_with_new_self_ty (
718
717
obligation. param_env ,
718
+ trait_ref,
719
+ suggested_ty,
719
720
) ;
720
721
721
722
if self . predicate_may_hold ( & new_obligation) {
@@ -782,20 +783,20 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
782
783
return ;
783
784
}
784
785
785
- let trait_type = match mutability {
786
+ let suggested_ty = match mutability {
786
787
hir:: Mutability :: Mut => self . tcx . mk_imm_ref ( region, t_type) ,
787
788
hir:: Mutability :: Not => self . tcx . mk_mut_ref ( region, t_type) ,
788
789
} ;
789
790
790
- let new_obligation = self . mk_obligation_for_def_id (
791
- trait_ref. skip_binder ( ) . def_id ,
792
- trait_type,
793
- ObligationCause :: dummy ( ) ,
791
+ let new_obligation = self . mk_trait_obligation_with_new_self_ty (
794
792
obligation. param_env ,
793
+ & trait_ref,
794
+ suggested_ty,
795
795
) ;
796
-
797
- if self . evaluate_obligation_no_overflow ( & new_obligation) . must_apply_modulo_regions ( )
798
- {
796
+ let suggested_ty_would_satisfy_obligation = self
797
+ . evaluate_obligation_no_overflow ( & new_obligation)
798
+ . must_apply_modulo_regions ( ) ;
799
+ if suggested_ty_would_satisfy_obligation {
799
800
let sp = self
800
801
. tcx
801
802
. sess
@@ -812,7 +813,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
812
813
err. note ( & format ! (
813
814
"`{}` is implemented for `{:?}`, but not for `{:?}`" ,
814
815
trait_ref. print_only_trait_path( ) ,
815
- trait_type ,
816
+ suggested_ty ,
816
817
trait_ref. skip_binder( ) . self_ty( ) ,
817
818
) ) ;
818
819
}
@@ -1891,7 +1892,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
1891
1892
span : Span ,
1892
1893
) {
1893
1894
debug ! (
1894
- "suggest_await_befor_try : obligation={:?}, span={:?}, trait_ref={:?}, trait_ref_self_ty={:?}" ,
1895
+ "suggest_await_before_try : obligation={:?}, span={:?}, trait_ref={:?}, trait_ref_self_ty={:?}" ,
1895
1896
obligation,
1896
1897
span,
1897
1898
trait_ref,
@@ -1946,16 +1947,15 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
1946
1947
) ;
1947
1948
1948
1949
debug ! (
1949
- "suggest_await_befor_try : normalized_projection_type {:?}" ,
1950
+ "suggest_await_before_try : normalized_projection_type {:?}" ,
1950
1951
self . resolve_vars_if_possible( & normalized_ty)
1951
1952
) ;
1952
- let try_obligation = self . mk_obligation_for_def_id (
1953
- trait_ref. def_id ( ) ,
1954
- normalized_ty,
1955
- obligation. cause . clone ( ) ,
1953
+ let try_obligation = self . mk_trait_obligation_with_new_self_ty (
1956
1954
obligation. param_env ,
1955
+ trait_ref,
1956
+ normalized_ty,
1957
1957
) ;
1958
- debug ! ( "suggest_await_befor_try : try_trait_obligation {:?}" , try_obligation) ;
1958
+ debug ! ( "suggest_await_before_try : try_trait_obligation {:?}" , try_obligation) ;
1959
1959
if self . predicate_may_hold ( & try_obligation) && impls_future {
1960
1960
if let Ok ( snippet) = self . tcx . sess . source_map ( ) . span_to_snippet ( span) {
1961
1961
if snippet. ends_with ( '?' ) {
0 commit comments