@@ -56,9 +56,8 @@ use rustc_hir::{
5656 LifetimeSyntax , ParamName , Target , TraitCandidate , find_attr,
5757} ;
5858use rustc_index:: { Idx , IndexSlice , IndexVec } ;
59- use rustc_macros:: extension;
6059use rustc_middle:: span_bug;
61- use rustc_middle:: ty:: { DelegationFnSig , DelegationInfo , ResolverAstLowering , TyCtxt } ;
60+ use rustc_middle:: ty:: { ResolverAstLowering , TyCtxt } ;
6261use rustc_session:: parse:: add_feature_diagnostics;
6362use rustc_span:: symbol:: { Ident , Symbol , kw, sym} ;
6463use rustc_span:: { DUMMY_SP , DesugaringKind , Span } ;
@@ -257,60 +256,20 @@ struct CombinedResolverAstLowering<'a, 'tcx> {
257256 mut_part : MutableResolverAstLowering ,
258257}
259258
260- impl ResolverAstLoweringExt for CombinedResolverAstLowering < ' _ , ' _ > {
259+ impl CombinedResolverAstLowering < ' _ , ' _ > {
261260 #[ inline]
262- fn legacy_const_generic_args ( & self , expr : & Expr , tcx : TyCtxt < ' _ > ) -> Option < Vec < usize > > {
263- self . base . legacy_const_generic_args ( expr, tcx)
264- }
265-
266- #[ inline]
267- fn get_partial_res ( & self , id : NodeId ) -> Option < PartialRes > {
268- self . mut_part . partial_res_map . get ( & id) . cloned ( ) . or_else ( || self . base . get_partial_res ( id) )
269- }
270-
271- #[ inline]
272- fn get_import_res ( & self , id : NodeId ) -> Option < & PerNS < Option < Res < NodeId > > > > {
273- self . base . get_import_res ( id)
274- }
275-
276- #[ inline]
277- fn get_label_res ( & self , id : NodeId ) -> Option < NodeId > {
278- self . base . get_label_res ( id)
279- }
280-
281- #[ inline]
282- fn get_lifetime_res ( & self , id : NodeId ) -> Option < LifetimeRes > {
283- self . base . get_lifetime_res ( id)
284- }
261+ fn get_partial_res ( & self , id : NodeId ) -> Option < & PartialRes > {
262+ let base_res = self . base . partial_res_map . get ( & id) ;
285263
286- #[ inline]
287- fn extra_lifetime_params ( & self , id : NodeId ) -> Option < & Vec < ( Ident , NodeId , LifetimeRes ) > > {
288- self . base . extra_lifetime_params ( id)
289- }
290-
291- #[ inline]
292- fn delegation_fn_sig ( & self , id : LocalDefId ) -> Option < & DelegationFnSig > {
293- self . base . delegation_fn_sig ( id)
294- }
295-
296- #[ inline]
297- fn delegation_info ( & self , id : LocalDefId ) -> Option < & DelegationInfo > {
298- self . base . delegation_info ( id)
299- }
300-
301- #[ inline]
302- fn def_id ( & self , id : NodeId ) -> Option < LocalDefId > {
303- self . mut_part . node_id_to_def_id . get ( & id) . copied ( ) . or_else ( || self . base . def_id ( id) )
304- }
264+ // Partial res map is modified only in delegation for now, so it will
265+ // be empty most of the time.
266+ if self . mut_part . partial_res_map . is_empty ( ) {
267+ return base_res;
268+ }
305269
306- #[ inline]
307- fn lifetime_elision_allowed ( & self , id : NodeId ) -> bool {
308- self . base . lifetime_elision_allowed ( id)
270+ self . mut_part . partial_res_map . get ( & id) . or ( base_res)
309271 }
310- }
311272
312- #[ extension( trait ResolverAstLoweringExt ) ]
313- impl ResolverAstLowering < ' _ > {
314273 fn legacy_const_generic_args ( & self , expr : & Expr , tcx : TyCtxt < ' _ > ) -> Option < Vec < usize > > {
315274 let ExprKind :: Path ( None , path) = & expr. kind else {
316275 return None ;
@@ -339,27 +298,10 @@ impl ResolverAstLowering<'_> {
339298 . map ( |fn_indexes| fn_indexes. iter ( ) . map ( |( num, _) | * num) . collect ( ) )
340299 }
341300
342- #[ inline]
343- fn get_partial_res ( & self , id : NodeId ) -> Option < PartialRes > {
344- self . partial_res_map . get ( & id) . copied ( )
345- }
346-
347- /// Obtains per-namespace resolutions for `use` statement with the given `NodeId`.
348- #[ inline]
349- fn get_import_res ( & self , id : NodeId ) -> Option < & PerNS < Option < Res < NodeId > > > > {
350- self . import_res_map . get ( & id)
351- }
352-
353- /// Obtains resolution for a label with the given `NodeId`.
354- #[ inline]
355- fn get_label_res ( & self , id : NodeId ) -> Option < NodeId > {
356- self . label_res_map . get ( & id) . copied ( )
357- }
358-
359301 /// Obtains resolution for a lifetime with the given `NodeId`.
360302 #[ inline]
361303 fn get_lifetime_res ( & self , id : NodeId ) -> Option < LifetimeRes > {
362- self . lifetimes_res_map . get ( & id) . copied ( )
304+ self . base . lifetimes_res_map . get ( & id) . copied ( )
363305 }
364306
365307 /// Obtain the list of lifetimes parameters to add to an item.
@@ -370,28 +312,8 @@ impl ResolverAstLowering<'_> {
370312 /// The extra lifetimes that appear from the parenthesized `Fn`-trait desugaring
371313 /// should appear at the enclosing `PolyTraitRef`.
372314 #[ inline]
373- fn extra_lifetime_params ( & self , id : NodeId ) -> Option < & Vec < ( Ident , NodeId , LifetimeRes ) > > {
374- self . extra_lifetime_params_map . get ( & id)
375- }
376-
377- #[ inline]
378- fn delegation_fn_sig ( & self , id : LocalDefId ) -> Option < & DelegationFnSig > {
379- self . delegation_fn_sigs . get ( & id)
380- }
381-
382- #[ inline]
383- fn delegation_info ( & self , id : LocalDefId ) -> Option < & DelegationInfo > {
384- self . delegation_infos . get ( & id)
385- }
386-
387- #[ inline]
388- fn def_id ( & self , id : NodeId ) -> Option < LocalDefId > {
389- self . node_id_to_def_id . get ( & id) . copied ( )
390- }
391-
392- #[ inline]
393- fn lifetime_elision_allowed ( & self , id : NodeId ) -> bool {
394- self . lifetime_elision_allowed . contains ( & id)
315+ fn extra_lifetime_params ( & self , id : NodeId ) -> Vec < ( Ident , NodeId , LifetimeRes ) > {
316+ self . base . extra_lifetime_params_map . get ( & id) . cloned ( ) . unwrap_or_default ( )
395317 }
396318}
397319
@@ -712,7 +634,12 @@ impl<'hir> LoweringContext<'_, '_, 'hir> {
712634 /// Given the id of some node in the AST, finds the `LocalDefId` associated with it by the name
713635 /// resolver (if any).
714636 fn opt_local_def_id ( & self , node : NodeId ) -> Option < LocalDefId > {
715- self . resolver . def_id ( node)
637+ // We are only inserting new ids, not rewriting already existent.
638+ if let Some ( & def_id) = self . resolver . base . node_id_to_def_id . get ( & node) {
639+ return Some ( def_id) ;
640+ }
641+
642+ self . resolver . mut_part . node_id_to_def_id . get ( & node) . copied ( )
716643 }
717644
718645 fn local_def_id ( & self , node : NodeId ) -> LocalDefId {
@@ -887,7 +814,7 @@ impl<'hir> LoweringContext<'_, '_, 'hir> {
887814 }
888815
889816 fn lower_import_res ( & mut self , id : NodeId , span : Span ) -> PerNS < Option < Res > > {
890- let per_ns = self . resolver . get_import_res ( id) . copied ( ) . unwrap_or_default ( ) ;
817+ let per_ns = self . resolver . base . import_res_map . get ( & id) . copied ( ) . unwrap_or_default ( ) ;
891818 let per_ns = per_ns. map ( |res| res. map ( |res| self . lower_res ( res) ) ) ;
892819 if per_ns. is_empty ( ) {
893820 // Propagate the error to all namespaces, just to be sure.
@@ -1019,8 +946,7 @@ impl<'hir> LoweringContext<'_, '_, 'hir> {
1019946 ) -> & ' hir [ hir:: GenericParam < ' hir > ] {
1020947 // Start by creating params for extra lifetimes params, as this creates the definitions
1021948 // that may be referred to by the AST inside `generic_params`.
1022- let extra_lifetimes =
1023- self . resolver . extra_lifetime_params ( binder) . cloned ( ) . unwrap_or_default ( ) ;
949+ let extra_lifetimes = self . resolver . extra_lifetime_params ( binder) ;
1024950 debug ! ( ?extra_lifetimes) ;
1025951 let extra_lifetimes: Vec < _ > = extra_lifetimes
1026952 . into_iter ( )
@@ -1859,7 +1785,11 @@ impl<'hir> LoweringContext<'_, '_, 'hir> {
18591785 inputs,
18601786 output,
18611787 c_variadic,
1862- lifetime_elision_allowed : self . resolver . lifetime_elision_allowed ( fn_node_id) ,
1788+ lifetime_elision_allowed : self
1789+ . resolver
1790+ . base
1791+ . lifetime_elision_allowed
1792+ . contains ( & fn_node_id) ,
18631793 implicit_self : decl. inputs . get ( 0 ) . map_or ( hir:: ImplicitSelfKind :: None , |arg| {
18641794 let is_mutable_pat = matches ! (
18651795 arg. pat. kind,
0 commit comments