Skip to content

Add support for splatted function pointers - #159643

Open
teor2345 wants to merge 1 commit into
rust-lang:mainfrom
teor2345:splat-fn-ptr
Open

Add support for splatted function pointers#159643
teor2345 wants to merge 1 commit into
rust-lang:mainfrom
teor2345:splat-fn-ptr

Conversation

@teor2345

@teor2345 teor2345 commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

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

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

This comment was marked as resolved.

@rustbot rustbot 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
Contributor Author

@rustbot label +C-bug

@rustbot rustbot 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
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 23, 2026
@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 Jul 23, 2026
@rustbot

rustbot commented Jul 23, 2026

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

@rustbot rustbot assigned folkertdev and unassigned petrochenkov Jul 23, 2026
Comment thread compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs Outdated
Inline splatted_callee()
Add tests for generic function pointers

@folkertdev folkertdev 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
Contributor Author

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
Contributor Author

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.

Copy link
Copy Markdown
Contributor Author

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:

enum SplattedFunc {
    FnDefReceiver(Expr),
    NoFnDefReceiver,
    FnPtrExpression(Expr),
}

@rustbot rustbot 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

rustbot commented Jul 25, 2026

Copy link
Copy Markdown
Collaborator

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

@teor2345 teor2345 left a comment

Copy link
Copy Markdown
Contributor Author

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
  • update tests to use assert_eq!

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>,

Copy link
Copy Markdown
Contributor Author

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:

enum SplattedFunc {
    FnDefReceiver(Expr),
    NoFnDefReceiver,
    FnPtrExpression(Expr),
}


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

Copy link
Copy Markdown
Contributor Author

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 Author

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.

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

Labels

C-bug Category: This is a bug. F-splat `#![feature(splat)]` https://github.com/rust-lang/rust/issues/153629 I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

5 participants