@@ -21,7 +21,7 @@ use rustc_middle::ty::fast_reject::{simplify_type, TreatParams};
2121use rustc_middle:: ty:: AssocItem ;
2222use rustc_middle:: ty:: GenericParamDefKind ;
2323use rustc_middle:: ty:: ToPredicate ;
24- use rustc_middle:: ty:: { self , ParamEnvAnd , Ty , TyCtxt , TypeFoldable , TypeVisitableExt } ;
24+ use rustc_middle:: ty:: { self , ParamEnvAnd , Ty , TyCtxt , TypeVisitableExt } ;
2525use rustc_middle:: ty:: { GenericArgs , GenericArgsRef } ;
2626use rustc_session:: lint;
2727use rustc_span:: def_id:: DefId ;
@@ -738,7 +738,6 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
738738 }
739739
740740 let ( impl_ty, impl_args) = self . impl_ty_and_args ( impl_def_id) ;
741- let impl_ty = impl_ty. instantiate ( self . tcx , impl_args) ;
742741
743742 debug ! ( "impl_ty: {:?}" , impl_ty) ;
744743
@@ -811,7 +810,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
811810 return ;
812811 }
813812
814- let new_trait_ref = this. instantiate_bound_regions_with_erased ( new_trait_ref) ;
813+ let new_trait_ref = this. tcx . instantiate_bound_regions_with_erased ( new_trait_ref) ;
815814
816815 let ( xform_self_ty, xform_ret_ty) =
817816 this. xform_self_ty ( item, new_trait_ref. self_ty ( ) , new_trait_ref. args ) ;
@@ -922,27 +921,12 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
922921 }
923922 }
924923
925- fn matches_return_type (
926- & self ,
927- method : ty:: AssocItem ,
928- self_ty : Option < Ty < ' tcx > > ,
929- expected : Ty < ' tcx > ,
930- ) -> bool {
924+ fn matches_return_type ( & self , method : ty:: AssocItem , expected : Ty < ' tcx > ) -> bool {
931925 match method. kind {
932926 ty:: AssocKind :: Fn => self . probe ( |_| {
933927 let args = self . fresh_args_for_item ( self . span , method. def_id ) ;
934928 let fty = self . tcx . fn_sig ( method. def_id ) . instantiate ( self . tcx , args) ;
935929 let fty = self . instantiate_binder_with_fresh_vars ( self . span , infer:: FnCall , fty) ;
936-
937- if let Some ( self_ty) = self_ty {
938- if self
939- . at ( & ObligationCause :: dummy ( ) , self . param_env )
940- . sup ( DefineOpaqueTypes :: No , fty. inputs ( ) [ 0 ] , self_ty)
941- . is_err ( )
942- {
943- return false ;
944- }
945- }
946930 self . can_sub ( self . param_env , fty. output ( ) , expected)
947931 } ) ,
948932 _ => false ,
@@ -1033,7 +1017,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
10331017 . filter ( |candidate| candidate_filter ( & candidate. item ) )
10341018 . filter ( |candidate| {
10351019 if let Some ( return_ty) = self . return_type {
1036- self . matches_return_type ( candidate. item , None , return_ty)
1020+ self . matches_return_type ( candidate. item , return_ty)
10371021 } else {
10381022 true
10391023 }
@@ -1890,40 +1874,13 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
18901874 fn_sig. instantiate ( self . tcx , args)
18911875 } ;
18921876
1893- self . instantiate_bound_regions_with_erased ( xform_fn_sig)
1877+ self . tcx . instantiate_bound_regions_with_erased ( xform_fn_sig)
18941878 }
18951879
18961880 /// Gets the type of an impl and generate generic parameters with inference vars.
1897- fn impl_ty_and_args (
1898- & self ,
1899- impl_def_id : DefId ,
1900- ) -> ( ty:: EarlyBinder < Ty < ' tcx > > , GenericArgsRef < ' tcx > ) {
1901- ( self . tcx . type_of ( impl_def_id) , self . fresh_args_for_item ( self . span , impl_def_id) )
1902- }
1903-
1904- /// Replaces late-bound-regions bound by `value` with `'static` using
1905- /// `ty::instantiate_bound_regions_with_erased`.
1906- ///
1907- /// This is only a reasonable thing to do during the *probe* phase, not the *confirm* phase, of
1908- /// method matching. It is reasonable during the probe phase because we don't consider region
1909- /// relationships at all. Therefore, we can just replace all the region variables with 'static
1910- /// rather than creating fresh region variables. This is nice for two reasons:
1911- ///
1912- /// 1. Because the numbers of the region variables would otherwise be fairly unique to this
1913- /// particular method call, it winds up creating fewer types overall, which helps for memory
1914- /// usage. (Admittedly, this is a rather small effect, though measurable.)
1915- ///
1916- /// 2. It makes it easier to deal with higher-ranked trait bounds, because we can replace any
1917- /// late-bound regions with 'static. Otherwise, if we were going to replace late-bound
1918- /// regions with actual region variables as is proper, we'd have to ensure that the same
1919- /// region got replaced with the same variable, which requires a bit more coordination
1920- /// and/or tracking the instantiations and
1921- /// so forth.
1922- fn instantiate_bound_regions_with_erased < T > ( & self , value : ty:: Binder < ' tcx , T > ) -> T
1923- where
1924- T : TypeFoldable < TyCtxt < ' tcx > > ,
1925- {
1926- self . tcx . instantiate_bound_regions_with_erased ( value)
1881+ fn impl_ty_and_args ( & self , impl_def_id : DefId ) -> ( Ty < ' tcx > , GenericArgsRef < ' tcx > ) {
1882+ let args = self . fresh_args_for_item ( self . span , impl_def_id) ;
1883+ ( self . tcx . type_of ( impl_def_id) . instantiate ( self . tcx , args) , args)
19271884 }
19281885
19291886 /// Determine if the given associated item type is relevant in the current context.
0 commit comments