rust-lang / rust-lang/reference

Add const generic default restrictions

Open
#1,159 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-generics
Dominant language
Rust
Stars
1.6k
Forks
607
PR merge metrics
PR metrics pending

Description

With const generic defaults stabilized (#90207), the reference should talk more about what the restrictions are.

  • What are valid expressions for the default? I assume it has to be a constant expression, are there other restrictions?
  • Presumably this is a const context, so I think "default const parameters" should be added to that list.
  • Restrictions on the type of the default expression. I believe it must be the same type as the declaration, but can there be any coercion?
  • Const defaults are only allowed on struct/enum/type/trait, but not fn or …

Are there other details about const generic defaults that can be added?
Note: default generic parameters are not documented at all. That is a separate issue (#24). That would also be great to complete, but I think can be done somewhat separately of this issue.

See also stabilization report: https://github.com/rust-lang/rust/pull/90207#issuecomment-958843546
and #1098.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Rust Reference's const evaluation sections and the stabilization report in #90207, then compare the related discussion in #1098 and the separate issue #24. Document the confirmed restrictions for const generic defaults, including valid defaults, const-context treatment, type compatibility, and permitted item kinds; done means these cases are covered without taking on general default generic parameters.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
documentation
Issue type
Documentation
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.