@@ -254,11 +254,38 @@ pub struct ConstArg {
254254 pub span : Span ,
255255}
256256
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+
257283#[ derive( Debug , HashStable_Generic ) ]
258284pub enum GenericArg < ' hir > {
259285 Lifetime ( Lifetime ) ,
260286 Type ( Ty < ' hir > ) ,
261287 Const ( ConstArg ) ,
288+ Infer ( InferArg ) ,
262289}
263290
264291impl GenericArg < ' _ > {
@@ -267,6 +294,7 @@ impl GenericArg<'_> {
267294 GenericArg :: Lifetime ( l) => l. span ,
268295 GenericArg :: Type ( t) => t. span ,
269296 GenericArg :: Const ( c) => c. span ,
297+ GenericArg :: Infer ( i) => i. span ,
270298 }
271299 }
272300
@@ -275,6 +303,7 @@ impl GenericArg<'_> {
275303 GenericArg :: Lifetime ( l) => l. hir_id ,
276304 GenericArg :: Type ( t) => t. hir_id ,
277305 GenericArg :: Const ( c) => c. value . hir_id ,
306+ GenericArg :: Infer ( i) => i. hir_id ,
278307 }
279308 }
280309
@@ -291,6 +320,7 @@ impl GenericArg<'_> {
291320 GenericArg :: Lifetime ( _) => "lifetime" ,
292321 GenericArg :: Type ( _) => "type" ,
293322 GenericArg :: Const ( _) => "constant" ,
323+ GenericArg :: Infer ( _) => "inferred" ,
294324 }
295325 }
296326
@@ -301,6 +331,7 @@ impl GenericArg<'_> {
301331 GenericArg :: Const ( _) => {
302332 ast:: ParamKindOrd :: Const { unordered : feats. unordered_const_ty_params ( ) }
303333 }
334+ GenericArg :: Infer ( _) => ast:: ParamKindOrd :: Infer ,
304335 }
305336 }
306337}
@@ -342,27 +373,36 @@ impl GenericArgs<'_> {
342373 break ;
343374 }
344375 GenericArg :: Const ( _) => { }
376+ GenericArg :: Infer ( _) => { }
345377 }
346378 }
347379 }
348380 panic ! ( "GenericArgs::inputs: not a `Fn(T) -> U`" ) ;
349381 }
350382
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+ }
356387
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+ }
364392
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 ( )
366406 }
367407
368408 /// The span encompassing the text inside the surrounding brackets.
@@ -485,6 +525,7 @@ pub struct GenericParamCount {
485525 pub lifetimes : usize ,
486526 pub types : usize ,
487527 pub consts : usize ,
528+ pub infer : usize ,
488529}
489530
490531/// Represents lifetimes and type parameters attached to a declaration
@@ -3130,6 +3171,8 @@ pub enum Node<'hir> {
31303171 Visibility ( & ' hir Visibility < ' hir > ) ,
31313172
31323173 Crate ( & ' hir Mod < ' hir > ) ,
3174+
3175+ Infer ( & ' hir InferArg ) ,
31333176}
31343177
31353178impl < ' hir > Node < ' hir > {
@@ -3198,6 +3241,7 @@ impl<'hir> Node<'hir> {
31983241 | Node :: Local ( Local { hir_id, .. } )
31993242 | Node :: Lifetime ( Lifetime { hir_id, .. } )
32003243 | Node :: Param ( Param { hir_id, .. } )
3244+ | Node :: Infer ( InferArg { hir_id, .. } )
32013245 | Node :: GenericParam ( GenericParam { hir_id, .. } ) => Some ( * hir_id) ,
32023246 Node :: TraitRef ( TraitRef { hir_ref_id, .. } ) => Some ( * hir_ref_id) ,
32033247 Node :: PathSegment ( PathSegment { hir_id, .. } ) => * hir_id,
0 commit comments