@@ -59,6 +59,27 @@ impl HygieneId {
59
59
}
60
60
}
61
61
62
+ pub type ExprPtr = AstPtr < ast:: Expr > ;
63
+ pub type ExprSource = InFile < ExprPtr > ;
64
+
65
+ pub type PatPtr = AstPtr < ast:: Pat > ;
66
+ pub type PatSource = InFile < PatPtr > ;
67
+
68
+ pub type LabelPtr = AstPtr < ast:: Label > ;
69
+ pub type LabelSource = InFile < LabelPtr > ;
70
+
71
+ pub type FieldPtr = AstPtr < ast:: RecordExprField > ;
72
+ pub type FieldSource = InFile < FieldPtr > ;
73
+
74
+ pub type PatFieldPtr = AstPtr < Either < ast:: RecordExprField , ast:: RecordPatField > > ;
75
+ pub type PatFieldSource = InFile < PatFieldPtr > ;
76
+
77
+ pub type ExprOrPatPtr = AstPtr < Either < ast:: Expr , ast:: Pat > > ;
78
+ pub type ExprOrPatSource = InFile < ExprOrPatPtr > ;
79
+
80
+ pub type SelfParamPtr = AstPtr < ast:: SelfParam > ;
81
+ pub type MacroCallPtr = AstPtr < ast:: MacroCall > ;
82
+
62
83
/// The body of an item (function, const etc.).
63
84
#[ derive( Debug , Eq , PartialEq ) ]
64
85
pub struct Body {
@@ -112,68 +133,6 @@ pub struct BodyCollector {
112
133
ident_hygiene : FxHashMap < ExprOrPatId , HygieneId > ,
113
134
}
114
135
115
- impl BodyCollector {
116
- fn finish (
117
- self ,
118
- body_expr : ExprId ,
119
- self_param : Option < BindingId > ,
120
- params : Box < [ PatId ] > ,
121
- ) -> Body {
122
- let Self {
123
- block_scopes,
124
- mut exprs,
125
- mut labels,
126
- mut pats,
127
- mut bindings,
128
- mut binding_owners,
129
- mut binding_hygiene,
130
- mut ident_hygiene,
131
- mut types,
132
- } = self ;
133
- exprs. shrink_to_fit ( ) ;
134
- labels. shrink_to_fit ( ) ;
135
- pats. shrink_to_fit ( ) ;
136
- bindings. shrink_to_fit ( ) ;
137
- binding_owners. shrink_to_fit ( ) ;
138
- binding_hygiene. shrink_to_fit ( ) ;
139
- ident_hygiene. shrink_to_fit ( ) ;
140
- types. shrink_to_fit ( ) ;
141
-
142
- Body {
143
- exprs,
144
- pats,
145
- bindings,
146
- labels,
147
- binding_owners,
148
- params,
149
- self_param,
150
- body_expr,
151
- types,
152
- block_scopes : block_scopes. into_boxed_slice ( ) ,
153
- binding_hygiene,
154
- ident_hygiene,
155
- }
156
- }
157
- }
158
-
159
- pub type ExprPtr = AstPtr < ast:: Expr > ;
160
- pub type ExprSource = InFile < ExprPtr > ;
161
-
162
- pub type PatPtr = AstPtr < ast:: Pat > ;
163
- pub type PatSource = InFile < PatPtr > ;
164
-
165
- pub type LabelPtr = AstPtr < ast:: Label > ;
166
- pub type LabelSource = InFile < LabelPtr > ;
167
-
168
- pub type FieldPtr = AstPtr < ast:: RecordExprField > ;
169
- pub type FieldSource = InFile < FieldPtr > ;
170
-
171
- pub type PatFieldPtr = AstPtr < Either < ast:: RecordExprField , ast:: RecordPatField > > ;
172
- pub type PatFieldSource = InFile < PatFieldPtr > ;
173
-
174
- pub type ExprOrPatPtr = AstPtr < Either < ast:: Expr , ast:: Pat > > ;
175
- pub type ExprOrPatSource = InFile < ExprOrPatPtr > ;
176
-
177
136
/// An item body together with the mapping from syntax nodes to HIR expression
178
137
/// IDs. This is needed to go from e.g. a position in a file to the HIR
179
138
/// expression containing it; but for type inference etc., we want to operate on
@@ -198,7 +157,7 @@ pub struct BodySourceMap {
198
157
label_map : FxHashMap < LabelSource , LabelId > ,
199
158
label_map_back : ArenaMap < LabelId , LabelSource > ,
200
159
201
- self_param : Option < InFile < AstPtr < ast :: SelfParam > > > ,
160
+ self_param : Option < InFile < SelfParamPtr > > ,
202
161
binding_definitions : FxHashMap < BindingId , SmallVec < [ PatId ; 4 ] > > ,
203
162
204
163
/// We don't create explicit nodes for record fields (`S { record_field: 92 }`).
@@ -210,7 +169,7 @@ pub struct BodySourceMap {
210
169
211
170
template_map : Option < Box < FormatTemplate > > ,
212
171
213
- expansions : FxHashMap < InFile < AstPtr < ast :: MacroCall > > , MacroFileId > ,
172
+ expansions : FxHashMap < InFile < MacroCallPtr > , MacroFileId > ,
214
173
215
174
/// Diagnostics accumulated during body lowering. These contain `AstPtr`s and so are stored in
216
175
/// the source map (since they're just as volatile).
@@ -228,19 +187,63 @@ struct FormatTemplate {
228
187
/// The value stored for each capture is its template literal and offset inside it. The template literal
229
188
/// is from the `format_args[_nl]!()` macro and so needs to be mapped up once to go to the user-written
230
189
/// template.
231
- implicit_capture_to_source : FxHashMap < ExprId , InFile < ( AstPtr < ast :: Expr > , TextRange ) > > ,
190
+ implicit_capture_to_source : FxHashMap < ExprId , InFile < ( ExprPtr , TextRange ) > > ,
232
191
}
233
192
234
193
#[ derive( Debug , Eq , PartialEq ) ]
235
194
pub enum BodyDiagnostic {
236
195
InactiveCode { node : InFile < SyntaxNodePtr > , cfg : CfgExpr , opts : CfgOptions } ,
237
- MacroError { node : InFile < AstPtr < ast :: MacroCall > > , err : ExpandError } ,
238
- UnresolvedMacroCall { node : InFile < AstPtr < ast :: MacroCall > > , path : ModPath } ,
196
+ MacroError { node : InFile < MacroCallPtr > , err : ExpandError } ,
197
+ UnresolvedMacroCall { node : InFile < MacroCallPtr > , path : ModPath } ,
239
198
UnreachableLabel { node : InFile < AstPtr < ast:: Lifetime > > , name : Name } ,
240
199
AwaitOutsideOfAsync { node : InFile < AstPtr < ast:: AwaitExpr > > , location : String } ,
241
200
UndeclaredLabel { node : InFile < AstPtr < ast:: Lifetime > > , name : Name } ,
242
201
}
243
202
203
+ impl BodyCollector {
204
+ fn finish (
205
+ self ,
206
+ body_expr : ExprId ,
207
+ self_param : Option < BindingId > ,
208
+ params : Box < [ PatId ] > ,
209
+ ) -> Body {
210
+ let Self {
211
+ block_scopes,
212
+ mut exprs,
213
+ mut labels,
214
+ mut pats,
215
+ mut bindings,
216
+ mut binding_owners,
217
+ mut binding_hygiene,
218
+ mut ident_hygiene,
219
+ mut types,
220
+ } = self ;
221
+ exprs. shrink_to_fit ( ) ;
222
+ labels. shrink_to_fit ( ) ;
223
+ pats. shrink_to_fit ( ) ;
224
+ bindings. shrink_to_fit ( ) ;
225
+ binding_owners. shrink_to_fit ( ) ;
226
+ binding_hygiene. shrink_to_fit ( ) ;
227
+ ident_hygiene. shrink_to_fit ( ) ;
228
+ types. shrink_to_fit ( ) ;
229
+
230
+ Body {
231
+ exprs,
232
+ pats,
233
+ bindings,
234
+ labels,
235
+ binding_owners,
236
+ params,
237
+ self_param,
238
+ body_expr,
239
+ types,
240
+ block_scopes : block_scopes. into_boxed_slice ( ) ,
241
+ binding_hygiene,
242
+ ident_hygiene,
243
+ }
244
+ }
245
+ }
246
+
244
247
impl Body {
245
248
pub ( crate ) fn body_with_source_map_query (
246
249
db : & dyn DefDatabase ,
@@ -765,17 +768,15 @@ impl BodySourceMap {
765
768
self . expansions . get ( & src) . cloned ( )
766
769
}
767
770
768
- pub fn macro_calls (
769
- & self ,
770
- ) -> impl Iterator < Item = ( InFile < AstPtr < ast:: MacroCall > > , MacroFileId ) > + ' _ {
771
+ pub fn macro_calls ( & self ) -> impl Iterator < Item = ( InFile < MacroCallPtr > , MacroFileId ) > + ' _ {
771
772
self . expansions . iter ( ) . map ( |( & a, & b) | ( a, b) )
772
773
}
773
774
774
775
pub fn pat_syntax ( & self , pat : PatId ) -> Result < ExprOrPatSource , SyntheticSyntax > {
775
776
self . pat_map_back . get ( pat) . cloned ( ) . ok_or ( SyntheticSyntax )
776
777
}
777
778
778
- pub fn self_param_syntax ( & self ) -> Option < InFile < AstPtr < ast :: SelfParam > > > {
779
+ pub fn self_param_syntax ( & self ) -> Option < InFile < SelfParamPtr > > {
779
780
self . self_param
780
781
}
781
782
@@ -809,9 +810,7 @@ impl BodySourceMap {
809
810
self . expr_map . get ( & src) . copied ( )
810
811
}
811
812
812
- pub fn expansions (
813
- & self ,
814
- ) -> impl Iterator < Item = ( & InFile < AstPtr < ast:: MacroCall > > , & MacroFileId ) > {
813
+ pub fn expansions ( & self ) -> impl Iterator < Item = ( & InFile < MacroCallPtr > , & MacroFileId ) > {
815
814
self . expansions . iter ( )
816
815
}
817
816
@@ -831,7 +830,7 @@ impl BodySourceMap {
831
830
pub fn format_args_implicit_capture (
832
831
& self ,
833
832
capture_expr : ExprId ,
834
- ) -> Option < InFile < ( AstPtr < ast :: Expr > , TextRange ) > > {
833
+ ) -> Option < InFile < ( ExprPtr , TextRange ) > > {
835
834
self . template_map . as_ref ( ) ?. implicit_capture_to_source . get ( & capture_expr) . copied ( )
836
835
}
837
836
0 commit comments