rust-clippy icon indicating copy to clipboard operation
rust-clippy copied to clipboard

Fix `println_empty_string` suggestion caused error when there is a `,` after arg

Open relaxcn opened this issue 2 months ago • 2 comments

Closes: rust-lang/rust-clippy#16167

changelog: [println_empty_string]: fix suggestion caused error when there is a comma after arg.

relaxcn avatar Dec 07 '25 09:12 relaxcn

r? @samueltardieu

rustbot has assigned @samueltardieu. 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

rustbot avatar Dec 07 '25 09:12 rustbot

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

rustbot avatar Dec 11 '25 18:12 rustbot

This PR was rebased onto a different master 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.

rustbot avatar Dec 16 '25 17:12 rustbot

@rustbot ready

relaxcn avatar Dec 16 '25 18:12 relaxcn

Ensure that there is no comment inside the macro call and don't provide a suggestion in this case.

It's reasonable. But how about using rustc_lexer to skip comment, whitespace to find the following span of ,?

Or we just skip linting the situation you mentioned above.

relaxcn avatar Dec 17 '25 12:12 relaxcn

@rustbot ready

relaxcn avatar Dec 17 '25 19:12 relaxcn

Ensure that there is no comment inside the macro call and don't provide a suggestion in this case.

It's reasonable. But how about using rustc_lexer to skip comment, whitespace to find the following span of ,?

Or we just skip linting the situation you mentioned above.

Note that I'm not proposing not to lint, but to not provide a suggestion (as in "autofix") in this case.

samueltardieu avatar Dec 17 '25 21:12 samueltardieu

This PR was rebased onto a different master 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.

rustbot avatar Dec 18 '25 17:12 rustbot

This is a lot of complex code for practically no gain. What about my proposal to just not have an autofix if there are comments inside the macro call? You can still lint, you just have to replace the suggestion by a help message saying "remove the empty string" and let the user deal with it.

Thank you. I think using simpler but more robust way to compute span is good as you mentioned before.

So I adopted your suggested code.

However, I still think that using rustc_lexer is a more perfect solution.

At least for writeln_empty_string line, there must be a comma in the macro. We can't use a way that determines whether to use MachineApplicable by checking for the presence of commas in the macro, so we also need to come up with another "compromise" at that time.

Compared to carefully handling strings, operating on tokens is more reassuring.

Just my two cents :)

@rustbot ready

relaxcn avatar Dec 18 '25 17:12 relaxcn