Skip to content

Commit d76890c

Browse files
committed
Remove InferredConst production
In actuality, the parser is going to treat an inferred const as an inferred type, so we don't need a separate rule for this, and removing this rule avoids some ambiguity in our grammar. We'll add a note describing this situation.
1 parent 1804fb6 commit d76890c

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

src/items/generics.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,12 +172,12 @@ fn example() {
172172
```
173173

174174
r[items.generics.const.inferred]
175-
Where a const argument is expected, an `_` (optionally surrounding by any number of matching parentheses), called the *inferred const* ([grammar][InferredConst], [path rules][paths.expr.complex-const-params]), can be used instead. This asks the compiler to infer the const argument if possible based on surrounding information.
175+
Where a const argument is expected, an `_` (optionally surrounding by any number of matching parentheses), called the *inferred const* ([path rules][paths.expr.complex-const-params]), can be used instead. This asks the compiler to infer the const argument if possible based on surrounding information.
176176

177177
```rust
178178
fn make_buf<const N: usize>() -> [u8; N] {
179-
[0x1; _]
180-
// ^ Infers `N`.
179+
[0; _]
180+
// ^ Infers `N`.
181181
}
182182
let _: [u8; 1024] = make_buf::<_>();
183183
// ^ Infers `1024`.

src/paths.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,10 @@ GenericArg ->
6262
6363
GenericArgsConst ->
6464
BlockExpression
65-
| InferredConst
6665
| LiteralExpression
6766
| `-` LiteralExpression
6867
| SimplePathSegment
6968
70-
InferredConst ->
71-
| `(` InferredConst `)`
72-
| `_`
73-
7469
GenericArgsBinding ->
7570
IDENTIFIER GenericArgs? `=` Type
7671
@@ -96,7 +91,7 @@ The order of generic arguments is restricted to lifetime arguments, then type
9691
arguments, then const arguments, then equality constraints.
9792

9893
r[paths.expr.complex-const-params]
99-
Const arguments must be surrounded by braces unless they are a [literal], an [inferred const] ([grammar][InferredConst]), or a single segment path.
94+
Const arguments must be surrounded by braces unless they are a [literal], an [inferred const], or a single segment path.
10095

10196
```rust
10297
mod m {
@@ -112,6 +107,9 @@ let _ = f::<C>(); // Single segment path.
112107
let _ = f::<{ m::C }>(); // Multi-segment path must be braced.
113108
```
114109

110+
> [!NOTE]
111+
> An [inferred const] is parsed as an [inferred type] but then semantically treated as a separate kind of [const generic argument].
112+
115113
r[paths.expr.impl-trait-params]
116114
The synthetic type parameters corresponding to `impl Trait` types are implicit,
117115
and these cannot be explicitly specified.
@@ -498,11 +496,13 @@ mod without { // crate::without
498496
[`Self` scope]: names/scopes.md#self-scope
499497
[`use`]: items/use-declarations.md
500498
[attributes]: attributes.md
499+
[const generic argument]: items.generics.const.argument
501500
[enumeration]: items/enumerations.md
502501
[expressions]: expressions.md
503502
[extern prelude]: names/preludes.md#extern-prelude
504503
[implementation]: items/implementations.md
505504
[inferred const]: items.generics.const.inferred
505+
[inferred type]: type.inferred
506506
[macro transcribers]: macros-by-example.md
507507
[macros]: macros.md
508508
[mbe]: macros-by-example.md

0 commit comments

Comments
 (0)