Skip to content

Improve suggestion for "missing function argument" on multiline call #144966

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 11, 2025

Conversation

scrabsha
Copy link
Contributor

@scrabsha scrabsha commented Aug 5, 2025

rustc has a very neat suggestion when the argument count does not match, with a nice placeholder that shows where an argument may be missing. Unfortunately the suggestion is always single-line, even when the function call spans across multiple lines. With this PR, rustc tries to guess if the function call is multiline or not, and emits a multiline suggestion when required.

r? @jdonszelmann

@rustbot
Copy link
Collaborator

rustbot commented Aug 5, 2025

jdonszelmann is currently at their maximum review capacity.
They may take a while to respond.

@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 Aug 5, 2025
@scrabsha scrabsha force-pushed the push-rozroqqmurvu branch from 033e147 to 1eb4aef Compare August 5, 2025 16:42
LL | function_with_lots_of_arguments(
LL | variable_name,
LL ~ /* char */,
LL ~ variable_name,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't understand why this line is labeled as ~, as it is (well, should be) identical to the initial source. I tried to tweak the code a bit, but found nothing :/

Copy link
Member

@compiler-errors compiler-errors Aug 6, 2025

Choose a reason for hiding this comment

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

Because the suggestion I think is being constructed as "/* char */\n " not "\n /* char */", so it's modifying an existing line (where the next arg already is) by adding the new arg suggestion in, then adding the new line with an existing suggestion which also being considered a modification.

You could modify this by appending the line to the previous arg, I think but it would require restructuring your logic.

@scrabsha scrabsha changed the title Add test for "missing function argument" on multiline call Improve suggestion for "missing function argument" on multiline call Aug 5, 2025
Copy link
Member

@compiler-errors compiler-errors left a comment

Choose a reason for hiding this comment

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

Seems fine to me

LL - p3, p4, p5, p6, p7, p8,
LL - );
LL + foo(p1, /* Arc<T2> */, p3, p4, p5, p6, p7, p8);
LL ~ foo(
Copy link
Member

Choose a reason for hiding this comment

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

This case is a bit unfortunate, though I don't know if we'd benefit from tweaking the heuristic to detect "fake" multiline args (i.e. when there's only one line break).

@scrabsha scrabsha force-pushed the push-rozroqqmurvu branch from 1eb4aef to 1e271d6 Compare August 6, 2025 17:17
@jdonszelmann
Copy link
Contributor

@bors r+ rollup looks like a good change as-is. Maybe you can improve the heuristic slightly later as per errs' suggestion

@bors
Copy link
Collaborator

bors commented Aug 11, 2025

📌 Commit 1e271d6 has been approved by jdonszelmann

It is now in the queue for this repository.

@bors bors 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 11, 2025
bors added a commit that referenced this pull request Aug 11, 2025
Rollup of 4 pull requests

Successful merges:

 - #144966 ( Improve suggestion for "missing function argument" on multiline call)
 - #145111 (remove some unused private trait impls)
 - #145221 (Fix Cargo cross-compilation (take two))
 - #145247 (Update `sysinfo` version to `0.37.0`)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 180e7ce into rust-lang:master Aug 11, 2025
10 checks passed
@rustbot rustbot added this to the 1.91.0 milestone Aug 11, 2025
rust-timer added a commit that referenced this pull request Aug 11, 2025
Rollup merge of #144966 - scrabsha:push-rozroqqmurvu, r=jdonszelmann

 Improve suggestion for "missing function argument" on multiline call

`rustc` has a very neat suggestion when the argument count does not match, with a nice placeholder that shows where an argument may be missing. Unfortunately the suggestion is always single-line, even when the function call spans across multiple lines. With this PR, `rustc` tries to guess if the function call is multiline or not, and emits a multiline suggestion when required.

r? `@jdonszelmann`
@scrabsha scrabsha deleted the push-rozroqqmurvu branch August 12, 2025 16:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.

5 participants