@@ -254,11 +254,38 @@ pub struct ConstArg {
254
254
pub span : Span ,
255
255
}
256
256
257
+ #[ derive( Copy , Clone , Encodable , Debug , HashStable_Generic ) ]
258
+ pub enum InferKind {
259
+ Const ,
260
+ Type ,
261
+ }
262
+
263
+ impl InferKind {
264
+ #[ inline]
265
+ pub fn is_type ( self ) -> bool {
266
+ matches ! ( self , InferKind :: Type )
267
+ }
268
+ }
269
+
270
+ #[ derive( Encodable , Debug , HashStable_Generic ) ]
271
+ pub struct InferArg {
272
+ pub hir_id : HirId ,
273
+ pub kind : InferKind ,
274
+ pub span : Span ,
275
+ }
276
+
277
+ impl InferArg {
278
+ pub fn to_ty ( & self ) -> Ty < ' _ > {
279
+ Ty { kind : TyKind :: Infer , span : self . span , hir_id : self . hir_id }
280
+ }
281
+ }
282
+
257
283
#[ derive( Debug , HashStable_Generic ) ]
258
284
pub enum GenericArg < ' hir > {
259
285
Lifetime ( Lifetime ) ,
260
286
Type ( Ty < ' hir > ) ,
261
287
Const ( ConstArg ) ,
288
+ Infer ( InferArg ) ,
262
289
}
263
290
264
291
impl GenericArg < ' _ > {
@@ -267,6 +294,7 @@ impl GenericArg<'_> {
267
294
GenericArg :: Lifetime ( l) => l. span ,
268
295
GenericArg :: Type ( t) => t. span ,
269
296
GenericArg :: Const ( c) => c. span ,
297
+ GenericArg :: Infer ( i) => i. span ,
270
298
}
271
299
}
272
300
@@ -275,6 +303,7 @@ impl GenericArg<'_> {
275
303
GenericArg :: Lifetime ( l) => l. hir_id ,
276
304
GenericArg :: Type ( t) => t. hir_id ,
277
305
GenericArg :: Const ( c) => c. value . hir_id ,
306
+ GenericArg :: Infer ( i) => i. hir_id ,
278
307
}
279
308
}
280
309
@@ -291,6 +320,7 @@ impl GenericArg<'_> {
291
320
GenericArg :: Lifetime ( _) => "lifetime" ,
292
321
GenericArg :: Type ( _) => "type" ,
293
322
GenericArg :: Const ( _) => "constant" ,
323
+ GenericArg :: Infer ( _) => "inferred" ,
294
324
}
295
325
}
296
326
@@ -301,6 +331,7 @@ impl GenericArg<'_> {
301
331
GenericArg :: Const ( _) => {
302
332
ast:: ParamKindOrd :: Const { unordered : feats. unordered_const_ty_params ( ) }
303
333
}
334
+ GenericArg :: Infer ( _) => ast:: ParamKindOrd :: Infer ,
304
335
}
305
336
}
306
337
}
@@ -342,27 +373,36 @@ impl GenericArgs<'_> {
342
373
break ;
343
374
}
344
375
GenericArg :: Const ( _) => { }
376
+ GenericArg :: Infer ( _) => { }
345
377
}
346
378
}
347
379
}
348
380
panic ! ( "GenericArgs::inputs: not a `Fn(T) -> U`" ) ;
349
381
}
350
382
351
- pub fn own_counts ( & self ) -> GenericParamCount {
352
- // We could cache this as a property of `GenericParamCount`, but
353
- // the aim is to refactor this away entirely eventually and the
354
- // presence of this method will be a constant reminder.
355
- let mut own_counts: GenericParamCount = Default :: default ( ) ;
383
+ #[ inline]
384
+ pub fn has_type_params ( & self ) -> bool {
385
+ self . args . iter ( ) . any ( |arg| matches ! ( arg, GenericArg :: Type ( _) ) )
386
+ }
356
387
357
- for arg in self . args {
358
- match arg {
359
- GenericArg :: Lifetime ( _) => own_counts. lifetimes += 1 ,
360
- GenericArg :: Type ( _) => own_counts. types += 1 ,
361
- GenericArg :: Const ( _) => own_counts. consts += 1 ,
362
- } ;
363
- }
388
+ #[ inline]
389
+ pub fn num_type_params ( & self ) -> usize {
390
+ self . args . iter ( ) . filter ( |arg| matches ! ( arg, GenericArg :: Type ( _) ) ) . count ( )
391
+ }
364
392
365
- own_counts
393
+ #[ inline]
394
+ pub fn num_lifetime_params ( & self ) -> usize {
395
+ self . args . iter ( ) . filter ( |arg| matches ! ( arg, GenericArg :: Lifetime ( _) ) ) . count ( )
396
+ }
397
+
398
+ #[ inline]
399
+ pub fn has_lifetime_params ( & self ) -> bool {
400
+ self . args . iter ( ) . any ( |arg| matches ! ( arg, GenericArg :: Lifetime ( _) ) )
401
+ }
402
+
403
+ #[ inline]
404
+ pub fn num_generic_params ( & self ) -> usize {
405
+ self . args . iter ( ) . filter ( |arg| !matches ! ( arg, GenericArg :: Lifetime ( _) ) ) . count ( )
366
406
}
367
407
368
408
/// The span encompassing the text inside the surrounding brackets.
@@ -485,6 +525,7 @@ pub struct GenericParamCount {
485
525
pub lifetimes : usize ,
486
526
pub types : usize ,
487
527
pub consts : usize ,
528
+ pub infer : usize ,
488
529
}
489
530
490
531
/// Represents lifetimes and type parameters attached to a declaration
@@ -3130,6 +3171,8 @@ pub enum Node<'hir> {
3130
3171
Visibility ( & ' hir Visibility < ' hir > ) ,
3131
3172
3132
3173
Crate ( & ' hir Mod < ' hir > ) ,
3174
+
3175
+ Infer ( & ' hir InferArg ) ,
3133
3176
}
3134
3177
3135
3178
impl < ' hir > Node < ' hir > {
@@ -3198,6 +3241,7 @@ impl<'hir> Node<'hir> {
3198
3241
| Node :: Local ( Local { hir_id, .. } )
3199
3242
| Node :: Lifetime ( Lifetime { hir_id, .. } )
3200
3243
| Node :: Param ( Param { hir_id, .. } )
3244
+ | Node :: Infer ( InferArg { hir_id, .. } )
3201
3245
| Node :: GenericParam ( GenericParam { hir_id, .. } ) => Some ( * hir_id) ,
3202
3246
Node :: TraitRef ( TraitRef { hir_ref_id, .. } ) => Some ( * hir_ref_id) ,
3203
3247
Node :: PathSegment ( PathSegment { hir_id, .. } ) => * hir_id,
0 commit comments