@@ -58,7 +58,6 @@ use rustc_hir::{
58
58
TraitCandidate ,
59
59
} ;
60
60
use rustc_index:: { Idx , IndexSlice , IndexVec } ;
61
- use rustc_macros:: extension;
62
61
use rustc_middle:: span_bug;
63
62
use rustc_middle:: ty:: { ResolverAstLowering , TyCtxt } ;
64
63
use rustc_session:: parse:: { add_feature_diagnostics, feature_err} ;
@@ -92,7 +91,7 @@ rustc_fluent_macro::fluent_messages! { "../messages.ftl" }
92
91
93
92
struct LoweringContext < ' a , ' hir > {
94
93
tcx : TyCtxt < ' hir > ,
95
- resolver : & ' a mut ResolverAstLowering ,
94
+ resolver : PerOwnerResolver < ' a > ,
96
95
97
96
/// Used to allocate HIR nodes.
98
97
arena : & ' hir hir:: Arena < ' hir > ,
@@ -152,7 +151,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
152
151
Self {
153
152
// Pseudo-globals.
154
153
tcx,
155
- resolver,
154
+ resolver : PerOwnerResolver { general : resolver } ,
156
155
arena : tcx. hir_arena ,
157
156
158
157
// HirId handling.
@@ -200,8 +199,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
200
199
}
201
200
}
202
201
203
- #[ extension( trait ResolverAstLoweringExt ) ]
204
- impl ResolverAstLowering {
202
+ pub ( crate ) struct PerOwnerResolver < ' a > {
203
+ pub general : & ' a mut ResolverAstLowering ,
204
+ }
205
+
206
+ impl PerOwnerResolver < ' _ > {
205
207
fn legacy_const_generic_args ( & self , expr : & Expr ) -> Option < Vec < usize > > {
206
208
if let ExprKind :: Path ( None , path) = & expr. kind {
207
209
// Don't perform legacy const generics rewriting if the path already
@@ -210,15 +212,17 @@ impl ResolverAstLowering {
210
212
return None ;
211
213
}
212
214
213
- if let Res :: Def ( DefKind :: Fn , def_id) = self . partial_res_map . get ( & expr. id ) ?. full_res ( ) ? {
215
+ if let Res :: Def ( DefKind :: Fn , def_id) =
216
+ self . general . partial_res_map . get ( & expr. id ) ?. full_res ( ) ?
217
+ {
214
218
// We only support cross-crate argument rewriting. Uses
215
219
// within the same crate should be updated to use the new
216
220
// const generics style.
217
221
if def_id. is_local ( ) {
218
222
return None ;
219
223
}
220
224
221
- if let Some ( v) = self . legacy_const_generic_args . get ( & def_id) {
225
+ if let Some ( v) = self . general . legacy_const_generic_args . get ( & def_id) {
222
226
return v. clone ( ) ;
223
227
}
224
228
}
@@ -228,22 +232,22 @@ impl ResolverAstLowering {
228
232
}
229
233
230
234
fn get_partial_res ( & self , id : NodeId ) -> Option < PartialRes > {
231
- self . partial_res_map . get ( & id) . copied ( )
235
+ self . general . partial_res_map . get ( & id) . copied ( )
232
236
}
233
237
234
238
/// Obtains per-namespace resolutions for `use` statement with the given `NodeId`.
235
239
fn get_import_res ( & self , id : NodeId ) -> PerNS < Option < Res < NodeId > > > {
236
- self . import_res_map . get ( & id) . copied ( ) . unwrap_or_default ( )
240
+ self . general . import_res_map . get ( & id) . copied ( ) . unwrap_or_default ( )
237
241
}
238
242
239
243
/// Obtains resolution for a label with the given `NodeId`.
240
244
fn get_label_res ( & self , id : NodeId ) -> Option < NodeId > {
241
- self . label_res_map . get ( & id) . copied ( )
245
+ self . general . label_res_map . get ( & id) . copied ( )
242
246
}
243
247
244
248
/// Obtains resolution for a lifetime with the given `NodeId`.
245
249
fn get_lifetime_res ( & self , id : NodeId ) -> Option < LifetimeRes > {
246
- self . lifetimes_res_map . get ( & id) . copied ( )
250
+ self . general . lifetimes_res_map . get ( & id) . copied ( )
247
251
}
248
252
249
253
/// Obtain the list of lifetimes parameters to add to an item.
@@ -254,7 +258,7 @@ impl ResolverAstLowering {
254
258
/// The extra lifetimes that appear from the parenthesized `Fn`-trait desugaring
255
259
/// should appear at the enclosing `PolyTraitRef`.
256
260
fn extra_lifetime_params ( & self , id : NodeId ) -> Vec < ( Ident , NodeId , LifetimeRes ) > {
257
- self . extra_lifetime_params_map . get ( & id) . cloned ( ) . unwrap_or_default ( )
261
+ self . general . extra_lifetime_params_map . get ( & id) . cloned ( ) . unwrap_or_default ( )
258
262
}
259
263
}
260
264
@@ -513,22 +517,22 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
513
517
self . tcx . at ( span) . create_def ( self . current_hir_id_owner . def_id , name, def_kind) . def_id ( ) ;
514
518
515
519
debug ! ( "create_def: def_id_to_node_id[{:?}] <-> {:?}" , def_id, node_id) ;
516
- self . resolver . node_id_to_def_id . insert ( node_id, def_id) ;
520
+ self . resolver . general . node_id_to_def_id . insert ( node_id, def_id) ;
517
521
518
522
def_id
519
523
}
520
524
521
525
fn next_node_id ( & mut self ) -> NodeId {
522
- let start = self . resolver . next_node_id ;
526
+ let start = self . resolver . general . next_node_id ;
523
527
let next = start. as_u32 ( ) . checked_add ( 1 ) . expect ( "input too large; ran out of NodeIds" ) ;
524
- self . resolver . next_node_id = ast:: NodeId :: from_u32 ( next) ;
528
+ self . resolver . general . next_node_id = ast:: NodeId :: from_u32 ( next) ;
525
529
start
526
530
}
527
531
528
532
/// Given the id of some node in the AST, finds the `LocalDefId` associated with it by the name
529
533
/// resolver (if any).
530
534
fn opt_local_def_id ( & self , node : NodeId ) -> Option < LocalDefId > {
531
- self . resolver . node_id_to_def_id . get ( & node) . copied ( )
535
+ self . resolver . general . node_id_to_def_id . get ( & node) . copied ( )
532
536
}
533
537
534
538
fn local_def_id ( & self , node : NodeId ) -> LocalDefId {
@@ -652,7 +656,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
652
656
self . children . push ( ( def_id, hir:: MaybeOwner :: NonOwner ( hir_id) ) ) ;
653
657
}
654
658
655
- if let Some ( traits) = self . resolver . trait_map . remove ( & ast_node_id) {
659
+ if let Some ( traits) = self . resolver . general . trait_map . remove ( & ast_node_id) {
656
660
self . trait_map . insert ( hir_id. local_id , traits. into_boxed_slice ( ) ) ;
657
661
}
658
662
@@ -1599,7 +1603,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1599
1603
inputs,
1600
1604
output,
1601
1605
c_variadic,
1602
- lifetime_elision_allowed : self . resolver . lifetime_elision_allowed . contains ( & fn_node_id) ,
1606
+ lifetime_elision_allowed : self
1607
+ . resolver
1608
+ . general
1609
+ . lifetime_elision_allowed
1610
+ . contains ( & fn_node_id) ,
1603
1611
implicit_self : decl. inputs . get ( 0 ) . map_or ( hir:: ImplicitSelfKind :: None , |arg| {
1604
1612
let is_mutable_pat = matches ! (
1605
1613
arg. pat. kind,
0 commit comments