Skip to content

Fix splat ICEs and ban it in closures#158645

Open
teor2345 wants to merge 7 commits into
rust-lang:mainfrom
teor2345:splat-fn-fixes
Open

Fix splat ICEs and ban it in closures#158645
teor2345 wants to merge 7 commits into
rust-lang:mainfrom
teor2345:splat-fn-fixes

Conversation

@teor2345

@teor2345 teor2345 commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

View all comments

This PR is part of the splat lang experiment #153629.

It fixes one ICE, and cleans up the surrounding error handling to avoid future ICEs:
Close #158482

Improves the message and error handling in another ICE (but doesn't fix it):
cc #158603

And bans splat on closures and rust-call, because they already de-tuple arguments:
Close #158605

In the process I discovered another symbol mangling bug with splatting, which I added a test for (but didn't fix yet):
cc #158644
This test might be flaky, I'll drop it from this PR if it fails in CI.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 1, 2026
@rustbot

rustbot commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator

r? @folkertdev

rustbot has assigned @folkertdev.
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 73 candidates
  • Random selection from 16 candidates

Comment thread tests/ui/splat/splat-fn-ptr-tuple.rs Outdated

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

A first pass. Overall this PR seems kind of large, it would be easier to review if split up into smaller chunks.

View changes since this review

Comment thread compiler/rustc_ast_passes/src/ast_validation.rs Outdated
Comment on lines +1788 to +1793
Extern::Explicit(abi_str, span)
if abi_str.symbol_unescaped.as_str() == "rust-call" =>
{
SplatSemantic::NoRustCall(span)
}
Extern::Explicit(_abi_str, _span) => SplatSemantic::Yes,

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.

Suggested change
Extern::Explicit(abi_str, span)
if abi_str.symbol_unescaped.as_str() == "rust-call" =>
{
SplatSemantic::NoRustCall(span)
}
Extern::Explicit(_abi_str, _span) => SplatSemantic::Yes,
Extern::Explicit(abi_str, span) => match abi_str.symbol_unescaped {
sym::rust_dash_call => SplatSemantic::NoRustCall(span),
_ => SplatSemantic::Yes,
},

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.

and add a comment on why here too perhaps?

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.

I think the rust_dash_call symbol only exists in rust-analyzer, not in the compiler, but I did add the comment.

Comment thread compiler/rustc_ast_passes/src/ast_validation.rs Outdated
@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 1, 2026
@rustbot

rustbot commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator

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

@rust-log-analyzer

This comment has been minimized.

Comment thread tests/ui/splat/splat-dyn-asref-tuple-fail.stderr Outdated
@rust-log-analyzer

This comment has been minimized.

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

A first pass. Overall this PR seems kind of large, it would be easier to review if split up into smaller chunks.

Yeah I wondered about that, I'll split it up today, now I know which parts actually fail in CI.

@rustbot label +F-splat +I-ICE +T-compiler +C-bug

View changes since this review

Comment thread compiler/rustc_ast_passes/src/ast_validation.rs Outdated
Comment thread tests/ui/splat/splat-fn-ptr-tuple.rs Outdated
Comment thread tests/ui/splat/splat-dyn-asref-tuple-fail.stderr Outdated
@rustbot rustbot added C-bug Category: This is a bug. F-splat `#![feature(splat)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ labels Jul 1, 2026
@teor2345 teor2345 mentioned this pull request Jul 2, 2026
@teor2345

teor2345 commented Jul 2, 2026

Copy link
Copy Markdown
Contributor Author

I split the extra tests into PR #158677, most of them didn't need any compiler changes to work, so they are fine to merge separately.

@rustbot

rustbot commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@teor2345

teor2345 commented Jul 2, 2026

Copy link
Copy Markdown
Contributor Author

I dropped the large refactor because it broke some unrelated UI tests. Later I'll see if I can get it to work, and submit it as a separate PR. Otherwise this should be ready to review, and independent of #158677 merging.

Let me know if you'd like the PR split further?

@rustbot ready

@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 2, 2026
@rustbot

rustbot commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

Error: shortcut handler unexpectedly failed in this comment: error sending request

Please file an issue on GitHub at triagebot if there's a problem with this bot, or reach out on #triagebot on Zulip.

@teor2345

teor2345 commented Jul 2, 2026

Copy link
Copy Markdown
Contributor Author

@rustbot ready

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 2, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jul 2, 2026
…eywiser

Add extra splat tests

This PR is part of the splat lang experiment rust-lang#153629.

It adds a bunch of tests for existing splat functionality, but doesn't make any compiler code changes.

Edit: split off from PR rust-lang#158645

@rustbot label +F-splat +T-compiler
TyKind::FnPtr(bfty) => {
self.check_fn_ptr_safety(bfty.decl_span, bfty.safety);
self.check_fn_decl(&bfty.decl, SelfSemantic::No);
self.check_fn_decl(&bfty.decl, SelfSemantic::No, SplatSemantic::Yes);

@teor2345 teor2345 Jul 3, 2026

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.

@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 3, 2026
@teor2345

teor2345 commented Jul 3, 2026

Copy link
Copy Markdown
Contributor Author

Ok, now splat + rust-call is banned on both function item declarations and function pointer types, and splat is banned on closures. And there are tests for all of them.

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 3, 2026
Comment on lines -576 to -577
// Whether the function is variadic (e.g. from C)
c_variadic: bool,

@folkertdev folkertdev Jul 4, 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.

why was this removed exactly?

View changes since the review

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.

It's not used in this function except for debug logging, and it's not particularly interesting in debug logging because splat and c_variadic aren't allowed on the same function at the AST level.

And the top of the function early exits if splat / Fn* traits / rust-call isn't being used, so c_variadic should always be false.

)
}
} else {
let fn_ty = self.typeck_results.expr_ty_adjusted(expr);

@folkertdev folkertdev Jul 4, 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.

maybe comment here that this case is for function pointers?

View changes since the review

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.

Perhaps a custom enum even makes sense? "None" meaning we're dealing with function pointers is a but subtle. On the other hand, the ergonomics of that might be worse.

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 add a comment.

I expect to populate the side-table in an upcoming PR, as part of that change I might need a custom enum with different fields for FnPtrs and FnDefs. I was holding off on that to avoid churn.

Comment on lines +1 to +7
error: `#[splat]` is not allowed on functions with the `rust-call` ABI
--> $DIR/reject-closure-issue-158605.rs:10:5
|
LL | extern "rust-call" fn method(#[splat] self: Self);
| ^^^^^^^^^^^^^^^^^^ ^^^^
|
= help: remove `#[splat]` or change the ABI

@folkertdev folkertdev Jul 4, 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.

is the span right here? I'd expect it on the #[splat] really?

also the #[splat] is not really "on" the function, it is on an argument. Not a native speaker, but "is not allowed in/for functions with ..." sounds more natural?

View changes since the review

@teor2345 teor2345 Jul 4, 2026

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.

is the span right here? I'd expect it on the #[splat] really?

Ideally on splat and the ABI, as one of them needs to be removed. I'll add a FIXME if that's not possible right now.

I think "splat is not allowed in the arguments of functions with the rust-call ABI" would be clearer, as "in" could mean the body as well.

// FIXME(splat): should splatting extern "C" or other ABIs be allowed?
Extern::Implicit(_) => SplatSemantic::Yes,
// For now, splatting rust-call is banned, because it already de-tuples args.
Extern::Explicit(abi_str, span) if abi_str.symbol_unescaped.as_str() == "rust-call" => {

@folkertdev folkertdev Jul 4, 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.

it would be fine to add a rust_dash_call to rustc too.

View changes since the review

@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 4, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jul 5, 2026
…eywiser

Add extra splat tests

This PR is part of the splat lang experiment rust-lang#153629.

It adds a bunch of tests for existing splat functionality, but doesn't make any compiler code changes.

Edit: split off from PR rust-lang#158645

@rustbot label +F-splat +T-compiler
rust-timer added a commit that referenced this pull request Jul 5, 2026
Rollup merge of #158677 - teor2345:extra-splat-tests, r=wesleywiser

Add extra splat tests

This PR is part of the splat lang experiment #153629.

It adds a bunch of tests for existing splat functionality, but doesn't make any compiler code changes.

Edit: split off from PR #158645

@rustbot label +F-splat +T-compiler

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

I'll have a look at these changes later today or tomorrow

View changes since this review

Comment on lines -576 to -577
// Whether the function is variadic (e.g. from C)
c_variadic: bool,

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.

It's not used in this function except for debug logging, and it's not particularly interesting in debug logging because splat and c_variadic aren't allowed on the same function at the AST level.

And the top of the function early exits if splat / Fn* traits / rust-call isn't being used, so c_variadic should always be false.

)
}
} else {
let fn_ty = self.typeck_results.expr_ty_adjusted(expr);

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 add a comment.

I expect to populate the side-table in an upcoming PR, as part of that change I might need a custom enum with different fields for FnPtrs and FnDefs. I was holding off on that to avoid churn.

Comment on lines +1 to +7
error: `#[splat]` is not allowed on functions with the `rust-call` ABI
--> $DIR/reject-closure-issue-158605.rs:10:5
|
LL | extern "rust-call" fn method(#[splat] self: Self);
| ^^^^^^^^^^^^^^^^^^ ^^^^
|
= help: remove `#[splat]` or change the ABI

@teor2345 teor2345 Jul 4, 2026

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.

is the span right here? I'd expect it on the #[splat] really?

Ideally on splat and the ABI, as one of them needs to be removed. I'll add a FIXME if that's not possible right now.

I think "splat is not allowed in the arguments of functions with the rust-call ABI" would be clearer, as "in" could mean the body as well.

@teor2345

teor2345 commented Jul 6, 2026

Copy link
Copy Markdown
Contributor Author

Alright, all of those should be fixed up now. This ended up a bit more complicated than I thought, because we were missing a test (and AST handling) for multiple splats on the same argument.

@teor2345

teor2345 commented Jul 6, 2026

Copy link
Copy Markdown
Contributor Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 6, 2026
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)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. 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.

#[splat] is allowed in closures and does nothing. [ICE]: None in tupled_args_count.unwrap().try_into().unwrap()

6 participants