Skip to content

Support function args const generics - #162727

Merged
rust-bors[bot] merged 14 commits into
rust-lang:mainfrom
bit-aloo:2026-09-06-function-argument-const-generics
Oct 14, 2026
Merged

rust-bors[bot] merged 14 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

View all comments

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
Comment thread src/tools/rustfmt/src/types.rs Outdated
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

@rust-bors

This comment has been minimized.

@khyperia khyperia left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm feeling a bit overwhelmed and struggling to review this, and haven't gotten through the parser changes yet. Still though, wanted to comment for what I've seen so far. I think I'd appreciate talking over how to deal with lowering here in zulip or something, I haven't fully thought through the theory space. If you have any direction/resources/etc. on lowering (e.g. whether we fundamentally must lower from hir instead of ast, what potential issues there are from doing so), I'd love to see.

View changes since this review

Comment thread compiler/rustc_ast/src/ast.rs Outdated
Comment thread compiler/rustc_feature/src/unstable.rs Outdated
Comment thread compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs
@rust-cloud-vms
rust-cloud-vms Bot force-pushed the 2026-09-06-function-argument-const-generics branch from 74ba4f6 to e0fc639 Compare October 7, 2026 10:41
@rustbot

rustbot commented Oct 7, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred in compiler/rustc_builtin_macros/src/autodiff.rs

cc @ZuseZ4

@khyperia khyperia left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

rawr, nice! looks good to me :3 just a couple nits!

... I am realizing now that you poking in Zulip maybe didn't imply you wanted a rereview but I only realized this just now after writing all this, so uuuh, get reviewed I guess

View changes since this review

Comment thread compiler/rustc_ast/src/ast.rs Outdated
Comment thread compiler/rustc_ast/src/ast.rs Outdated
Comment thread compiler/rustc_hir/src/hir.rs Outdated
@khyperia khyperia added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 8, 2026
@rust-cloud-vms
rust-cloud-vms Bot force-pushed the 2026-09-06-function-argument-const-generics branch 2 times, most recently from 9d3480a to 08a6a30 Compare October 9, 2026 09:08
@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (c48133e): comparison URL.

Overall result: ❌✅ regressions and improvements - please read:

Benchmarking means the PR may be perf-sensitive. It's automatically marked not fit for rolling up. Overriding is possible but disadvised: it risks changing compiler perf.

Next, please: If you can, justify the regressions found in this try perf run in writing along with @rustbot label: +perf-regression-triaged. If not, fix the regressions and do another perf run. Neutral or positive results will clear the label automatically.

@bors rollup=never rustc-perf
@rustbot label: -S-waiting-on-perf +perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
0.1% [0.1%, 0.1%] 3
Regressions ❌
(secondary)
0.3% [0.1%, 0.4%] 10
Improvements ✅
(primary)
-0.3% [-0.6%, -0.1%] 5
Improvements ✅
(secondary)
-0.4% [-0.7%, -0.1%] 39
All ❌✅ (primary) -0.1% [-0.6%, 0.1%] 8

Max RSS (memory usage)

Results (primary -1.1%, secondary -2.0%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
1.1% [1.1%, 1.1%] 1
Regressions ❌
(secondary)
4.6% [4.6%, 4.6%] 1
Improvements ✅
(primary)
-2.1% [-2.7%, -1.6%] 2
Improvements ✅
(secondary)
-8.7% [-8.7%, -8.7%] 1
All ❌✅ (primary) -1.1% [-2.7%, 1.1%] 3

Cycles

Results (primary 2.4%, secondary 1.8%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
2.4% [2.1%, 2.6%] 2
Regressions ❌
(secondary)
3.3% [2.1%, 4.8%] 3
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.5% [-2.5%, -2.5%] 1
All ❌✅ (primary) 2.4% [2.1%, 2.6%] 2

Binary size

Results (primary -0.0%, secondary -0.0%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.0% [-0.1%, -0.0%] 4
Improvements ✅
(secondary)
-0.0% [-0.1%, -0.0%] 2
All ❌✅ (primary) -0.0% [-0.1%, -0.0%] 4

Bootstrap: 487.044s -> 489.815s (0.57%)
Artifact size: 406.45 MiB -> 406.75 MiB (0.07%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Oct 10, 2026
@bit-aloo

Copy link
Copy Markdown
Member Author

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Oct 10, 2026
@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Oct 10, 2026
…enerics, r=<try>

Support function args const generics
@rust-bors

rust-bors Bot commented Oct 10, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 5415718 (5415718efb0ab088d913bf332f4581c437f1cd84)
Base parent: 6e4cba3 (6e4cba3380a6f9e1e4d7672e11e40372bf04e873)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (5415718): comparison URL.

Overall result: ❌✅ regressions and improvements - please read:

Benchmarking means the PR may be perf-sensitive. It's automatically marked not fit for rolling up. Overriding is possible but disadvised: it risks changing compiler perf.

Next, please: If you can, justify the regressions found in this try perf run in writing along with @rustbot label: +perf-regression-triaged. If not, fix the regressions and do another perf run. Neutral or positive results will clear the label automatically.

@bors rollup=never rustc-perf
@rustbot label: -S-waiting-on-perf +perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
0.1% [0.1%, 0.1%] 1
Regressions ❌
(secondary)
0.3% [0.1%, 0.3%] 8
Improvements ✅
(primary)
-0.3% [-0.6%, -0.1%] 6
Improvements ✅
(secondary)
-0.4% [-0.7%, -0.1%] 39
All ❌✅ (primary) -0.2% [-0.6%, 0.1%] 7

Max RSS (memory usage)

Results (primary 1.3%, secondary 2.0%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
1.9% [0.6%, 2.8%] 8
Regressions ❌
(secondary)
3.8% [0.9%, 9.8%] 8
Improvements ✅
(primary)
-2.9% [-2.9%, -2.9%] 1
Improvements ✅
(secondary)
-2.8% [-3.2%, -2.2%] 3
All ❌✅ (primary) 1.3% [-2.9%, 2.8%] 9

Cycles

Results (secondary 4.4%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
7.5% [2.8%, 11.5%] 5
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-3.3% [-3.8%, -2.8%] 2
All ❌✅ (primary) - - 0

Binary size

Results (primary 0.1%, secondary 0.1%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
0.1% [0.0%, 0.2%] 123
Regressions ❌
(secondary)
0.1% [0.0%, 0.2%] 105
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.1% [0.0%, 0.2%] 123

Bootstrap: 488.311s -> 489.736s (0.29%)
Artifact size: 407.22 MiB -> 406.75 MiB (-0.12%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Oct 10, 2026
@bit-aloo
bit-aloo requested a review from fmease October 12, 2026 20:44

@fmease fmease left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

FnParseMode.allow_const is quite vague of a field name. If you don't look at its docs it could perceivably refer to sth. like "allow const on fn aka const fn"

Otherwise the parser changes LGTM now

View changes since this review

@khyperia

Copy link
Copy Markdown
Member

@bors r+

@rust-bors

rust-bors Bot commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 8104522 has been approved by khyperia

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 13, 2026
@JonathanBrouwer

Copy link
Copy Markdown
Member

@bors rollup=iffy
Making a rollup of perf sensitive PRs

rust-bors Bot pushed a commit that referenced this pull request Oct 14, 2026
…uwer

Rollup of 3 perf-sensitive pull requests

Successful merges:

 - #162727 (Support function args const generics)
 - #164059 (perf: drop error in `unwrap_failed` instead of `unwrap`)
 - #164236 (Move `fully_perform` early return earlier)
rust-bors Bot pushed a commit that referenced this pull request Oct 14, 2026
…uwer

Rollup of 3 perf-sensitive pull requests

Successful merges:

 - #162727 (Support function args const generics)
 - #164059 (perf: drop error in `unwrap_failed` instead of `unwrap`)
 - #164236 (Move `fully_perform` early return earlier)
rust-bors Bot pushed a commit that referenced this pull request Oct 14, 2026
Rollup merge of #162727 - bit-aloo:2026-09-06-function-argument-const-generics, r=khyperia

Support function args const generics

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
@rust-bors
rust-bors Bot merged commit 49c9894 into rust-lang:main Oct 14, 2026
14 checks passed
@rustbot rustbot added this to the 1.101.0 milestone Oct 14, 2026
@bit-aloo
bit-aloo deleted the 2026-09-06-function-argument-const-generics branch October 14, 2026 11:49
@rust-timer

Copy link
Copy Markdown
Collaborator

Note

This PR was benchmarked as part of triage of its containing rollup: triage URL.

Finished benchmarking commit (91a47b5): comparison URL.

Overall result: ❌ regressions - please read:

Our benchmarks found a performance regression caused by this PR.
This might be an actual regression, but it can also be just noise.

Next Steps:

  • If the regression was expected or you think it can be justified,
    please write a comment with sufficient written justification, and add
    @rustbot label: +perf-regression-triaged to it, to mark the regression as triaged.
  • If you think that you know of a way to resolve the regression, try to create
    a new PR with a fix for the regression.
  • If you do not understand the regression or you think that it is just noise,
    you can ask the @rust-lang/wg-compiler-performance working group for help (members of this group
    were already notified of this PR).

@rustbot label: +perf-regression
cc @rust-lang/wg-compiler-performance

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
0.2% [0.1%, 0.3%] 4
Regressions ❌
(secondary)
0.3% [0.1%, 0.6%] 11
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.3% [-0.3%, -0.3%] 1
All ❌✅ (primary) 0.2% [0.1%, 0.3%] 4

Max RSS (memory usage)

Results (secondary -3.5%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-3.5% [-3.5%, -3.5%] 1
All ❌✅ (primary) - - 0

Cycles

Results (secondary -2.4%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.4% [-2.4%, -2.4%] 1
All ❌✅ (primary) - - 0

Binary size

This perf run didn't have relevant results for this metric.

Artifact size: 406.81 MiB -> 406.98 MiB (0.04%)

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

Labels

perf-regression Performance regression. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.

9 participants