You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Lifetime | Type | GenericArgsConst | GenericArgsBinding | GenericArgsBounds
60
-
61
-
GenericArgsConst ->
62
-
BlockExpression
63
-
| LiteralExpression
64
-
| `-` LiteralExpression
65
-
| SimplePathSegment
66
-
67
-
GenericArgsBinding ->
68
-
IDENTIFIER GenericArgs? `=` Type
69
-
70
-
GenericArgsBounds ->
71
-
IDENTIFIER GenericArgs? `:` TypeParamBounds
72
53
```
73
54
74
55
r[paths.expr.intro]
@@ -82,38 +63,6 @@ The `::` token is required before the opening `<` for generic arguments to avoid
82
63
Vec::<u8>::with_capacity(1024);
83
64
```
84
65
85
-
r[paths.expr.argument-order]
86
-
The order of generic arguments is restricted to lifetime arguments, then type arguments, then const arguments, then equality constraints.
87
-
88
-
r[paths.expr.complex-const-params]
89
-
Const arguments must be surrounded by braces unless they are a [literal], an [inferred const], or a single segment path. An [inferred const] may not be surrounded by braces.
90
-
91
-
```rust
92
-
modm {
93
-
pubconstC:usize=1;
94
-
}
95
-
constC:usize=m::C;
96
-
fnf<constN:usize>() -> [u8; N] { [0; N] }
97
-
98
-
let_=f::<1>(); // Literal.
99
-
let_: [_; 1] =f::<_>(); // Inferred const.
100
-
let_: [_; 1] =f::<(((_)))>(); // Inferred const.
101
-
let_=f::<C>(); // Single segment path.
102
-
let_=f::<{ m::C }>(); // Multi-segment path must be braced.
103
-
```
104
-
105
-
```rust,compile_fail
106
-
fn f<const N: usize>() -> [u8; N] { [0; _] }
107
-
let _: [_; 1] = f::<{ _ }>();
108
-
// ^ ERROR `_` not allowed here
109
-
```
110
-
111
-
> [!NOTE]
112
-
> In a generic argument list, an [inferred const] is parsed as an [inferred type][InferredType] but then semantically treated as a separate kind of [const generic argument].
113
-
114
-
r[paths.expr.impl-trait-params]
115
-
The synthetic type parameters corresponding to `impl Trait` types are implicit, and these cannot be explicitly specified.
116
-
117
66
r[paths.qualified]
118
67
## Qualified paths
119
68
@@ -465,17 +414,14 @@ mod without { // crate::without
> In a generic argument list, an [inferred const] is parsed as an [inferred type][InferredType] but then semantically treated as a separate kind of [const generic argument].
152
152
153
153
r[generics.const.inferred]
154
-
Where a const argument is expected, an `_` (optionally surrounded by any number of matching parentheses), called the *inferred const* ([path rules][paths.expr.complex-const-params], [array expression rules][expr.array.length-restriction]), can be used instead. This asks the compiler to infer the const argument if possible based on surrounding information.
154
+
Where a const argument is expected, an `_` (optionally surrounded by any number of matching parentheses), called the *inferred const* ([generic argument rules][generics.arguments.complex-const-params], [array expression rules][expr.array.length-restriction]), can be used instead. This asks the compiler to infer the const argument if possible based on surrounding information.
Generic arguments are the concrete values provided for generic parameters when using a parameterized item. They are specified in angle brackets (`<...>`) following the item's path (see [paths in types] and [paths in expressions]). Generic arguments can include lifetimes, types, and const values corresponding to the generic parameters declared on the item.
Lifetime | Type | GenericArgsConst | GenericArgsBinding | GenericArgsBounds
257
+
258
+
GenericArgsConst ->
259
+
BlockExpression
260
+
| LiteralExpression
261
+
| `-` LiteralExpression
262
+
| SimplePathSegment
263
+
264
+
GenericArgsBinding ->
265
+
IDENTIFIER GenericArgs? `=` Type
266
+
267
+
GenericArgsBounds ->
268
+
IDENTIFIER GenericArgs? `:` TypeParamBounds
269
+
```
270
+
271
+
r[generics.arguments.argument-order]
272
+
The order of generic arguments is restricted to lifetime parameters and then type and const parameters intermixed.
273
+
274
+
r[generics.arguments.complex-const-params]
275
+
Const arguments must be surrounded by braces unless they are a [literal], an [inferred const], or a single segment path. An [inferred const] may not be surrounded by braces.
276
+
277
+
```rust
278
+
modm {
279
+
pubconstC:usize=1;
280
+
}
281
+
constC:usize=m::C;
282
+
fnf<constN:usize>() -> [u8; N] { [0; N] }
283
+
284
+
let_=f::<1>(); // Literal.
285
+
let_: [_; 1] =f::<_>(); // Inferred const.
286
+
let_: [_; 1] =f::<(((_)))>(); // Inferred const.
287
+
let_=f::<C>(); // Single segment path.
288
+
let_=f::<{ m::C }>(); // Multi-segment path must be braced.
289
+
```
290
+
291
+
```rust,compile_fail
292
+
fn f<const N: usize>() -> [u8; N] { [0; _] }
293
+
let _: [_; 1] = f::<{ _ }>();
294
+
// ^ ERROR `_` not allowed here
295
+
```
296
+
297
+
> [!NOTE]
298
+
> In a generic argument list, an [inferred const] is parsed as an [inferred type][InferredType] but then semantically treated as a separate kind of [const generic argument].
299
+
300
+
r[generics.arguments.impl-trait-params]
301
+
The synthetic type parameters corresponding to `impl Trait` types are implicit, and these cannot be explicitly specified.
0 commit comments