@@ -792,6 +792,14 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
792
792
// a `&self` method will wind up with an argument type like `&dyn Trait`.
793
793
let trait_ref = principal. with_self_ty ( self . tcx , self_ty) ;
794
794
self . elaborate_bounds ( iter:: once ( trait_ref) , |this, new_trait_ref, item| {
795
+ if new_trait_ref. has_non_region_late_bound ( ) {
796
+ this. tcx . sess . delay_span_bug (
797
+ this. span ,
798
+ "tried to select method from HRTB with non-lifetime bound vars" ,
799
+ ) ;
800
+ return ;
801
+ }
802
+
795
803
let new_trait_ref = this. erase_late_bound_regions ( new_trait_ref) ;
796
804
797
805
let ( xform_self_ty, xform_ret_ty) =
@@ -842,18 +850,15 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
842
850
} ) ;
843
851
844
852
self . elaborate_bounds ( bounds, |this, poly_trait_ref, item| {
845
- let trait_ref = this. erase_late_bound_regions ( poly_trait_ref) ;
853
+ let trait_ref = this. instantiate_binder_with_fresh_vars (
854
+ this. span ,
855
+ infer:: LateBoundRegionConversionTime :: FnCall ,
856
+ poly_trait_ref,
857
+ ) ;
846
858
847
859
let ( xform_self_ty, xform_ret_ty) =
848
860
this. xform_self_ty ( item, trait_ref. self_ty ( ) , trait_ref. substs ) ;
849
861
850
- // Because this trait derives from a where-clause, it
851
- // should not contain any inference variables or other
852
- // artifacts. This means it is safe to put into the
853
- // `WhereClauseCandidate` and (eventually) into the
854
- // `WhereClausePick`.
855
- assert ! ( !trait_ref. substs. needs_infer( ) ) ;
856
-
857
862
this. push_candidate (
858
863
Candidate {
859
864
xform_self_ty,
@@ -963,7 +968,11 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
963
968
bound_trait_ref. def_id ( ) ,
964
969
) ) ;
965
970
} else {
966
- let new_trait_ref = self . erase_late_bound_regions ( bound_trait_ref) ;
971
+ let new_trait_ref = self . instantiate_binder_with_fresh_vars (
972
+ self . span ,
973
+ infer:: LateBoundRegionConversionTime :: FnCall ,
974
+ bound_trait_ref,
975
+ ) ;
967
976
968
977
let ( xform_self_ty, xform_ret_ty) =
969
978
self . xform_self_ty ( item, new_trait_ref. self_ty ( ) , new_trait_ref. substs ) ;
0 commit comments