@@ -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 ;
@@ -745,7 +745,6 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
745745 }
746746
747747 let ( impl_ty, impl_args) = self . impl_ty_and_args ( impl_def_id) ;
748- let impl_ty = impl_ty. instantiate ( self . tcx , impl_args) ;
749748
750749 debug ! ( "impl_ty: {:?}" , impl_ty) ;
751750
@@ -818,7 +817,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
818817 return ;
819818 }
820819
821- let new_trait_ref = this. instantiate_bound_regions_with_erased ( new_trait_ref) ;
820+ let new_trait_ref = this. tcx . instantiate_bound_regions_with_erased ( new_trait_ref) ;
822821
823822 let ( xform_self_ty, xform_ret_ty) =
824823 this. xform_self_ty ( item, new_trait_ref. self_ty ( ) , new_trait_ref. args ) ;
@@ -929,27 +928,12 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
929928 }
930929 }
931930
932- fn matches_return_type (
933- & self ,
934- method : ty:: AssocItem ,
935- self_ty : Option < Ty < ' tcx > > ,
936- expected : Ty < ' tcx > ,
937- ) -> bool {
931+ fn matches_return_type ( & self , method : ty:: AssocItem , expected : Ty < ' tcx > ) -> bool {
938932 match method. kind {
939933 ty:: AssocKind :: Fn => self . probe ( |_| {
940934 let args = self . fresh_args_for_item ( self . span , method. def_id ) ;
941935 let fty = self . tcx . fn_sig ( method. def_id ) . instantiate ( self . tcx , args) ;
942936 let fty = self . instantiate_binder_with_fresh_vars ( self . span , infer:: FnCall , fty) ;
943-
944- if let Some ( self_ty) = self_ty {
945- if self
946- . at ( & ObligationCause :: dummy ( ) , self . param_env )
947- . sup ( DefineOpaqueTypes :: No , fty. inputs ( ) [ 0 ] , self_ty)
948- . is_err ( )
949- {
950- return false ;
951- }
952- }
953937 self . can_sub ( self . param_env , fty. output ( ) , expected)
954938 } ) ,
955939 _ => false ,
@@ -1040,7 +1024,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
10401024 . filter ( |candidate| candidate_filter ( & candidate. item ) )
10411025 . filter ( |candidate| {
10421026 if let Some ( return_ty) = self . return_type {
1043- self . matches_return_type ( candidate. item , None , return_ty)
1027+ self . matches_return_type ( candidate. item , return_ty)
10441028 } else {
10451029 true
10461030 }
@@ -1894,40 +1878,13 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
18941878 fn_sig. instantiate ( self . tcx , args)
18951879 } ;
18961880
1897- self . instantiate_bound_regions_with_erased ( xform_fn_sig)
1881+ self . tcx . instantiate_bound_regions_with_erased ( xform_fn_sig)
18981882 }
18991883
19001884 /// Gets the type of an impl and generate generic parameters with inference vars.
1901- fn impl_ty_and_args (
1902- & self ,
1903- impl_def_id : DefId ,
1904- ) -> ( ty:: EarlyBinder < Ty < ' tcx > > , GenericArgsRef < ' tcx > ) {
1905- ( self . tcx . type_of ( impl_def_id) , self . fresh_args_for_item ( self . span , impl_def_id) )
1906- }
1907-
1908- /// Replaces late-bound-regions bound by `value` with `'static` using
1909- /// `ty::instantiate_bound_regions_with_erased`.
1910- ///
1911- /// This is only a reasonable thing to do during the *probe* phase, not the *confirm* phase, of
1912- /// method matching. It is reasonable during the probe phase because we don't consider region
1913- /// relationships at all. Therefore, we can just replace all the region variables with 'static
1914- /// rather than creating fresh region variables. This is nice for two reasons:
1915- ///
1916- /// 1. Because the numbers of the region variables would otherwise be fairly unique to this
1917- /// particular method call, it winds up creating fewer types overall, which helps for memory
1918- /// usage. (Admittedly, this is a rather small effect, though measurable.)
1919- ///
1920- /// 2. It makes it easier to deal with higher-ranked trait bounds, because we can replace any
1921- /// late-bound regions with 'static. Otherwise, if we were going to replace late-bound
1922- /// regions with actual region variables as is proper, we'd have to ensure that the same
1923- /// region got replaced with the same variable, which requires a bit more coordination
1924- /// and/or tracking the instantiations and
1925- /// so forth.
1926- fn instantiate_bound_regions_with_erased < T > ( & self , value : ty:: Binder < ' tcx , T > ) -> T
1927- where
1928- T : TypeFoldable < TyCtxt < ' tcx > > ,
1929- {
1930- self . tcx . instantiate_bound_regions_with_erased ( value)
1885+ fn impl_ty_and_args ( & self , impl_def_id : DefId ) -> ( Ty < ' tcx > , GenericArgsRef < ' tcx > ) {
1886+ let args = self . fresh_args_for_item ( self . span , impl_def_id) ;
1887+ ( self . tcx . type_of ( impl_def_id) . instantiate ( self . tcx , args) , args)
19311888 }
19321889
19331890 /// Determine if the given associated item type is relevant in the current context.
0 commit comments