@@ -792,6 +792,14 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
792792 // a `&self` method will wind up with an argument type like `&dyn Trait`.
793793 let trait_ref = principal. with_self_ty ( self . tcx , self_ty) ;
794794 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+
795803 let new_trait_ref = this. erase_late_bound_regions ( new_trait_ref) ;
796804
797805 let ( xform_self_ty, xform_ret_ty) =
@@ -842,18 +850,15 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
842850 } ) ;
843851
844852 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+ ) ;
846858
847859 let ( xform_self_ty, xform_ret_ty) =
848860 this. xform_self_ty ( item, trait_ref. self_ty ( ) , trait_ref. substs ) ;
849861
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-
857862 this. push_candidate (
858863 Candidate {
859864 xform_self_ty,
@@ -963,7 +968,11 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
963968 bound_trait_ref. def_id ( ) ,
964969 ) ) ;
965970 } 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+ ) ;
967976
968977 let ( xform_self_ty, xform_ret_ty) =
969978 self . xform_self_ty ( item, new_trait_ref. self_ty ( ) , new_trait_ref. substs ) ;
0 commit comments