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 3 commits into
base: master
Choose a base branch
from
Open
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
13 changes: 13 additions & 0 deletions src/items/generics.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,19 @@ fn example() {
}
```

r[items.generics.const.inferred]
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.const.type-ambiguity]
When there is ambiguity if a generic argument could be resolved as either a
type or const argument, it is always resolved as a type. Placing the argument
Expand Down
Loading