@@ -1943,94 +1943,11 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
1943
1943
self . lower_ty_common ( hir_ty, false , true )
1944
1944
}
1945
1945
1946
- fn check_delegation_constraints ( & self , sig_id : DefId , span : Span , emit : bool ) -> bool {
1947
- let mut error_occured = false ;
1948
- let sig_span = self . tcx ( ) . def_span ( sig_id) ;
1949
- let mut try_emit = |descr| {
1950
- if emit {
1951
- self . tcx ( ) . dcx ( ) . emit_err ( crate :: errors:: NotSupportedDelegation {
1952
- span,
1953
- descr,
1954
- callee_span : sig_span,
1955
- } ) ;
1956
- }
1957
- error_occured = true ;
1958
- } ;
1959
-
1960
- if let Some ( node) = self . tcx ( ) . hir ( ) . get_if_local ( sig_id)
1961
- && let Some ( decl) = node. fn_decl ( )
1962
- && let hir:: FnRetTy :: Return ( ty) = decl. output
1963
- && let hir:: TyKind :: InferDelegation ( _, _) = ty. kind
1964
- {
1965
- try_emit ( "recursive delegation" ) ;
1966
- }
1967
-
1968
- let sig_generics = self . tcx ( ) . generics_of ( sig_id) ;
1969
- let parent = self . tcx ( ) . parent ( self . item_def_id ( ) ) ;
1970
- let parent_generics = self . tcx ( ) . generics_of ( parent) ;
1971
-
1972
- let parent_is_trait = ( self . tcx ( ) . def_kind ( parent) == DefKind :: Trait ) as usize ;
1973
- let sig_has_self = sig_generics. has_self as usize ;
1974
-
1975
- if sig_generics. count ( ) > sig_has_self || parent_generics. count ( ) > parent_is_trait {
1976
- try_emit ( "delegation with early bound generics" ) ;
1977
- }
1978
-
1979
- // There is no way to instantiate `Self` param for caller if
1980
- // 1. callee is a trait method
1981
- // 2. delegation item isn't an associative item
1982
- if let DefKind :: AssocFn = self . tcx ( ) . def_kind ( sig_id)
1983
- && let DefKind :: Fn = self . tcx ( ) . def_kind ( self . item_def_id ( ) )
1984
- && self . tcx ( ) . associated_item ( sig_id) . container
1985
- == ty:: AssocItemContainer :: TraitContainer
1986
- {
1987
- try_emit ( "delegation to a trait method from a free function" ) ;
1988
- }
1989
-
1990
- error_occured
1991
- }
1992
-
1993
- fn lower_delegation_ty (
1994
- & self ,
1995
- sig_id : DefId ,
1996
- idx : hir:: InferDelegationKind ,
1997
- span : Span ,
1998
- ) -> Ty < ' tcx > {
1999
- if self . check_delegation_constraints ( sig_id, span, idx == hir:: InferDelegationKind :: Output )
2000
- {
2001
- let e = self . tcx ( ) . dcx ( ) . span_delayed_bug ( span, "not supported delegation case" ) ;
2002
- self . set_tainted_by_errors ( e) ;
2003
- return Ty :: new_error ( self . tcx ( ) , e) ;
2004
- } ;
2005
- let sig = self . tcx ( ) . fn_sig ( sig_id) ;
2006
- let sig_generics = self . tcx ( ) . generics_of ( sig_id) ;
2007
-
2008
- let parent = self . tcx ( ) . parent ( self . item_def_id ( ) ) ;
2009
- let parent_def_kind = self . tcx ( ) . def_kind ( parent) ;
2010
-
2011
- let sig = if let DefKind :: Impl { .. } = parent_def_kind
2012
- && sig_generics. has_self
2013
- {
2014
- // Generic params can't be here except the trait self type.
2015
- // They are not supported yet.
2016
- assert_eq ! ( sig_generics. count( ) , 1 ) ;
2017
- assert_eq ! ( self . tcx( ) . generics_of( parent) . count( ) , 0 ) ;
2018
-
2019
- let self_ty = self . tcx ( ) . type_of ( parent) . instantiate_identity ( ) ;
2020
- let generic_self_ty = ty:: GenericArg :: from ( self_ty) ;
2021
- let args = self . tcx ( ) . mk_args_from_iter ( std:: iter:: once ( generic_self_ty) ) ;
2022
- sig. instantiate ( self . tcx ( ) , args)
2023
- } else {
2024
- sig. instantiate_identity ( )
2025
- } ;
2026
-
2027
- // Bound vars are also inherited from `sig_id`.
2028
- // They will be rebound later in `lower_fn_ty`.
2029
- let sig = sig. skip_binder ( ) ;
2030
-
1946
+ fn lower_delegation_ty ( & self , idx : hir:: InferDelegationKind ) -> Ty < ' tcx > {
1947
+ let delegation_res = self . tcx ( ) . resolve_delegation ( self . item_def_id ( ) . expect_local ( ) ) ;
2031
1948
match idx {
2032
- hir:: InferDelegationKind :: Input ( id ) => sig . inputs ( ) [ id ] ,
2033
- hir:: InferDelegationKind :: Output => sig . output ( ) ,
1949
+ hir:: InferDelegationKind :: Input ( idx ) => delegation_res . inputs [ idx ] ,
1950
+ hir:: InferDelegationKind :: Output => delegation_res . output ,
2034
1951
}
2035
1952
}
2036
1953
@@ -2047,9 +1964,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
2047
1964
let tcx = self . tcx ( ) ;
2048
1965
2049
1966
let result_ty = match & hir_ty. kind {
2050
- hir:: TyKind :: InferDelegation ( sig_id, idx) => {
2051
- self . lower_delegation_ty ( * sig_id, * idx, hir_ty. span )
2052
- }
1967
+ hir:: TyKind :: InferDelegation ( _, idx) => self . lower_delegation_ty ( * idx) ,
2053
1968
hir:: TyKind :: Slice ( ty) => Ty :: new_slice ( tcx, self . lower_ty ( ty) ) ,
2054
1969
hir:: TyKind :: Ptr ( mt) => Ty :: new_ptr ( tcx, self . lower_ty ( mt. ty ) , mt. mutbl ) ,
2055
1970
hir:: TyKind :: Ref ( region, mt) => {
0 commit comments