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