2
2
3
3
> ** <sup >Syntax</sup >** \
4
4
> _ Generics_ :\
5
- >   ;  ; ` < ` _ GenericParams_ ` > `
5
+ >   ;  ; ` < ` _ GenericParams_ < sup >?</ sup > ` > `
6
6
>
7
7
> _ GenericParams_ :\
8
- >   ;  ;   ;  ; _ LifetimeParams_ \
9
- >   ;  ; | ( _ LifetimeParam_ ` , ` )<sup >\* </sup > _ TypeParams_ \
10
- >   ;  ; | ( _ LifetimeParam_ ` , ` )<sup >\* </sup > ( _ TypeParam_ ` , ` )<sup >\* </sup > _ ConstParams_
8
+ >   ;  ; (_ GenericParam_ ` , ` )<sup >\* </sup > _ GenericParam_ ` , ` <sup >?</sup >
11
9
>
12
- > _ LifetimeParams_ :\
13
- >   ;  ; ( _ LifetimeParam_ ` , ` )<sup >\* </sup > _ LifetimeParam_ <sup >?</sup >
10
+ > _ GenericParam_ :\
11
+ >   ;  ; [ _ OuterAttribute_ ] <sup >\* </sup >\
12
+ >   ;  ; (\
13
+ >   ;  ;   ;  ;   ;  ; _ LifetimeParam_ \
14
+ >   ;  ;   ;  ; | _ TypeParam_ \
15
+ >   ;  ;   ;  ; | _ ConstParam_ \
16
+ >   ;  ; )
14
17
>
15
18
> _ 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 >
20
20
>
21
21
> _ 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 >
26
23
>
27
24
> _ ConstParam_ :\
28
- >   ;  ; [ _ OuterAttribute _ ] < sup >?</ sup > ` const ` [ IDENTIFIER] ` : ` [ _ Type_ ]
25
+ >   ;  ; ` const ` [ IDENTIFIER] ` : ` [ _ Type_ ]
29
26
30
27
Functions, type aliases, structs, enumerations, unions, traits, and
31
28
implementations may be * parameterized* by types, constants, and lifetimes. These
@@ -91,12 +88,15 @@ referred to with path syntax.
91
88
>   ;  ; _ ForLifetimes_ <sup >?</sup > [ _ Type_ ] ` : ` [ _ TypeParamBounds_ ] <sup >?</sup >
92
89
>
93
90
> _ ForLifetimes_ :\
94
- >   ;  ; ` for ` ` < ` [ _ LifetimeParams _ ] ( #generic-parameters ) ` > `
91
+ >   ;  ; ` for ` ` < ` [ _ GenericParams _ ] ( #generic-parameters ) ` > `
95
92
96
93
* Where clauses* provide another way to specify bounds on type and lifetime
97
94
parameters as well as a way to specify bounds on types that aren't type
98
95
parameters.
99
96
97
+ The ` for ` keyword can be used to introduce [ higher-ranked lifetimes] . It only
98
+ allows [ _ LifetimeParam_ ] parameters.
99
+
100
100
Bounds that don't use the item's parameters or higher-ranked lifetimes are
101
101
checked when the item is defined. It is an error for such a bound to be false.
102
102
@@ -141,6 +141,7 @@ struct Foo<#[my_flexible_clone(unbounded)] H> {
141
141
[ IDENTIFIER ] : ../identifiers.md
142
142
[ LIFETIME_OR_LABEL ] : ../tokens.md#lifetimes-and-loop-labels
143
143
144
+ [ _LifetimeParam_ ] : #generic-parameters
144
145
[ _LifetimeBounds_ ] : ../trait-bounds.md
145
146
[ _Lifetime_ ] : ../trait-bounds.md
146
147
[ _OuterAttribute_ ] : ../attributes.md
@@ -150,6 +151,7 @@ struct Foo<#[my_flexible_clone(unbounded)] H> {
150
151
[ arrays ] : ../types/array.md
151
152
[ const contexts ] : ../const_eval.md#const-context
152
153
[ function pointers ] : ../types/function-pointer.md
154
+ [ higher-ranked lifetimes ] : ../trait-bounds.md#higher-ranked-trait-bounds
153
155
[ raw pointers ] : ../types/pointer.md#raw-pointers-const-and-mut
154
156
[ references ] : ../types/pointer.md#shared-references-
155
157
[ repeat expressions ] : ../expressions/array-expr.md
0 commit comments