@@ -21,7 +21,7 @@ use crate::{
21
21
db:: DefDatabase ,
22
22
dyn_map:: { keys, DynMap } ,
23
23
expander:: Expander ,
24
- item_tree:: ItemTree ,
24
+ item_tree:: { AttrOwner , ItemTree } ,
25
25
lower:: LowerCtx ,
26
26
nameres:: { DefMap , MacroSubNs } ,
27
27
src:: { HasChildSource , HasSource } ,
@@ -215,9 +215,14 @@ impl GenericParams {
215
215
}
216
216
}
217
217
218
- pub ( crate ) fn fill ( & mut self , lower_ctx : & LowerCtx < ' _ > , node : & dyn HasGenericParams ) {
218
+ pub ( crate ) fn fill (
219
+ & mut self ,
220
+ lower_ctx : & LowerCtx < ' _ > ,
221
+ node : & dyn HasGenericParams ,
222
+ add_param_attrs : impl FnMut ( AttrOwner , ast:: GenericParam ) ,
223
+ ) {
219
224
if let Some ( params) = node. generic_param_list ( ) {
220
- self . fill_params ( lower_ctx, params)
225
+ self . fill_params ( lower_ctx, params, add_param_attrs )
221
226
}
222
227
if let Some ( where_clause) = node. where_clause ( ) {
223
228
self . fill_where_predicates ( lower_ctx, where_clause) ;
@@ -235,7 +240,12 @@ impl GenericParams {
235
240
}
236
241
}
237
242
238
- fn fill_params ( & mut self , lower_ctx : & LowerCtx < ' _ > , params : ast:: GenericParamList ) {
243
+ fn fill_params (
244
+ & mut self ,
245
+ lower_ctx : & LowerCtx < ' _ > ,
246
+ params : ast:: GenericParamList ,
247
+ mut add_param_attrs : impl FnMut ( AttrOwner , ast:: GenericParam ) ,
248
+ ) {
239
249
for type_or_const_param in params. type_or_const_params ( ) {
240
250
match type_or_const_param {
241
251
ast:: TypeOrConstParam :: Type ( type_param) => {
@@ -249,13 +259,14 @@ impl GenericParams {
249
259
default,
250
260
provenance : TypeParamProvenance :: TypeParamList ,
251
261
} ;
252
- self . type_or_consts . alloc ( param. into ( ) ) ;
262
+ let idx = self . type_or_consts . alloc ( param. into ( ) ) ;
253
263
let type_ref = TypeRef :: Path ( name. into ( ) ) ;
254
264
self . fill_bounds (
255
265
lower_ctx,
256
266
type_param. type_bound_list ( ) ,
257
267
Either :: Left ( type_ref) ,
258
268
) ;
269
+ add_param_attrs ( idx. into ( ) , ast:: GenericParam :: TypeParam ( type_param) ) ;
259
270
}
260
271
ast:: TypeOrConstParam :: Const ( const_param) => {
261
272
let name = const_param. name ( ) . map_or_else ( Name :: missing, |it| it. as_name ( ) ) ;
@@ -267,21 +278,23 @@ impl GenericParams {
267
278
ty : Interned :: new ( ty) ,
268
279
has_default : const_param. default_val ( ) . is_some ( ) ,
269
280
} ;
270
- self . type_or_consts . alloc ( param. into ( ) ) ;
281
+ let idx = self . type_or_consts . alloc ( param. into ( ) ) ;
282
+ add_param_attrs ( idx. into ( ) , ast:: GenericParam :: ConstParam ( const_param) ) ;
271
283
}
272
284
}
273
285
}
274
286
for lifetime_param in params. lifetime_params ( ) {
275
287
let name =
276
288
lifetime_param. lifetime ( ) . map_or_else ( Name :: missing, |lt| Name :: new_lifetime ( & lt) ) ;
277
289
let param = LifetimeParamData { name : name. clone ( ) } ;
278
- self . lifetimes . alloc ( param) ;
290
+ let idx = self . lifetimes . alloc ( param) ;
279
291
let lifetime_ref = LifetimeRef :: new_name ( name) ;
280
292
self . fill_bounds (
281
293
lower_ctx,
282
294
lifetime_param. type_bound_list ( ) ,
283
295
Either :: Right ( lifetime_ref) ,
284
296
) ;
297
+ add_param_attrs ( idx. into ( ) , ast:: GenericParam :: LifetimeParam ( lifetime_param) ) ;
285
298
}
286
299
}
287
300
0 commit comments