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