Skip to content

mGCA: type check arguments to array expressions #152125

Closed

Description

@BoxyUwU

WellFormed goals for const generics currently don't require that the constituent consts of an array valtree have the same type as the element type of the valtree. This allows the following code to pass even though Bar is not of type Foo:

#![feature(adt_const_params, min_generic_const_args)]

use std::marker::ConstParamTy;

#[derive(Eq, PartialEq, ConstParamTy)]
struct Foo;

struct Bar;

fn foo<const N: [Foo; 1]>() {}

fn main() {
    foo::<{ [Bar] }>();
}

See #150713 as an example of where this was previously implemented for tuples. Implementing this will involve extending the Tuple arm to also cover Arrays.

Activity

  1. added
    E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
    E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    A-const-genericsArea: const generics (parameters and arguments)
    T-typesRelevant to the types team, which will review and decide on the PR/issue.
    F-gca_min_const_items`#![feature(gca_min_const_items)]` (previously: `min_generic_const_args`)
    on Feb 4, 2026
  2. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Feb 4, 2026
  3. removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Feb 4, 2026
  4. meithecatte commented on Feb 4, 2026

    @meithecatte
    Contributor

    @rustbot claim

  5. biscuitrescue commented on Feb 10, 2026

    @biscuitrescue
    Contributor

    Hi @meithecatte, are you still working on this? I'm interested in working on this and would love to help out if it's no bother to you.

  6. meithecatte commented on Feb 10, 2026

    @meithecatte
    Contributor

    Hi! I ended up getting deep into the weeds. If you'd like to work on this instead, feel free.

  7. biscuitrescue commented on Feb 10, 2026

    @biscuitrescue
    Contributor

    Sure, thankyou. @rustbot claim

  8. alv-around commented on Feb 10, 2026

    @alv-around
    Contributor

    Oops! I accidentally drafted a fix without realizing this was already claimed last week. Sorry about that, @biscuitrescue! I'm happy to collaborate on this PR together, or you can cherry-pick what I've done into your own branch—whatever is easiest for you! 🦀

  9. biscuitrescue commented on Feb 11, 2026

    @biscuitrescue
    Contributor

    @alv-around I already implemented the fix but I'd love to double check and compare. Never hurts to be careful ;)

  10. biscuitrescue commented on Feb 11, 2026

    @biscuitrescue
    Contributor

    @BoxyUwU I have implemented the fix but I wanted to clarify if my approach aligns with how this should be solved.

    The current implementation adds a separate ty::Array arm alongside the existing ty::Tuple. The Array arm is similar to how the Tuple fix was done in #150713. The logic for both only differs in how element types are extracted.

    Which approach would you prefer?

    ty::Tuple(field_tys) => { ... }
    ty::Array(elem_ty, _) => { ... }

    or

    ty::Tuple(_) | ty::Array(_, _) => { ... } // with a match
  11. biscuitrescue commented on Feb 11, 2026

    @biscuitrescue
    Contributor

    Nevermind, I tried to implement both in the same arm, but it creates more problems than its worth due because requires an inner match on the same variable that's running on the outer match. Separate arms look cleaner.

  12. added a commit that references this issue on Feb 24, 2026
    b8999f2
  13. added a commit that references this issue on Feb 24, 2026
    3e4d4ad
  14. added a commit that references this issue on Mar 2, 2026
    a9e876c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-const-genericsArea: const generics (parameters and arguments)E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.F-adt_const_params`#![feature(adt_const_params)]`F-gca_min_const_items`#![feature(gca_min_const_items)]` (previously: `min_generic_const_args`)T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-typesRelevant to the types team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions