@@ -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 ;
@@ -745,7 +745,6 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
745
745
}
746
746
747
747
let ( impl_ty, impl_args) = self . impl_ty_and_args ( impl_def_id) ;
748
- let impl_ty = impl_ty. instantiate ( self . tcx , impl_args) ;
749
748
750
749
debug ! ( "impl_ty: {:?}" , impl_ty) ;
751
750
@@ -818,7 +817,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
818
817
return ;
819
818
}
820
819
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) ;
822
821
823
822
let ( xform_self_ty, xform_ret_ty) =
824
823
this. xform_self_ty ( item, new_trait_ref. self_ty ( ) , new_trait_ref. args ) ;
@@ -929,27 +928,12 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
929
928
}
930
929
}
931
930
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 {
938
932
match method. kind {
939
933
ty:: AssocKind :: Fn => self . probe ( |_| {
940
934
let args = self . fresh_args_for_item ( self . span , method. def_id ) ;
941
935
let fty = self . tcx . fn_sig ( method. def_id ) . instantiate ( self . tcx , args) ;
942
936
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
- }
953
937
self . can_sub ( self . param_env , fty. output ( ) , expected)
954
938
} ) ,
955
939
_ => false ,
@@ -1040,7 +1024,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
1040
1024
. filter ( |candidate| candidate_filter ( & candidate. item ) )
1041
1025
. filter ( |candidate| {
1042
1026
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)
1044
1028
} else {
1045
1029
true
1046
1030
}
@@ -1894,40 +1878,13 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
1894
1878
fn_sig. instantiate ( self . tcx , args)
1895
1879
} ;
1896
1880
1897
- self . instantiate_bound_regions_with_erased ( xform_fn_sig)
1881
+ self . tcx . instantiate_bound_regions_with_erased ( xform_fn_sig)
1898
1882
}
1899
1883
1900
1884
/// 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)
1931
1888
}
1932
1889
1933
1890
/// Determine if the given associated item type is relevant in the current context.
0 commit comments