Skip to content

Add support for splatted function pointers - #159643

Merged
rust-bors[bot] merged 3 commits into
rust-lang:mainfrom
teor2345:splat-fn-ptr
Aug 8, 2026
Merged

Add support for splatted function pointers#159643
rust-bors[bot] merged 3 commits into
rust-lang:mainfrom
teor2345:splat-fn-ptr

Conversation

@teor2345

@teor2345teor2345 commented Jul 21, 2026

Copy link
Copy Markdown
Member

View all comments

Tracking issue: #153629

This PR adds support for splatted function pointers.

Currently splatted function pointers ICE due to unpopulated side-tables. This PR fixes the ICE by populating the side-table correctly, and fixes the MIR lowering code. It also refactors the surrounding code to reduce code duplication.

Generic function pointers also work. I'm sure if there's something extra we need to do to support all generic function pointers?

Close#158603

@rustbotrustbot 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. labels Jul 21, 2026
@teor2345

This comment was marked as resolved.

@rustbotrustbot added F-splat `#![feature(splat)]` https://github.com/rust-lang/rust/issues/153629 I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ labels Jul 21, 2026
@teor2345

Copy link
Copy Markdown
MemberAuthor

@rustbot label +C-bug

@rustbotrustbot added the C-bug Category: This is a bug. label Jul 21, 2026
@rust-log-analyzer

This comment has been minimized.

@teor2345
teor2345 marked this pull request as ready for review July 23, 2026 04:23
@rustbotrustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 23, 2026
@rustbotrustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jul 23, 2026
@rustbot

Copy link
Copy Markdown
Collaborator

r? @petrochenkov

rustbot has assigned @petrochenkov.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 74 candidates
  • Random selection from 20 candidates

@petrochenkov

Copy link
Copy Markdown
Contributor

@rustbot reroll

Comment threadcompiler/rustc_hir_typeck/src/fn_ctxt/checks.rs Outdated

@folkertdevfolkertdev left a comment

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.

This PR got quite big and seemingly fixes a bunch of different things, is there any chance you can split it up? At least the refactoring into using the custom enums seems like it could be split out, just stubbing out the branches for FnPtr and errors. If possible a separate PR would be nice (just assign me as a reviewer to preserve context), otherwise separate commits would also work.

It's just really tough to review like this.

View changes since this review


fn main() {
// FIXME(rustfmt): the attribute gets deleted by rustfmt
#[rustfmt::skip]

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.

Might be better to put the #[rustfmt::skip] on the function to reduce noise?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Happy to do that. It's better for readability, but slightly worse for maintenance because now every line is unformatted, not just the splatted type lines.

Ultimately we'll fix this in rustfmt if function argument attributes become a thing.

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.

We usually just use assert_eq!, is there any particular reason to deviate from that? Your generic<T: Tuple + Debug>(#[splat] a: T) could use format! and return a String?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

No particular reason, it will be much more readable to use assert_eq! across all the splat UI tests. The generic case can just return the argument.

A codegen bug could swap the tupled argument and return value, or overwrite the return value, but the multi-argument case will catch that. Or it might be worth having a test that swaps the order of the arguments in the return value. I'll have a think about it.

receiver: Option<&'tcx hir::Expr<'tcx>>,
has_receiver: bool,
// This is the method receiver, or the function path
receiver_or_func: &'tcx hir::Expr<'tcx>,

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.

this still feels kind of wrong, although I don't have any obviously better suggestions.

@teor2345teor2345Jul 27, 2026

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

To make the states clearer, it could be:

enumSplattedFunc{FnDefReceiver(Expr),/* NoFnDefReceiver, edit: can't be known at call site */FnPtrExpression(Expr),}

@rustbotrustbot 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 Jul 25, 2026
@rustbot

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@teor2345teor2345 left a comment

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

This PR got quite big and seemingly fixes a bunch of different things, is there any chance you can split it up? At least the refactoring into using the custom enums seems like it could be split out, just stubbing out the branches for FnPtr and errors. If possible a separate PR would be nice (just assign me as a reviewer to preserve context), otherwise separate commits would also work.

That's good feedback. I ended up squashing the whole thing to make it easier to rebase and rewrite, but I didn't split it into commits again.

I think it can be split into something like:

  • inline the splatted_callee function
  • refactor using custom enums (with stubs)
  • support for splatted FnPtrs

In a separate PR:

  • update tests to use assert_eq! (and a single rustfmt::skip)
    • edit: for FnPtr specific tests, I made this change in the commit where I added FnPtr support
  • remove resolved FIXMEs in splat UI tests

If you'd like some of those commits in different PRs, or in a different order, please let me know.

View changes since this review

receiver: Option<&'tcx hir::Expr<'tcx>>,
has_receiver: bool,
// This is the method receiver, or the function path
receiver_or_func: &'tcx hir::Expr<'tcx>,

@teor2345teor2345Jul 27, 2026

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

To make the states clearer, it could be:

enumSplattedFunc{FnDefReceiver(Expr),/* NoFnDefReceiver, edit: can't be known at call site */FnPtrExpression(Expr),}


fn main() {
// FIXME(rustfmt): the attribute gets deleted by rustfmt
#[rustfmt::skip]

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Happy to do that. It's better for readability, but slightly worse for maintenance because now every line is unformatted, not just the splatted type lines.

Ultimately we'll fix this in rustfmt if function argument attributes become a thing.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

No particular reason, it will be much more readable to use assert_eq! across all the splat UI tests. The generic case can just return the argument.

A codegen bug could swap the tupled argument and return value, or overwrite the return value, but the multi-argument case will catch that. Or it might be worth having a test that swaps the order of the arguments in the return value. I'll have a think about it.

@rustbot

This comment has been minimized.

@teor2345

Copy link
Copy Markdown
MemberAuthor

I split into these commits:

  • inline the splatted_callee function
  • refactor using custom enums (with stubs)
  • support for splatted FnPtrs
    • including test cleanups for FnPtr tests

And I opened PR #160049 with the unrelated test cleanups.

@rustbot ready

@rustbotrustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jul 28, 2026
@rust-bors

rust-borsBot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

📌 Commit f88563c has been approved by folkertdev

It is now in the queue for this repository.

@rust-borsrust-borsBot 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 Aug 6, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Aug 6, 2026
Add support for splatted function pointers
Tracking issue: rust-lang#153629
This PR adds support for splatted function pointers.
Currently splatted function pointers ICE due to unpopulated side-tables. This PR fixes the ICE by populating the side-table correctly, and fixes the MIR lowering code. It also refactors the surrounding code to reduce code duplication.
Generic function pointers also work. I'm sure if there's something extra we need to do to support all generic function pointers?
Closerust-lang#158603
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Aug 6, 2026
Add support for splatted function pointers
Tracking issue: rust-lang#153629
This PR adds support for splatted function pointers.
Currently splatted function pointers ICE due to unpopulated side-tables. This PR fixes the ICE by populating the side-table correctly, and fixes the MIR lowering code. It also refactors the surrounding code to reduce code duplication.
Generic function pointers also work. I'm sure if there's something extra we need to do to support all generic function pointers?
Closerust-lang#158603
jhpratt added a commit to jhpratt/rust that referenced this pull request Aug 7, 2026
Add support for splatted function pointers
Tracking issue: rust-lang#153629
This PR adds support for splatted function pointers.
Currently splatted function pointers ICE due to unpopulated side-tables. This PR fixes the ICE by populating the side-table correctly, and fixes the MIR lowering code. It also refactors the surrounding code to reduce code duplication.
Generic function pointers also work. I'm sure if there's something extra we need to do to support all generic function pointers?
Closerust-lang#158603
@jhprattjhpratt mentioned this pull request Aug 7, 2026
jhpratt added a commit to jhpratt/rust that referenced this pull request Aug 7, 2026
Add support for splatted function pointers
Tracking issue: rust-lang#153629
This PR adds support for splatted function pointers.
Currently splatted function pointers ICE due to unpopulated side-tables. This PR fixes the ICE by populating the side-table correctly, and fixes the MIR lowering code. It also refactors the surrounding code to reduce code duplication.
Generic function pointers also work. I'm sure if there's something extra we need to do to support all generic function pointers?
Closerust-lang#158603
@jhprattjhpratt mentioned this pull request Aug 7, 2026
rust-borsBot pushed a commit that referenced this pull request Aug 7, 2026
Rollup of 14 pull requests
Successful merges:
- #150885 (Revive L4Re target)
- #159643 (Add support for splatted function pointers)
- #160433 (delegation: add support for wrapping of the return value with `From::from`)
- #160530 (refactor handling of target features in Session)
- #160606 (bootstrap: Store and use an explicit CheckKind in `check::Rustc`)
- #160628 (fix ICE in `suggest_add_reference_to_arg` for non-callable items)
- #160634 (miri subtree update)
- #158904 (Fix FutureDropPoll shim for by-move async closures)
- #160335 (dlopen offload)
- #160445 (codegen: classify localized MSVC linker progress as linker_info)
- #160504 (cleanup borrowck, improve c-variadic handling)
- #160587 (Add regression test for associated type outlives bound at call site)
- #160625 (platform-support/netbsd.md: No longer mention 8.x, due to EoL.)
- #160636 (derive(Diagnostic): link to proper docs)
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Aug 7, 2026
Add support for splatted function pointers
Tracking issue: rust-lang#153629
This PR adds support for splatted function pointers.
Currently splatted function pointers ICE due to unpopulated side-tables. This PR fixes the ICE by populating the side-table correctly, and fixes the MIR lowering code. It also refactors the surrounding code to reduce code duplication.
Generic function pointers also work. I'm sure if there's something extra we need to do to support all generic function pointers?
Closerust-lang#158603
rust-borsBot pushed a commit that referenced this pull request Aug 7, 2026
…uwer
Rollup of 21 pull requests
Successful merges:
- #159784 (Hint that memchr returns an in-bounds index)
- #150885 (Revive L4Re target)
- #159643 (Add support for splatted function pointers)
- #160433 (delegation: add support for wrapping of the return value with `From::from`)
- #160530 (refactor handling of target features in Session)
- #160606 (bootstrap: Store and use an explicit CheckKind in `check::Rustc`)
- #160628 (fix ICE in `suggest_add_reference_to_arg` for non-callable items)
- #160634 (miri subtree update)
- #157641 (Do not promote extern statics)
- #158904 (Fix FutureDropPoll shim for by-move async closures)
- #160103 (Add regression test for GAT bound mismatched type error)
- #160335 (dlopen offload)
- #160445 (codegen: classify localized MSVC linker progress as linker_info)
- #160499 (rustc_resolve: move diagnostic attribute linting to attr parsing)
- #160504 (cleanup borrowck, improve c-variadic handling)
- #160577 (expand: Feature gate AST-based attribute macros on expressions and statements)
- #160587 (Add regression test for associated type outlives bound at call site)
- #160625 (platform-support/netbsd.md: No longer mention 8.x, due to EoL.)
- #160636 (derive(Diagnostic): link to proper docs)
- #160644 (Clean up some manual debug impls)
- #160649 (move naked function ui tests)
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Aug 7, 2026
Add support for splatted function pointers
Tracking issue: rust-lang#153629
This PR adds support for splatted function pointers.
Currently splatted function pointers ICE due to unpopulated side-tables. This PR fixes the ICE by populating the side-table correctly, and fixes the MIR lowering code. It also refactors the surrounding code to reduce code duplication.
Generic function pointers also work. I'm sure if there's something extra we need to do to support all generic function pointers?
Closerust-lang#158603
rust-borsBot pushed a commit that referenced this pull request Aug 7, 2026
…uwer
Rollup of 20 pull requests
Successful merges:
- #159784 (Hint that memchr returns an in-bounds index)
- #150885 (Revive L4Re target)
- #159643 (Add support for splatted function pointers)
- #160433 (delegation: add support for wrapping of the return value with `From::from`)
- #160530 (refactor handling of target features in Session)
- #160606 (bootstrap: Store and use an explicit CheckKind in `check::Rustc`)
- #160628 (fix ICE in `suggest_add_reference_to_arg` for non-callable items)
- #160634 (miri subtree update)
- #157641 (Do not promote extern statics)
- #158904 (Fix FutureDropPoll shim for by-move async closures)
- #160103 (Add regression test for GAT bound mismatched type error)
- #160335 (dlopen offload)
- #160445 (codegen: classify localized MSVC linker progress as linker_info)
- #160499 (rustc_resolve: move diagnostic attribute linting to attr parsing)
- #160504 (cleanup borrowck, improve c-variadic handling)
- #160577 (expand: Feature gate AST-based attribute macros on expressions and statements)
- #160587 (Add regression test for associated type outlives bound at call site)
- #160625 (platform-support/netbsd.md: No longer mention 8.x, due to EoL.)
- #160636 (derive(Diagnostic): link to proper docs)
- #160644 (Clean up some manual debug impls)
jhpratt added a commit to jhpratt/rust that referenced this pull request Aug 7, 2026
Add support for splatted function pointers
Tracking issue: rust-lang#153629
This PR adds support for splatted function pointers.
Currently splatted function pointers ICE due to unpopulated side-tables. This PR fixes the ICE by populating the side-table correctly, and fixes the MIR lowering code. It also refactors the surrounding code to reduce code duplication.
Generic function pointers also work. I'm sure if there's something extra we need to do to support all generic function pointers?
Closerust-lang#158603
@jhprattjhpratt mentioned this pull request Aug 7, 2026
rust-borsBot pushed a commit that referenced this pull request Aug 7, 2026
…uwer
Rollup of 28 pull requests
Successful merges:
- #159784 (Hint that memchr returns an in-bounds index)
- #160673 (Improve `canonical_param_env_cache`)
- #150885 (Revive L4Re target)
- #159643 (Add support for splatted function pointers)
- #160433 (delegation: add support for wrapping of the return value with `From::from`)
- #160530 (refactor handling of target features in Session)
- #160606 (bootstrap: Store and use an explicit CheckKind in `check::Rustc`)
- #160628 (fix ICE in `suggest_add_reference_to_arg` for non-callable items)
- #160683 (Add regression test for unknown feaeture name reported with other errors)
- #157641 (Do not promote extern statics)
- #158904 (Fix FutureDropPoll shim for by-move async closures)
- #159816 (added note/help about iterator invalidation when mutating a collection inside a for loop)
- #160103 (Add regression test for GAT bound mismatched type error)
- #160335 (dlopen offload)
- #160445 (codegen: classify localized MSVC linker progress as linker_info)
- #160499 (rustc_resolve: move diagnostic attribute linting to attr parsing)
- #160504 (cleanup borrowck, improve c-variadic handling)
- #160577 (expand: Feature gate AST-based attribute macros on expressions and statements)
- #160587 (Add regression test for associated type outlives bound at call site)
- #160625 (platform-support/netbsd.md: No longer mention 8.x, due to EoL.)
- #160633 (delegation: fix determining wrong `FnKind` when delegation is inside const arg)
- #160636 (derive(Diagnostic): link to proper docs)
- #160644 (Clean up some manual debug impls)
- #160649 (move naked function ui tests)
- #160672 (Improve `MaybeLiveLocals`)
- #160693 (Add branch config for perf. unrolling in bors)
- #160696 (rustc_codegen_llvm: handle sm_101* features being an alias)
- #160706 (renovate: clarify that vulnerability PRs are opened automatically)
@rust-bors
rust-borsBot merged commit ede75f6 into rust-lang:mainAug 8, 2026
26 checks passed
@rustbotrustbot added this to the 1.99.0 milestone Aug 8, 2026
rust-timer added a commit that referenced this pull request Aug 8, 2026
Rollup merge of #159643 - teor2345:splat-fn-ptr, r=folkertdev
Add support for splatted function pointers
Tracking issue: #153629
This PR adds support for splatted function pointers.
Currently splatted function pointers ICE due to unpopulated side-tables. This PR fixes the ICE by populating the side-table correctly, and fixes the MIR lowering code. It also refactors the surrounding code to reduce code duplication.
Generic function pointers also work. I'm sure if there's something extra we need to do to support all generic function pointers?
Close#158603
pullBot pushed a commit to LeeeeeeM/miri that referenced this pull request Aug 8, 2026
…uwer
Rollup of 28 pull requests
Successful merges:
- rust-lang/rust#159784 (Hint that memchr returns an in-bounds index)
- rust-lang/rust#160673 (Improve `canonical_param_env_cache`)
- rust-lang/rust#150885 (Revive L4Re target)
- rust-lang/rust#159643 (Add support for splatted function pointers)
- rust-lang/rust#160433 (delegation: add support for wrapping of the return value with `From::from`)
- rust-lang/rust#160530 (refactor handling of target features in Session)
- rust-lang/rust#160606 (bootstrap: Store and use an explicit CheckKind in `check::Rustc`)
- rust-lang/rust#160628 (fix ICE in `suggest_add_reference_to_arg` for non-callable items)
- rust-lang/rust#160683 (Add regression test for unknown feaeture name reported with other errors)
- rust-lang/rust#157641 (Do not promote extern statics)
- rust-lang/rust#158904 (Fix FutureDropPoll shim for by-move async closures)
- rust-lang/rust#159816 (added note/help about iterator invalidation when mutating a collection inside a for loop)
- rust-lang/rust#160103 (Add regression test for GAT bound mismatched type error)
- rust-lang/rust#160335 (dlopen offload)
- rust-lang/rust#160445 (codegen: classify localized MSVC linker progress as linker_info)
- rust-lang/rust#160499 (rustc_resolve: move diagnostic attribute linting to attr parsing)
- rust-lang/rust#160504 (cleanup borrowck, improve c-variadic handling)
- rust-lang/rust#160577 (expand: Feature gate AST-based attribute macros on expressions and statements)
- rust-lang/rust#160587 (Add regression test for associated type outlives bound at call site)
- rust-lang/rust#160625 (platform-support/netbsd.md: No longer mention 8.x, due to EoL.)
- rust-lang/rust#160633 (delegation: fix determining wrong `FnKind` when delegation is inside const arg)
- rust-lang/rust#160636 (derive(Diagnostic): link to proper docs)
- rust-lang/rust#160644 (Clean up some manual debug impls)
- rust-lang/rust#160649 (move naked function ui tests)
- rust-lang/rust#160672 (Improve `MaybeLiveLocals`)
- rust-lang/rust#160693 (Add branch config for perf. unrolling in bors)
- rust-lang/rust#160696 (rustc_codegen_llvm: handle sm_101* features being an alias)
- rust-lang/rust#160706 (renovate: clarify that vulnerability PRs are opened automatically)
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-bugCategory: This is a bug.F-splat`#![feature(splat)]` https://github.com/rust-lang/rust/issues/153629I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️S-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ICE] due to #[splat] in a function pointer type

5 participants

@teor2345@rust-log-analyzer@rustbot@petrochenkov@folkertdev