Skip to content

Document inferred const args (feature(generic_arg_infer)) #1835

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/items/generics.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,28 @@ fn generic<const B: bool>() {
}
```

r[items.generics.const.inferred]

r[items.generics.const.inferred.syntax]
```grammar,items
InferredConst ->
`_`
| `(` InferredConst `)`
```

r[items.generics.const.inferred.intro]
Where a const argument is expected, an `_` (optionally surrounding by any number of matching parentheses), called the "inferred const", can be used instead. This asks the compiler to infer the const argument if possible based on surrounding information.

```rust
fn make_buf() -> [u8; 1024] {
[0x1; _]
// ^ Infers `1024`.
}
```

r[items.generics.const.inferred.constraint]
It cannot be used in item signatures.

r[items.generics.where]
## Where clauses

Expand Down
1 change: 1 addition & 0 deletions src/paths.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ GenericArgsConst ->
| LiteralExpression
| `-` LiteralExpression
| SimplePathSegment
| InferredConst
GenericArgsBinding ->
IDENTIFIER GenericArgs? `=` Type
Expand Down
Loading