1
- use super :: { AstOwner , ImplTraitContext , ImplTraitPosition , ResolverAstLowering } ;
1
+ use super :: ResolverAstLoweringExt ;
2
+ use super :: { AstOwner , ImplTraitContext , ImplTraitPosition } ;
2
3
use super :: { LoweringContext , ParamMode } ;
3
4
use crate :: { Arena , FnDeclKind } ;
4
5
@@ -11,8 +12,11 @@ use rustc_errors::struct_span_err;
11
12
use rustc_hir as hir;
12
13
use rustc_hir:: def:: { DefKind , Res } ;
13
14
use rustc_hir:: def_id:: { LocalDefId , CRATE_DEF_ID } ;
15
+ use rustc_hir:: definitions:: Definitions ;
14
16
use rustc_hir:: PredicateOrigin ;
15
17
use rustc_index:: vec:: { Idx , IndexVec } ;
18
+ use rustc_middle:: ty:: { ResolverAstLowering , ResolverOutputs } ;
19
+ use rustc_session:: cstore:: CrateStoreDyn ;
16
20
use rustc_session:: Session ;
17
21
use rustc_span:: source_map:: DesugaringKind ;
18
22
use rustc_span:: symbol:: { kw, sym, Ident } ;
@@ -24,7 +28,10 @@ use std::iter;
24
28
25
29
pub ( super ) struct ItemLowerer < ' a , ' hir > {
26
30
pub ( super ) sess : & ' a Session ,
27
- pub ( super ) resolver : & ' a mut dyn ResolverAstLowering ,
31
+ pub ( super ) definitions : & ' a mut Definitions ,
32
+ pub ( super ) cstore : & ' a CrateStoreDyn ,
33
+ pub ( super ) resolutions : & ' a ResolverOutputs ,
34
+ pub ( super ) resolver : & ' a mut ResolverAstLowering ,
28
35
pub ( super ) arena : & ' hir Arena < ' hir > ,
29
36
pub ( super ) ast_index : & ' a IndexVec < LocalDefId , AstOwner < ' a > > ,
30
37
pub ( super ) owners : & ' a mut IndexVec < LocalDefId , hir:: MaybeOwner < & ' hir hir:: OwnerInfo < ' hir > > > ,
@@ -59,6 +66,9 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
59
66
let mut lctx = LoweringContext {
60
67
// Pseudo-globals.
61
68
sess : & self . sess ,
69
+ definitions : self . definitions ,
70
+ cstore : self . cstore ,
71
+ resolutions : self . resolutions ,
62
72
resolver : self . resolver ,
63
73
arena : self . arena ,
64
74
@@ -118,8 +128,7 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
118
128
119
129
#[ instrument( level = "debug" , skip( self , c) ) ]
120
130
fn lower_crate ( & mut self , c : & Crate ) {
121
- debug_assert_eq ! ( self . resolver. local_def_id( CRATE_NODE_ID ) , CRATE_DEF_ID ) ;
122
-
131
+ debug_assert_eq ! ( self . resolver. node_id_to_def_id[ & CRATE_NODE_ID ] , CRATE_DEF_ID ) ;
123
132
self . with_lctx ( CRATE_NODE_ID , |lctx| {
124
133
let module = lctx. lower_mod ( & c. items , & c. spans ) ;
125
134
lctx. lower_attrs ( hir:: CRATE_HIR_ID , & c. attrs ) ;
@@ -133,10 +142,10 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
133
142
}
134
143
135
144
fn lower_assoc_item ( & mut self , item : & AssocItem , ctxt : AssocCtxt ) {
136
- let def_id = self . resolver . local_def_id ( item. id ) ;
145
+ let def_id = self . resolver . node_id_to_def_id [ & item. id ] ;
137
146
138
147
let parent_id = {
139
- let parent = self . resolver . definitions ( ) . def_key ( def_id) . parent ;
148
+ let parent = self . definitions . def_key ( def_id) . parent ;
140
149
let local_def_index = parent. unwrap ( ) ;
141
150
LocalDefId { local_def_index }
142
151
} ;
@@ -177,7 +186,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
177
186
}
178
187
179
188
pub ( super ) fn lower_item_ref ( & mut self , i : & Item ) -> SmallVec < [ hir:: ItemId ; 1 ] > {
180
- let mut node_ids = smallvec ! [ hir:: ItemId { def_id: self . resolver . local_def_id( i. id) } ] ;
189
+ let mut node_ids = smallvec ! [ hir:: ItemId { def_id: self . local_def_id( i. id) } ] ;
181
190
if let ItemKind :: Use ( ref use_tree) = & i. kind {
182
191
self . lower_item_id_use_tree ( use_tree, i. id , & mut node_ids) ;
183
192
}
@@ -193,7 +202,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
193
202
match tree. kind {
194
203
UseTreeKind :: Nested ( ref nested_vec) => {
195
204
for & ( ref nested, id) in nested_vec {
196
- vec. push ( hir:: ItemId { def_id : self . resolver . local_def_id ( id) } ) ;
205
+ vec. push ( hir:: ItemId { def_id : self . local_def_id ( id) } ) ;
197
206
self . lower_item_id_use_tree ( nested, id, vec) ;
198
207
}
199
208
}
@@ -202,7 +211,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
202
211
for ( _, & id) in
203
212
iter:: zip ( self . expect_full_res_from_use ( base_id) . skip ( 1 ) , & [ id1, id2] )
204
213
{
205
- vec. push ( hir:: ItemId { def_id : self . resolver . local_def_id ( id) } ) ;
214
+ vec. push ( hir:: ItemId { def_id : self . local_def_id ( id) } ) ;
206
215
}
207
216
}
208
217
}
@@ -467,7 +476,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
467
476
}
468
477
ItemKind :: MacroDef ( MacroDef { ref body, macro_rules } ) => {
469
478
let body = P ( self . lower_mac_args ( body) ) ;
470
- let macro_kind = self . resolver . decl_macro_kind ( self . resolver . local_def_id ( id) ) ;
479
+ let macro_kind = self . resolver . decl_macro_kind ( self . local_def_id ( id) ) ;
471
480
hir:: ItemKind :: Macro ( ast:: MacroDef { body, macro_rules } , macro_kind)
472
481
}
473
482
ItemKind :: MacCall ( ..) => {
@@ -527,7 +536,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
527
536
// Essentially a single `use` which imports two names is desugared into
528
537
// two imports.
529
538
for new_node_id in [ id1, id2] {
530
- let new_id = self . resolver . local_def_id ( new_node_id) ;
539
+ let new_id = self . local_def_id ( new_node_id) ;
531
540
let Some ( res) = resolutions. next ( ) else {
532
541
// Associate an HirId to both ids even if there is no resolution.
533
542
let _old = self . children . insert (
@@ -540,7 +549,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
540
549
let ident = * ident;
541
550
let mut path = path. clone ( ) ;
542
551
for seg in & mut path. segments {
543
- seg. id = self . resolver . next_node_id ( ) ;
552
+ seg. id = self . next_node_id ( ) ;
544
553
}
545
554
let span = path. span ;
546
555
@@ -603,13 +612,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
603
612
604
613
// Add all the nested `PathListItem`s to the HIR.
605
614
for & ( ref use_tree, id) in trees {
606
- let new_hir_id = self . resolver . local_def_id ( id) ;
615
+ let new_hir_id = self . local_def_id ( id) ;
607
616
608
617
let mut prefix = prefix. clone ( ) ;
609
618
610
619
// Give the segments new node-ids since they are being cloned.
611
620
for seg in & mut prefix. segments {
612
- seg. id = self . resolver . next_node_id ( ) ;
621
+ seg. id = self . next_node_id ( ) ;
613
622
}
614
623
615
624
// Each `use` import is an item and thus are owners of the
@@ -683,7 +692,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
683
692
684
693
fn lower_foreign_item_ref ( & mut self , i : & ForeignItem ) -> hir:: ForeignItemRef {
685
694
hir:: ForeignItemRef {
686
- id : hir:: ForeignItemId { def_id : self . resolver . local_def_id ( i. id ) } ,
695
+ id : hir:: ForeignItemId { def_id : self . local_def_id ( i. id ) } ,
687
696
ident : self . lower_ident ( i. ident ) ,
688
697
span : self . lower_span ( i. span ) ,
689
698
}
@@ -839,7 +848,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
839
848
}
840
849
AssocItemKind :: MacCall ( ..) => unimplemented ! ( ) ,
841
850
} ;
842
- let id = hir:: TraitItemId { def_id : self . resolver . local_def_id ( i. id ) } ;
851
+ let id = hir:: TraitItemId { def_id : self . local_def_id ( i. id ) } ;
843
852
let defaultness = hir:: Defaultness :: Default { has_value : has_default } ;
844
853
hir:: TraitItemRef {
845
854
id,
@@ -919,7 +928,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
919
928
let has_value = true ;
920
929
let ( defaultness, _) = self . lower_defaultness ( i. kind . defaultness ( ) , has_value) ;
921
930
hir:: ImplItemRef {
922
- id : hir:: ImplItemId { def_id : self . resolver . local_def_id ( i. id ) } ,
931
+ id : hir:: ImplItemId { def_id : self . local_def_id ( i. id ) } ,
923
932
ident : self . lower_ident ( i. ident ) ,
924
933
span : self . lower_span ( i. span ) ,
925
934
defaultness,
@@ -1331,7 +1340,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
1331
1340
generics
1332
1341
. params
1333
1342
. iter ( )
1334
- . any ( |p| def_id == self . resolver . local_def_id ( p. id ) . to_def_id ( ) )
1343
+ . any ( |p| def_id == self . local_def_id ( p. id ) . to_def_id ( ) )
1335
1344
}
1336
1345
// Either the `bounded_ty` is not a plain type parameter, or
1337
1346
// it's not found in the generic type parameters list.
@@ -1435,7 +1444,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
1435
1444
match kind {
1436
1445
GenericParamKind :: Const { .. } => None ,
1437
1446
GenericParamKind :: Type { .. } => {
1438
- let def_id = self . resolver . local_def_id ( id) . to_def_id ( ) ;
1447
+ let def_id = self . local_def_id ( id) . to_def_id ( ) ;
1439
1448
let ty_path = self . arena . alloc ( hir:: Path {
1440
1449
span : param_span,
1441
1450
res : Res :: Def ( DefKind :: TyParam , def_id) ,
@@ -1458,7 +1467,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
1458
1467
let res = self . resolver . get_lifetime_res ( id) . unwrap_or_else ( || {
1459
1468
panic ! ( "Missing resolution for lifetime {:?} at {:?}" , id, ident. span)
1460
1469
} ) ;
1461
- let lt_id = self . resolver . next_node_id ( ) ;
1470
+ let lt_id = self . next_node_id ( ) ;
1462
1471
let lifetime = self . new_named_lifetime_with_res ( lt_id, ident_span, ident, res) ;
1463
1472
Some ( hir:: WherePredicate :: RegionPredicate ( hir:: WhereRegionPredicate {
1464
1473
lifetime,
0 commit comments