11use rustc_data_structures:: fx:: FxHashMap ;
2+ use rustc_hir as hir;
23use rustc_hir:: def:: DefKind ;
34use rustc_hir:: def_id:: { DefId , LocalDefId } ;
5+ use rustc_middle:: query:: Providers ;
46use rustc_middle:: ty:: fold:: { TypeFoldable , TypeFolder , TypeSuperFoldable } ;
57use rustc_middle:: ty:: { self , Ty , TyCtxt } ;
68use rustc_span:: ErrorGuaranteed ;
@@ -217,7 +219,7 @@ fn check_constraints<'tcx>(
217219 }
218220
219221 if let Some ( local_sig_id) = sig_id. as_local ( )
220- && tcx. hir ( ) . opt_delegation_sig_id ( local_sig_id) . is_some ( )
222+ && tcx. opt_delegation_sig_id ( local_sig_id) . is_some ( )
221223 {
222224 emit ( "recursive delegation is not supported yet" ) ;
223225 }
@@ -242,7 +244,7 @@ pub(crate) fn inherit_sig_for_delegation_item<'tcx>(
242244 tcx : TyCtxt < ' tcx > ,
243245 def_id : LocalDefId ,
244246) -> & ' tcx [ Ty < ' tcx > ] {
245- let sig_id = tcx. hir ( ) . delegation_sig_id ( def_id ) ;
247+ let sig_id = tcx. opt_delegation_sig_id ( def_id ) . unwrap ( ) ;
246248 let caller_sig = tcx. fn_sig ( sig_id) ;
247249 if let Err ( err) = check_constraints ( tcx, def_id, sig_id) {
248250 let sig_len = caller_sig. instantiate_identity ( ) . skip_binder ( ) . inputs ( ) . len ( ) + 1 ;
@@ -257,3 +259,17 @@ pub(crate) fn inherit_sig_for_delegation_item<'tcx>(
257259 let sig_iter = sig. inputs ( ) . iter ( ) . cloned ( ) . chain ( std:: iter:: once ( sig. output ( ) ) ) ;
258260 tcx. arena . alloc_from_iter ( sig_iter)
259261}
262+
263+ pub ( crate ) fn opt_delegation_sig_id < ' tcx > ( tcx : TyCtxt < ' tcx > , def_id : LocalDefId ) -> Option < DefId > {
264+ if let Some ( ret) = tcx. hir ( ) . get_fn_output ( def_id)
265+ && let hir:: FnRetTy :: Return ( ty) = ret
266+ && let hir:: TyKind :: InferDelegation ( sig_id, _) = ty. kind
267+ {
268+ return Some ( sig_id) ;
269+ }
270+ None
271+ }
272+
273+ pub fn provide ( providers : & mut Providers ) {
274+ * providers = Providers { inherit_sig_for_delegation_item, opt_delegation_sig_id, ..* providers } ;
275+ }
0 commit comments