rust-lang / rust-lang/rust

Question/request: const generic dependencies

Open
#160,812 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-const-generics F-adt_const_params needs-triage T-types
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

(the adt_const_params tracking issue said to create an issue for questions and/or requests, so I'm doing that)

Under #![feature(adt_const_params)], I would expect the following to be allowed:

pub struct Array<const N: usize, const D: [usize; N]> {
    // ...
}

However, this gives an error:

error[E0770]: the type of const parameters must not depend on other generic parameters
  --> src/lib.rs:18:51
   |
18 | pub struct Array<const N: usize, const D: [usize; N]> {
   |                                                   ^ the type must not depend on the parameter `N`

This feels like a reasonably-common use of const type parameters; it would be nice for this to be supported.

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 by reproducing the adt_const_params example with const D: [usize; N] and inspect the reported E0770 diagnostic. Determine the language and compiler changes needed to permit const-parameter types that depend on earlier generic parameters; done means the example is accepted under the feature without regressing existing restrictions.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.