22
33> ** <sup >Syntax</sup >** \
44> _ Generics_ :\
5- >   ;  ; ` < ` _ GenericParams_ ` > `
5+ >   ;  ; ` < ` _ GenericParams_ < sup >?</ sup > ` > `
66>
77> _ GenericParams_ :\
8- >   ;  ;   ;  ; _ LifetimeParams_ \
9- >   ;  ; | ( _ LifetimeParam_ ` , ` )<sup >\* </sup > _ TypeParams_ \
10- >   ;  ; | ( _ LifetimeParam_ ` , ` )<sup >\* </sup > ( _ TypeParam_ ` , ` )<sup >\* </sup > _ ConstParams_
8+ >   ;  ; (_ GenericParam_ ` , ` )<sup >\* </sup > _ GenericParam_ ` , ` <sup >?</sup >
119>
12- > _ LifetimeParams_ :\
13- >   ;  ; ( _ LifetimeParam_ ` , ` )<sup >\* </sup > _ LifetimeParam_ <sup >?</sup >
10+ > _ GenericParam_ :\
11+ >   ;  ; [ _ OuterAttribute_ ] <sup >\* </sup >\
12+ >   ;  ; (\
13+ >   ;  ;   ;  ;   ;  ; _ LifetimeParam_ \
14+ >   ;  ;   ;  ; | _ TypeParam_ \
15+ >   ;  ;   ;  ; | _ ConstParam_ \
16+ >   ;  ; )
1417>
1518> _ LifetimeParam_ :\
16- >   ;  ; [ _ OuterAttribute_ ] <sup >?</sup > [ LIFETIME_OR_LABEL]   ; ( ` : ` [ _ LifetimeBounds_ ] )<sup >?</sup >
17- >
18- > _ TypeParams_ :\
19- >   ;  ; ( _ TypeParam_ ` , ` )<sup >\* </sup > _ TypeParam_ <sup >?</sup >
19+ >   ;  ; [ LIFETIME_OR_LABEL]   ; ( ` : ` [ _ LifetimeBounds_ ] )<sup >?</sup >
2020>
2121> _ TypeParam_ :\
22- >   ;  ; [ _ OuterAttribute_ ] <sup >?</sup > [ IDENTIFIER] ( ` : ` [ _ TypeParamBounds_ ] <sup >?</sup > )<sup >?</sup > ( ` = ` [ _ Type_ ] )<sup >?</sup >
23- >
24- > _ ConstParams_ :\
25- >   ;  ; ( _ ConstParam_ ` , ` )<sup >\* </sup > _ ConstParam_ <sup >?</sup >
22+ >   ;  ; [ IDENTIFIER] ( ` : ` [ _ TypeParamBounds_ ] <sup >?</sup > )<sup >?</sup > ( ` = ` [ _ Type_ ] )<sup >?</sup >
2623>
2724> _ ConstParam_ :\
28- >   ;  ; [ _ OuterAttribute _ ] < sup >?</ sup > ` const ` [ IDENTIFIER] ` : ` [ _ Type_ ]
25+ >   ;  ; ` const ` [ IDENTIFIER] ` : ` [ _ Type_ ]
2926
3027Functions, type aliases, structs, enumerations, unions, traits, and
3128implementations may be * parameterized* by types, constants, and lifetimes. These
@@ -91,12 +88,15 @@ referred to with path syntax.
9188>   ;  ; _ ForLifetimes_ <sup >?</sup > [ _ Type_ ] ` : ` [ _ TypeParamBounds_ ] <sup >?</sup >
9289>
9390> _ ForLifetimes_ :\
94- >   ;  ; ` for ` ` < ` [ _ LifetimeParams _ ] ( #generic-parameters ) ` > `
91+ >   ;  ; ` for ` ` < ` [ _ GenericParams _ ] ( #generic-parameters ) ` > `
9592
9693* Where clauses* provide another way to specify bounds on type and lifetime
9794parameters as well as a way to specify bounds on types that aren't type
9895parameters.
9996
97+ The ` for ` keyword can be used to introduce [ higher-ranked lifetimes] . It only
98+ allows [ _ LifetimeParam_ ] parameters.
99+
100100Bounds that don't use the item's parameters or higher-ranked lifetimes are
101101checked when the item is defined. It is an error for such a bound to be false.
102102
@@ -141,6 +141,7 @@ struct Foo<#[my_flexible_clone(unbounded)] H> {
141141[ IDENTIFIER ] : ../identifiers.md
142142[ LIFETIME_OR_LABEL ] : ../tokens.md#lifetimes-and-loop-labels
143143
144+ [ _LifetimeParam_ ] : #generic-parameters
144145[ _LifetimeBounds_ ] : ../trait-bounds.md
145146[ _Lifetime_ ] : ../trait-bounds.md
146147[ _OuterAttribute_ ] : ../attributes.md
@@ -150,6 +151,7 @@ struct Foo<#[my_flexible_clone(unbounded)] H> {
150151[ arrays ] : ../types/array.md
151152[ const contexts ] : ../const_eval.md#const-context
152153[ function pointers ] : ../types/function-pointer.md
154+ [ higher-ranked lifetimes ] : ../trait-bounds.md#higher-ranked-trait-bounds
153155[ raw pointers ] : ../types/pointer.md#raw-pointers-const-and-mut
154156[ references ] : ../types/pointer.md#shared-references-
155157[ repeat expressions ] : ../expressions/array-expr.md
0 commit comments