Skip to content

Avoid underflow for splatted rust-call receivers#158850

Open
chenyukang wants to merge 1 commit into
rust-lang:mainfrom
chenyukang:yukang-fix-158800-splat-self-wfcheck-overflow
Open

Avoid underflow for splatted rust-call receivers#158850
chenyukang wants to merge 1 commit into
rust-lang:mainfrom
chenyukang:yukang-fix-158800-splat-self-wfcheck-overflow

Conversation

@chenyukang

@chenyukang chenyukang commented Jul 6, 2026

Copy link
Copy Markdown
Member

Fixes #158800

We alreay have proper error for #[splat] self in following code, so here we just need to avoid the overflow.

cc @teor2345

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

rustbot commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

r? @jieyouxu

rustbot has assigned @jieyouxu.
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 75 candidates
  • Random selection from 20 candidates

@jieyouxu jieyouxu added the F-splat `#![feature(splat)]` label Jul 6, 2026

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

I think that banning splat on rust-call and closures in PR #158645 will make these fixes obsolete. But there's still some useful changes we can make in this code.

View changes since this review


impl<T> dyn FnOnce(T) -> () {
//~^ ERROR cannot define inherent `impl` for a type outside of the crate
extern "rust-call" fn call_once(#[splat] self) {}

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.

Unfortunately splatted rust-call will be banned in PR #158645.

I think that's a good way forward, because:

  • rust-call already de-tuples its arguments
  • the semantics of splat in addition to rust-call are undefined, and there's no obvious way it should work
  • if we ban it now, people can't rely on any incomplete feature behaviour

Later, if we decide on a sensible way for it to work, we can re-enable it with those semantics.

I would still like to merge this test, but with the error output from #158645.

@@ -1717,14 +1717,18 @@ fn check_fn_or_method<'tcx>(
let has_implicit_self = hir_decl.implicit_self().has_implicit_self();
let mut inputs = sig.inputs().iter().skip(if has_implicit_self { 1 } else { 0 });
// FIXME(splat): support the rest of closure splatting, or replace this code with an error

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.

Based on the ban in #158645, this splatted closure code should probably become a compiler error (or an ICE bug).

And we can delete the rest of the calculations, so there's no underflow.

@teor2345

teor2345 commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Oh, and thank you for the PR! It's great to have a bunch of people finding bugs and fixing things.

@chenyukang

chenyukang commented Jul 6, 2026

Copy link
Copy Markdown
Member Author

I think that banning splat on rust-call and closures in PR #158645 will make these fixes obsolete. But there's still some useful changes we can make in this code.

View changes since this review

I will rework on it after #158645 is merged.

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

Labels

F-splat `#![feature(splat)]` 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.

[ICE]: attempt to subtract with overflow

4 participants