@@ -20,7 +20,7 @@ use rustc_middle::ty::fast_reject::{simplify_type, TreatParams};
2020use rustc_middle:: ty:: AssocItem ;
2121use rustc_middle:: ty:: GenericParamDefKind ;
2222use rustc_middle:: ty:: ToPredicate ;
23- use rustc_middle:: ty:: { self , ParamEnvAnd , Ty , TyCtxt , TypeFoldable , TypeVisitableExt } ;
23+ use rustc_middle:: ty:: { self , ParamEnvAnd , Ty , TyCtxt , TypeVisitableExt } ;
2424use rustc_middle:: ty:: { GenericArgs , GenericArgsRef } ;
2525use rustc_session:: lint;
2626use rustc_span:: def_id:: DefId ;
@@ -744,7 +744,6 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
744744 }
745745
746746 let ( impl_ty, impl_args) = self . impl_ty_and_args ( impl_def_id) ;
747- let impl_ty = impl_ty. instantiate ( self . tcx , impl_args) ;
748747
749748 debug ! ( "impl_ty: {:?}" , impl_ty) ;
750749
@@ -817,7 +816,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
817816 return ;
818817 }
819818
820- let new_trait_ref = this. instantiate_bound_regions_with_erased ( new_trait_ref) ;
819+ let new_trait_ref = this. tcx . instantiate_bound_regions_with_erased ( new_trait_ref) ;
821820
822821 let ( xform_self_ty, xform_ret_ty) =
823822 this. xform_self_ty ( item, new_trait_ref. self_ty ( ) , new_trait_ref. args ) ;
@@ -928,27 +927,12 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
928927 }
929928 }
930929
931- fn matches_return_type (
932- & self ,
933- method : ty:: AssocItem ,
934- self_ty : Option < Ty < ' tcx > > ,
935- expected : Ty < ' tcx > ,
936- ) -> bool {
930+ fn matches_return_type ( & self , method : ty:: AssocItem , expected : Ty < ' tcx > ) -> bool {
937931 match method. kind {
938932 ty:: AssocKind :: Fn => self . probe ( |_| {
939933 let args = self . fresh_args_for_item ( self . span , method. def_id ) ;
940934 let fty = self . tcx . fn_sig ( method. def_id ) . instantiate ( self . tcx , args) ;
941935 let fty = self . instantiate_binder_with_fresh_vars ( self . span , infer:: FnCall , fty) ;
942-
943- if let Some ( self_ty) = self_ty {
944- if self
945- . at ( & ObligationCause :: dummy ( ) , self . param_env )
946- . sup ( DefineOpaqueTypes :: No , fty. inputs ( ) [ 0 ] , self_ty)
947- . is_err ( )
948- {
949- return false ;
950- }
951- }
952936 self . can_sub ( self . param_env , fty. output ( ) , expected)
953937 } ) ,
954938 _ => false ,
@@ -1039,7 +1023,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
10391023 . filter ( |candidate| candidate_filter ( & candidate. item ) )
10401024 . filter ( |candidate| {
10411025 if let Some ( return_ty) = self . return_type {
1042- self . matches_return_type ( candidate. item , None , return_ty)
1026+ self . matches_return_type ( candidate. item , return_ty)
10431027 } else {
10441028 true
10451029 }
@@ -1893,40 +1877,13 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
18931877 fn_sig. instantiate ( self . tcx , args)
18941878 } ;
18951879
1896- self . instantiate_bound_regions_with_erased ( xform_fn_sig)
1880+ self . tcx . instantiate_bound_regions_with_erased ( xform_fn_sig)
18971881 }
18981882
18991883 /// Gets the type of an impl and generate generic parameters with inference vars.
1900- fn impl_ty_and_args (
1901- & self ,
1902- impl_def_id : DefId ,
1903- ) -> ( ty:: EarlyBinder < Ty < ' tcx > > , GenericArgsRef < ' tcx > ) {
1904- ( self . tcx . type_of ( impl_def_id) , self . fresh_args_for_item ( self . span , impl_def_id) )
1905- }
1906-
1907- /// Replaces late-bound-regions bound by `value` with `'static` using
1908- /// `ty::instantiate_bound_regions_with_erased`.
1909- ///
1910- /// This is only a reasonable thing to do during the *probe* phase, not the *confirm* phase, of
1911- /// method matching. It is reasonable during the probe phase because we don't consider region
1912- /// relationships at all. Therefore, we can just replace all the region variables with 'static
1913- /// rather than creating fresh region variables. This is nice for two reasons:
1914- ///
1915- /// 1. Because the numbers of the region variables would otherwise be fairly unique to this
1916- /// particular method call, it winds up creating fewer types overall, which helps for memory
1917- /// usage. (Admittedly, this is a rather small effect, though measurable.)
1918- ///
1919- /// 2. It makes it easier to deal with higher-ranked trait bounds, because we can replace any
1920- /// late-bound regions with 'static. Otherwise, if we were going to replace late-bound
1921- /// regions with actual region variables as is proper, we'd have to ensure that the same
1922- /// region got replaced with the same variable, which requires a bit more coordination
1923- /// and/or tracking the instantiations and
1924- /// so forth.
1925- fn instantiate_bound_regions_with_erased < T > ( & self , value : ty:: Binder < ' tcx , T > ) -> T
1926- where
1927- T : TypeFoldable < TyCtxt < ' tcx > > ,
1928- {
1929- self . tcx . instantiate_bound_regions_with_erased ( value)
1884+ fn impl_ty_and_args ( & self , impl_def_id : DefId ) -> ( Ty < ' tcx > , GenericArgsRef < ' tcx > ) {
1885+ let args = self . fresh_args_for_item ( self . span , impl_def_id) ;
1886+ ( self . tcx . type_of ( impl_def_id) . instantiate ( self . tcx , args) , args)
19301887 }
19311888
19321889 /// Determine if the given associated item type is relevant in the current context.
0 commit comments