Skip to content

Support function args const generics - #162727

Open
bit-aloo wants to merge 8 commits into
rust-lang:mainfrom
bit-aloo:2026-09-06-function-argument-const-generics
Open

bit-aloo wants to merge 8 commits into
rust-lang:mainfrom
bit-aloo:2026-09-06-function-argument-const-generics

Conversation

@bit-aloo

@bit-aloo bit-aloo commented Sep 13, 2026 •

Copy link
Copy Markdown
Member

This PR adds initial support for argument-position const generics behind the function_arg_const_generics feature gate.

It allows const generics to be declared directly in function arguments. The PR adds the basic plumbing across AST, HIR, and ty, parses these parameters into the function's generics, lowers call arguments into consts. For now, we lower literals, negated literals, const parameters, const items, unit variants, and etc, This works for functions, methods and a couple of more cases.

r? @BoxyUwU
cc: @khyperia

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustfmt Relevant to the rustfmt team, which will review and decide on the PR/issue. labels Sep 13, 2026
@rust-log-analyzer

This comment has been minimized.

@BoxyUwU BoxyUwU self-assigned this Sep 13, 2026
Comment thread compiler/rustc_parse/src/parser/function.rs Outdated
Comment thread compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs Outdated
@rust-log-analyzer

This comment has been minimized.

@rust-cloud-vms
rust-cloud-vms Bot force-pushed the 2026-09-06-function-argument-const-generics branch from 069cb06 to 0816e30 Compare September 14, 2026 10:55
@rust-bors

This comment has been minimized.

@rust-cloud-vms
rust-cloud-vms Bot force-pushed the 2026-09-06-function-argument-const-generics branch from 0816e30 to 74ba4f6 Compare September 24, 2026 13:50
@rustbot rustbot added the T-clippy Relevant to the Clippy team. label Sep 24, 2026
@rustbot

rustbot commented Sep 24, 2026

Copy link
Copy Markdown
Collaborator

Requested reviewer is already assigned to this pull request.

Please choose another assignee.

@bit-aloo
bit-aloo marked this pull request as ready for review September 24, 2026 17:29
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 24, 2026
@rustbot

rustbot commented Sep 24, 2026

Copy link
Copy Markdown
Collaborator

rustfmt is developed in its own repository. If possible, consider making this change to rust-lang/rustfmt instead.

cc @rust-lang/rustfmt

This PR changes rustc_public

cc @oli-obk, @celinval, @ouz-a, @makai410

The parser was modified, potentially altering the grammar of (stable) Rust
which would be a breaking change.

cc @fmease

Changes to the size of AST and/or HIR nodes.

cc @nnethercote

HIR ty lowering was modified

cc @fmease

clippy is developed in its own repository. If possible, consider making this change to rust-lang/rust-clippy instead.

cc @rust-lang/clippy

@rustbot rustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Sep 24, 2026
ref ty,
span,
default,
arg_pos: _,

@ytmimi ytmimi Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is arg_pos, and does rustfmt need to handle formatting it in some way?

Probably good to add a #![feature(function_arg_const_generics] test case to rustfmt to make sure things are getting formatted as expected.

View changes since the review

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustfmt Relevant to the rustfmt team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants