1
1
use rustc_data_structures:: fx:: FxHashMap ;
2
+ use rustc_hir as hir;
2
3
use rustc_hir:: def:: DefKind ;
3
4
use rustc_hir:: def_id:: { DefId , LocalDefId } ;
5
+ use rustc_middle:: query:: Providers ;
4
6
use rustc_middle:: ty:: fold:: { TypeFoldable , TypeFolder , TypeSuperFoldable } ;
5
7
use rustc_middle:: ty:: { self , Ty , TyCtxt } ;
6
8
use rustc_span:: ErrorGuaranteed ;
@@ -217,7 +219,7 @@ fn check_constraints<'tcx>(
217
219
}
218
220
219
221
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 ( )
221
223
{
222
224
emit ( "recursive delegation is not supported yet" ) ;
223
225
}
@@ -242,7 +244,7 @@ pub(crate) fn inherit_sig_for_delegation_item<'tcx>(
242
244
tcx : TyCtxt < ' tcx > ,
243
245
def_id : LocalDefId ,
244
246
) -> & ' 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 ( ) ;
246
248
let caller_sig = tcx. fn_sig ( sig_id) ;
247
249
if let Err ( err) = check_constraints ( tcx, def_id, sig_id) {
248
250
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>(
257
259
let sig_iter = sig. inputs ( ) . iter ( ) . cloned ( ) . chain ( std:: iter:: once ( sig. output ( ) ) ) ;
258
260
tcx. arena . alloc_from_iter ( sig_iter)
259
261
}
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