@@ -21,7 +21,7 @@ use rustc_middle::ty::fast_reject::{simplify_type, TreatParams};
21
21
use rustc_middle:: ty:: AssocItem ;
22
22
use rustc_middle:: ty:: GenericParamDefKind ;
23
23
use 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 } ;
25
25
use rustc_middle:: ty:: { GenericArgs , GenericArgsRef } ;
26
26
use rustc_session:: lint;
27
27
use rustc_span:: def_id:: DefId ;
@@ -738,7 +738,6 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
738
738
}
739
739
740
740
let ( impl_ty, impl_args) = self . impl_ty_and_args ( impl_def_id) ;
741
- let impl_ty = impl_ty. instantiate ( self . tcx , impl_args) ;
742
741
743
742
debug ! ( "impl_ty: {:?}" , impl_ty) ;
744
743
@@ -811,7 +810,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
811
810
return ;
812
811
}
813
812
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) ;
815
814
816
815
let ( xform_self_ty, xform_ret_ty) =
817
816
this. xform_self_ty ( item, new_trait_ref. self_ty ( ) , new_trait_ref. args ) ;
@@ -922,27 +921,12 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
922
921
}
923
922
}
924
923
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 {
931
925
match method. kind {
932
926
ty:: AssocKind :: Fn => self . probe ( |_| {
933
927
let args = self . fresh_args_for_item ( self . span , method. def_id ) ;
934
928
let fty = self . tcx . fn_sig ( method. def_id ) . instantiate ( self . tcx , args) ;
935
929
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
- }
946
930
self . can_sub ( self . param_env , fty. output ( ) , expected)
947
931
} ) ,
948
932
_ => false ,
@@ -1033,7 +1017,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
1033
1017
. filter ( |candidate| candidate_filter ( & candidate. item ) )
1034
1018
. filter ( |candidate| {
1035
1019
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)
1037
1021
} else {
1038
1022
true
1039
1023
}
@@ -1890,40 +1874,13 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
1890
1874
fn_sig. instantiate ( self . tcx , args)
1891
1875
} ;
1892
1876
1893
- self . instantiate_bound_regions_with_erased ( xform_fn_sig)
1877
+ self . tcx . instantiate_bound_regions_with_erased ( xform_fn_sig)
1894
1878
}
1895
1879
1896
1880
/// 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)
1927
1884
}
1928
1885
1929
1886
/// Determine if the given associated item type is relevant in the current context.
0 commit comments