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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

4 participants