@@ -20,7 +20,7 @@ use rustc_middle::ty::fast_reject::{simplify_type, TreatParams};
20
20
use rustc_middle:: ty:: AssocItem ;
21
21
use rustc_middle:: ty:: GenericParamDefKind ;
22
22
use 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 } ;
24
24
use rustc_middle:: ty:: { GenericArgs , GenericArgsRef } ;
25
25
use rustc_session:: lint;
26
26
use rustc_span:: def_id:: DefId ;
@@ -744,7 +744,6 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
744
744
}
745
745
746
746
let ( impl_ty, impl_args) = self . impl_ty_and_args ( impl_def_id) ;
747
- let impl_ty = impl_ty. instantiate ( self . tcx , impl_args) ;
748
747
749
748
debug ! ( "impl_ty: {:?}" , impl_ty) ;
750
749
@@ -817,7 +816,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
817
816
return ;
818
817
}
819
818
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) ;
821
820
822
821
let ( xform_self_ty, xform_ret_ty) =
823
822
this. xform_self_ty ( item, new_trait_ref. self_ty ( ) , new_trait_ref. args ) ;
@@ -928,27 +927,12 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
928
927
}
929
928
}
930
929
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 {
937
931
match method. kind {
938
932
ty:: AssocKind :: Fn => self . probe ( |_| {
939
933
let args = self . fresh_args_for_item ( self . span , method. def_id ) ;
940
934
let fty = self . tcx . fn_sig ( method. def_id ) . instantiate ( self . tcx , args) ;
941
935
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
- }
952
936
self . can_sub ( self . param_env , fty. output ( ) , expected)
953
937
} ) ,
954
938
_ => false ,
@@ -1039,7 +1023,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
1039
1023
. filter ( |candidate| candidate_filter ( & candidate. item ) )
1040
1024
. filter ( |candidate| {
1041
1025
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)
1043
1027
} else {
1044
1028
true
1045
1029
}
@@ -1893,40 +1877,13 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
1893
1877
fn_sig. instantiate ( self . tcx , args)
1894
1878
} ;
1895
1879
1896
- self . instantiate_bound_regions_with_erased ( xform_fn_sig)
1880
+ self . tcx . instantiate_bound_regions_with_erased ( xform_fn_sig)
1897
1881
}
1898
1882
1899
1883
/// 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)
1930
1887
}
1931
1888
1932
1889
/// Determine if the given associated item type is relevant in the current context.
0 commit comments