Skip to content

Tracking Issue for more complex const parameter types: feature(adt_const_params) #95174

Open

Description

@lcnr

This is a tracking issue for allowing more const parameter types.
The feature gate for this issue is #![feature(adt_const_params)].

About tracking issues

Tracking issues are used to record the overall progress of implementation.
They are also used as hubs connecting to other relevant issues, e.g., bugs or open design questions.
A tracking issue is however not meant for large scale discussion, questions, or bug reports about a feature.
Instead, open a dedicated issue for the specific matter and add the relevant feature gate label.

Steps

Most of the work here will be coordinated in the #project-const-generics stream on zulip.

Unresolved Questions

cc @rust-lang/project-const-generics

Activity

  1. added
    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFC
    A-const-genericsArea: const generics (parameters and arguments)
    on Mar 21, 2022
  2. changed the title [-]Tracking Issue for more complex const parameter types (`adt_const_params`)[/-] [+]Tracking Issue for more complex const parameter types: `feature(adt_const_params)`[/+] on Mar 21, 2022
  3. added 2 commits that reference this issue on Mar 21, 2022
  4. griffi-gh commented on Oct 14, 2022

    @griffi-gh

    I think at least simple enums without assigned values should be allowed for now

  5. tarcieri commented on Oct 14, 2022

    @tarcieri
    Contributor

    @griffi-gh I agree. However, in the meantime if you have an e.g. repr(u64) C-style enum, you can cast it with as u64 (or whatever integer type) to sort of fake being const generic around an enum, and that works fine even in const contexts, while also hopefully being trivially upgradable to adt_const_params in the future.

  6. jhpratt commented on Oct 15, 2022

    @jhpratt
    Member

    For what it's worth, I am currently hacking around this in time by encoding a struct into a u128, passing as a const generic, and decoding it back to the original struct. All at compile time, as the values are then associated constants. This approach is tedious, but it works for everything up to 16 bytes in size.

  7. mqudsi commented on Nov 6, 2022

    @mqudsi
  8. eminence commented on Nov 22, 2022

    @eminence
    Contributor

    Once place where adt_const_params really shines is in diagnostics. Consider the following stable code, which casts a repr(u8) enum, to be used in a const generic:

    #[repr(u8)]
    pub enum Facing {
        Up,
        Down,
    }
    
    pub struct Card<const FACING: u8> {
        // would normally have a "suit" and "number" field
    }
    
    pub fn foo(card: Card<{Facing::Up as u8}>) {
        let _: Card<{Facing::Down as u8}> = card;
    }
       |
    12 |     let _: Card<{Facing::Down as u8}> = card;
       |            --------------------------   ^^^^ expected `1`, found `0`
       |            |
       |            expected due to this
       |
       = note: expected struct `Card<1>`
                  found struct `Card<0>`
    

    But with a real enum and adt_const_params, the error message is much clearer:

       |
    14 |     let _: Card<{Facing::Down}> = card;
       |            --------------------   ^^^^ expected `Facing::Down`, found `Facing::Up`
       |            |
       |            expected due to this
       |
       = note: expected struct `Card<Facing::Down>`
                  found struct `Card<Facing::Up>`
    
  9. 18 remaining items

  10. added a commit that references this issue on Aug 19, 2024
  11. added a commit that references this issue on Sep 23, 2024
  12. added a commit that references this issue on Sep 23, 2024
  13. added a commit that references this issue on Sep 23, 2024
  14. added a commit that references this issue on Sep 30, 2024
  15. added a commit that references this issue on Sep 30, 2024
  16. added
    T-typesRelevant to the types team, which will review and decide on the PR/issue.
    on Feb 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-genericsArea: const generics (parameters and arguments)C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCF-adt_const_params`#![feature(adt_const_params)]`T-langRelevant to the language teamT-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