11# Generic parameters
22
33> ** <sup >Syntax</sup >** \
4- > _ Generics_ :\
5- >   ;  ; ` < ` _ GenericParams_ ` > `
6- >
74> _ GenericParams_ :\
8- >   ;  ;   ;  ; _ LifetimeParams_ \
9- >   ;  ; | ( _ LifetimeParam_ ` , ` )<sup >\* </sup > _ TypeParams_ \
10- >   ;  ; | ( _ LifetimeParam_ ` , ` )<sup >\* </sup > ( _ TypeParam_ ` , ` )<sup >\* </sup > _ ConstParams_
5+ >   ;  ;   ;  ; ` < ` ` > ` \
6+ >   ;  ; | ` < ` (_ GenericParam_ ` , ` )<sup >\* </sup > _ GenericParam_ ` , ` <sup >?</sup > ` > `
117>
12- > _ LifetimeParams _ :\
13- >   ;  ; ( _ LifetimeParam _ ` , ` ) <sup >\* </sup > _ LifetimeParam_ < sup >?</ sup >
8+ > _ GenericParam _ :\
9+ >   ;  ; [ _ OuterAttribute _ ] <sup >\* </sup > ( _ LifetimeParam_ | _ TypeParam _ | _ ConstParam _ )
1410>
1511> _ LifetimeParam_ :\
16- >   ;  ; [ _ OuterAttribute_ ] <sup >?</sup > [ LIFETIME_OR_LABEL]   ; ( ` : ` [ _ LifetimeBounds_ ] )<sup >?</sup >
17- >
18- > _ TypeParams_ :\
19- >   ;  ; ( _ TypeParam_ ` , ` )<sup >\* </sup > _ TypeParam_ <sup >?</sup >
12+ >   ;  ; [ LIFETIME_OR_LABEL]   ; ( ` : ` [ _ LifetimeBounds_ ] )<sup >?</sup >
2013>
2114> _ TypeParam_ :\
22- >   ;  ; [ _ OuterAttribute_ ] <sup >?</sup > [ IDENTIFIER] ( ` : ` [ _ TypeParamBounds_ ] <sup >?</sup > )<sup >?</sup > ( ` = ` [ _ Type_ ] )<sup >?</sup >
23- >
24- > _ ConstParams_ :\
25- >   ;  ; ( _ ConstParam_ ` , ` )<sup >\* </sup > _ ConstParam_ <sup >?</sup >
15+ >   ;  ; [ IDENTIFIER] ( ` : ` [ _ TypeParamBounds_ ] <sup >?</sup > )<sup >?</sup > ( ` = ` [ _ Type_ ] )<sup >?</sup >
2616>
2717> _ ConstParam_ :\
28- >   ;  ; [ _ OuterAttribute _ ] < sup >?</ sup > ` const ` [ IDENTIFIER] ` : ` [ _ Type_ ]
18+ >   ;  ; ` const ` [ IDENTIFIER] ` : ` [ _ Type_ ]
2919
3020Functions, type aliases, structs, enumerations, unions, traits, and
3121implementations may be * parameterized* by types, constants, and lifetimes. These
@@ -91,12 +81,15 @@ referred to with path syntax.
9181>   ;  ; _ ForLifetimes_ <sup >?</sup > [ _ Type_ ] ` : ` [ _ TypeParamBounds_ ] <sup >?</sup >
9282>
9383> _ ForLifetimes_ :\
94- >   ;  ; ` for ` ` < ` [ _ LifetimeParams _ ] ( #generic-parameters ) ` > `
84+ >   ;  ; ` for ` [ _ GenericParams _ ] ( #generic-parameters )
9585
9686* Where clauses* provide another way to specify bounds on type and lifetime
9787parameters as well as a way to specify bounds on types that aren't type
9888parameters.
9989
90+ The ` for ` keyword can be used to introduce [ higher-ranked lifetimes] . It only
91+ allows [ _ LifetimeParam_ ] parameters.
92+
10093Bounds that don't use the item's parameters or higher-ranked lifetimes are
10194checked when the item is defined. It is an error for such a bound to be false.
10295
@@ -141,6 +134,7 @@ struct Foo<#[my_flexible_clone(unbounded)] H> {
141134[ IDENTIFIER ] : ../identifiers.md
142135[ LIFETIME_OR_LABEL ] : ../tokens.md#lifetimes-and-loop-labels
143136
137+ [ _LifetimeParam_ ] : #generic-parameters
144138[ _LifetimeBounds_ ] : ../trait-bounds.md
145139[ _Lifetime_ ] : ../trait-bounds.md
146140[ _OuterAttribute_ ] : ../attributes.md
@@ -150,6 +144,7 @@ struct Foo<#[my_flexible_clone(unbounded)] H> {
150144[ arrays ] : ../types/array.md
151145[ const contexts ] : ../const_eval.md#const-context
152146[ function pointers ] : ../types/function-pointer.md
147+ [ higher-ranked lifetimes ] : ../trait-bounds.md#higher-ranked-trait-bounds
153148[ raw pointers ] : ../types/pointer.md#raw-pointers-const-and-mut
154149[ references ] : ../types/pointer.md#shared-references-
155150[ repeat expressions ] : ../expressions/array-expr.md
0 commit comments