@@ -48,9 +48,11 @@ use rustc_data_structures::fx::FxHashSet;
4848use rustc_errors:: ErrorGuaranteed ;
4949use rustc_hir:: Target ;
5050use rustc_hir:: attrs:: { AttributeKind , InlineAttr } ;
51- use rustc_hir:: def_id:: DefId ;
51+ use rustc_hir:: def_id:: { DefId , LocalDefId } ;
5252use rustc_middle:: span_bug;
53- use rustc_middle:: ty:: { Asyncness , DelegationFnSigAttrs , ResolverAstLowering } ;
53+ use rustc_middle:: ty:: {
54+ Asyncness , DelegationFnSigAttrs , DelegationResolutionInfo , ResolverAstLowering ,
55+ } ;
5456use rustc_span:: symbol:: kw;
5557use rustc_span:: { DUMMY_SP , Ident , Span , Symbol } ;
5658use { rustc_ast as ast, rustc_hir as hir} ;
@@ -124,14 +126,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
124126 ) -> DelegationResults < ' hir > {
125127 let span = self . lower_span ( delegation. path . segments . last ( ) . unwrap ( ) . ident . span ) ;
126128
127- let sig_id = self . resolve_callee_sig (
128- self . resolver
129- . delegation_resolution_info
130- . get ( & self . local_def_id ( item_id) )
131- . unwrap ( )
132- . sig_resolution_id ,
133- span,
134- ) ;
129+ let sig_id = self
130+ . delegation_res_info_or_err ( & self . local_def_id ( item_id) , span)
131+ . map ( |info| self . get_delegation_sig_id ( info. sig_resolution_id , span) )
132+ . flatten ( ) ;
135133
136134 match sig_id {
137135 Ok ( sig_id) => {
@@ -246,7 +244,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
246244 }
247245 }
248246
249- fn resolve_callee_sig (
247+ fn get_delegation_sig_id (
250248 & self ,
251249 mut node_id : NodeId ,
252250 span : Span ,
@@ -265,31 +263,34 @@ impl<'hir> LoweringContext<'_, 'hir> {
265263 && let Some ( local_id) = def_id. as_local ( )
266264 && !self . resolver . delegation_fn_sigs . contains_key ( & local_id)
267265 {
268- if let Some ( info) = self . resolver . delegation_resolution_info . get ( & local_id) {
269- node_id = info. sig_resolution_id ;
270- if visited. contains ( & node_id) {
271- // We encountered a cycle in the resolution, or delegation callee refers to non-existent
272- // entity, in this case emit an error.
273- return Err ( self . dcx ( ) . emit_err ( UnresolvedDelegationCallee { span } ) ) ;
274- }
275-
276- continue ;
277- } else {
278- // The LocalDefId for some reason refers not to another delegation, in this case
279- // we will emit a bug (not an error), as we have to catch such cases on the resolve stage,
280- // during smart_resolve_path in resolve_delegation.
281- return Err ( self . tcx . dcx ( ) . span_delayed_bug ( span, format ! (
282- "There is no information about delegation resolution node id for LocalDefId {:?}" ,
283- local_id
284- ) ) ) ;
266+ node_id = self . delegation_res_info_or_err ( & local_id, span) ?. sig_resolution_id ;
267+ if visited. contains ( & node_id) {
268+ // We encountered a cycle in the resolution, or delegation callee refers to non-existent
269+ // entity, in this case emit an error.
270+ return Err ( self . dcx ( ) . emit_err ( UnresolvedDelegationCallee { span } ) ) ;
285271 }
272+
273+ continue ;
286274 }
287275
288276 // DefId is either None or is from non-local crate, fallback to the original routine.
289277 return self . def_id_or_guaranteed_err ( def_id, node_id, span) ;
290278 }
291279 }
292280
281+ fn delegation_res_info_or_err (
282+ & self ,
283+ local_id : & LocalDefId ,
284+ span : Span ,
285+ ) -> Result < & DelegationResolutionInfo , ErrorGuaranteed > {
286+ self . resolver . delegation_resolution_info . get ( local_id) . ok_or_else ( || {
287+ self . tcx . dcx ( ) . span_delayed_bug ( span, format ! (
288+ "There is no information about delegation resolution node id for LocalDefId {:?}" ,
289+ local_id
290+ ) )
291+ } )
292+ }
293+
293294 fn opt_get_partial_res_id ( & self , node_id : NodeId ) -> Option < DefId > {
294295 self . resolver . get_partial_res ( node_id) . and_then ( |r| r. expect_full_res ( ) . opt_def_id ( ) )
295296 }
@@ -326,8 +327,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
326327 // Function parameter count, including C variadic `...` if present.
327328 fn param_count ( & self , sig_id : DefId ) -> ( usize , bool /*c_variadic*/ ) {
328329 if let Some ( local_sig_id) = sig_id. as_local ( ) {
329- // Map may be filled incorrectly due to recursive delegation.
330- // Error will be emitted later during HIR ty lowering.
331330 match self . resolver . delegation_fn_sigs . get ( & local_sig_id) {
332331 Some ( sig) => ( sig. param_count , sig. c_variadic ) ,
333332 None => ( 0 , false ) ,
0 commit comments