3737//! also be emitted during HIR ty lowering.
3838
3939use std:: iter;
40+ use std:: marker:: PhantomData ;
4041
4142use ast:: visit:: Visitor ;
4243use hir:: def:: { DefKind , PartialRes , Res } ;
@@ -51,7 +52,7 @@ use rustc_hir as hir;
5152use rustc_hir:: attrs:: { AttributeKind , InlineAttr } ;
5253use rustc_hir:: def_id:: { DefId , LocalDefId } ;
5354use rustc_middle:: span_bug;
54- use rustc_middle:: ty:: { Asyncness , DelegationAttrs , DelegationFnSigAttrs , ResolverAstLowering } ;
55+ use rustc_middle:: ty:: { Asyncness , DelegationAttrs , DelegationFnSigAttrs } ;
5556use rustc_span:: symbol:: kw;
5657use rustc_span:: { DUMMY_SP , Ident , Span , Symbol } ;
5758use smallvec:: SmallVec ;
@@ -134,16 +135,14 @@ impl DelegationIds {
134135 }
135136}
136137
137- impl < ' hir > LoweringContext < ' _ , ' hir > {
138+ impl < ' hir , R : ResolverAstLoweringExt < ' hir > > LoweringContext < ' _ , ' hir , R > {
138139 fn is_method ( & self , def_id : DefId , span : Span ) -> bool {
139140 match self . tcx . def_kind ( def_id) {
140141 DefKind :: Fn => false ,
141142 DefKind :: AssocFn => match def_id. as_local ( ) {
142- Some ( local_def_id) => self
143- . resolver
144- . delegation_fn_sigs
145- . get ( & local_def_id)
146- . is_some_and ( |sig| sig. has_self ) ,
143+ Some ( local_def_id) => {
144+ self . resolver . delegation_fn_sig ( local_def_id) . is_some_and ( |sig| sig. has_self )
145+ }
147146 None => self . tcx . associated_item ( def_id) . is_method ( ) ,
148147 } ,
149148 _ => span_bug ! ( span, "unexpected DefKind for delegation item" ) ,
@@ -159,7 +158,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
159158
160159 // Delegation can be unresolved in illegal places such as function bodies in extern blocks (see #151356)
161160 let ids = if let Some ( delegation_info) =
162- self . resolver . delegation_infos . get ( & self . local_def_id ( item_id) )
161+ self . resolver . delegation_info ( self . local_def_id ( item_id) )
163162 {
164163 self . get_delegation_ids ( delegation_info. resolution_node , span)
165164 } else {
@@ -344,10 +343,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
344343
345344 fn get_attrs ( & self , local_id : LocalDefId ) -> & DelegationAttrs {
346345 // local_id can correspond either to a function or other delegation
347- if let Some ( fn_sig) = self . resolver . delegation_fn_sigs . get ( & local_id) {
346+ if let Some ( fn_sig) = self . resolver . delegation_fn_sig ( local_id) {
348347 & fn_sig. attrs
349348 } else {
350- & self . resolver . delegation_infos [ & local_id] . attrs
349+ & self . resolver . delegation_info ( local_id) . expect ( "processing delegation" ) . attrs
351350 }
352351 }
353352
@@ -378,7 +377,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
378377 // it means that we refer to another delegation as a callee, so in order to obtain
379378 // a signature DefId we obtain NodeId of the callee delegation and try to get signature from it.
380379 if let Some ( local_id) = def_id. as_local ( )
381- && let Some ( delegation_info) = self . resolver . delegation_infos . get ( & local_id)
380+ && let Some ( delegation_info) = self . resolver . delegation_info ( local_id)
382381 {
383382 node_id = delegation_info. resolution_node ;
384383 if visited. contains ( & node_id) {
@@ -402,7 +401,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
402401 // Function parameter count, including C variadic `...` if present.
403402 fn param_count ( & self , def_id : DefId ) -> ( usize , bool /*c_variadic*/ ) {
404403 if let Some ( local_sig_id) = def_id. as_local ( ) {
405- match self . resolver . delegation_fn_sigs . get ( & local_sig_id) {
404+ match self . resolver . delegation_fn_sig ( local_sig_id) {
406405 Some ( sig) => ( sig. param_count , sig. c_variadic ) ,
407406 None => ( 0 , false ) ,
408407 }
@@ -457,7 +456,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
457456 span : Span ,
458457 ) -> hir:: FnSig < ' hir > {
459458 let header = if let Some ( local_sig_id) = sig_id. as_local ( ) {
460- match self . resolver . delegation_fn_sigs . get ( & local_sig_id) {
459+ match self . resolver . delegation_fn_sig ( local_sig_id) {
461460 Some ( sig) => {
462461 let parent = self . tcx . parent ( sig_id) ;
463462 // HACK: we override the default safety instead of generating attributes from the ether.
@@ -573,6 +572,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
573572 resolver : this. resolver ,
574573 path_id : delegation. id ,
575574 self_param_id : pat_node_id,
575+ phantom : PhantomData ,
576576 } ;
577577 self_resolver. visit_block ( block) ;
578578 // Target expr needs to lower `self` path.
@@ -818,25 +818,26 @@ impl<'hir> LoweringContext<'_, 'hir> {
818818 }
819819}
820820
821- struct SelfResolver < ' a , ' tcx > {
822- resolver : & ' a mut ResolverAstLowering < ' tcx > ,
821+ struct SelfResolver < ' a , ' tcx , R > {
822+ resolver : & ' a mut R ,
823823 path_id : NodeId ,
824824 self_param_id : NodeId ,
825+ phantom : PhantomData < & ' tcx ( ) > ,
825826}
826827
827- impl SelfResolver < ' _ , ' _ > {
828+ impl < ' tcx , R : ResolverAstLoweringExt < ' tcx > > SelfResolver < ' _ , ' tcx , R > {
828829 fn try_replace_id ( & mut self , id : NodeId ) {
829- if let Some ( res) = self . resolver . partial_res_map . get ( & id)
830+ if let Some ( res) = self . resolver . get_partial_res ( id)
830831 && let Some ( Res :: Local ( sig_id) ) = res. full_res ( )
831832 && sig_id == self . path_id
832833 {
833834 let new_res = PartialRes :: new ( Res :: Local ( self . self_param_id ) ) ;
834- self . resolver . partial_res_map . insert ( id, new_res) ;
835+ self . resolver . insert_partial_res ( id, new_res) ;
835836 }
836837 }
837838}
838839
839- impl < ' ast , ' a > Visitor < ' ast > for SelfResolver < ' a , ' _ > {
840+ impl < ' ast , ' a , ' tcx , R : ResolverAstLoweringExt < ' tcx > > Visitor < ' ast > for SelfResolver < ' a , ' tcx , R > {
840841 fn visit_id ( & mut self , id : NodeId ) {
841842 self . try_replace_id ( id) ;
842843 }
0 commit comments