rust-lang / rust-lang/rust

Support fn() types as const generic parameters

Open
#148,377 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-const-generics C-enhancement needs-triage
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Currently even with custom ADT const generics, fn() types are not allowed as const generic parameters types.

Adding that support would quite useful as it would allow to specify a ZST type that implements the Fn/FnOnce/FnMut traits by calling a const fn() value from a conat generic parameter (typically from an fb item), guaranteeing monomorphization.

Currently it seems the only way to do this is to manually create with a macro a separate type for each fn item.

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 issue description and trace the compiler's existing custom ADT const-generic support for function types. Determine the required language and compiler changes for accepting fn() types as const generic parameters, then add coverage demonstrating calls to const fn values and Fn/FnOnce/FnMut behavior.

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
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.