Skip to content

Suggest add missing , before doc comments in parsing item list #142341

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

xizheyin
Copy link
Contributor

@xizheyin xizheyin commented Jun 11, 2025

Fixes #142311

@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 Jun 11, 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.

This approach feels larger than the issue it's trying to fix, and it also isn't applied to other generalizations of this problem like struct fields. I'm not sure if it's warranted--I think we could simply suppress the doc comment /// -> // / suggestion when a trailing comma is in the expected tokens list, which would be a good enough approximation of this without needing to add a whole new "parse context" tracking to the parser.

@xizheyin
Copy link
Contributor Author

That's what I thought at first, but I'm worried that there are many similar cases in the code.

If only record the case, fixing every such error will make the code ugly like patching. But I haven't got a detailed investigation of the specific situations where context is needed. Maybe the current one can be used without context. But in the future, this context refactoring may be useful to enhance the maintainability of the code to solve multiple similar problem.

@compiler-errors
Copy link
Member

Well right now it doesn't seem particularly worthwhile. I'm not totally sure if the original issue report is really worth fixing, since the suggestion is valid in some cases, and suppressing it seems like more work than is worth it.

@xizheyin
Copy link
Contributor Author

For that edge situation, it is really worth fixing, at least it should be set to maybeincorrect, not machineappreciate.At present, the testcase related to that doc comment suggestion does not cover this situation.

Copy link
Member

@fee1-dead fee1-dead left a comment

Choose a reason for hiding this comment

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

This isn't needed because the edible parameter on expected_one_of_not_found already contains information on what tokens we expect.

It would be much better to suggest adding a comma before the doc comment if a comma was expected, so this case works out too:

fn a() {
    [
        a /// Test
        b
    ]
}

@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 Jun 12, 2025
Copy link
Contributor Author

@xizheyin xizheyin left a comment

Choose a reason for hiding this comment

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

@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 Jun 12, 2025
@xizheyin xizheyin changed the title Add ParseContext for diagnostic in Parser and remove false comments suggestion Suggest add missing , before doc comments in parsing item list Jun 12, 2025
@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 Jun 13, 2025
@xizheyin
Copy link
Contributor Author

I modified the fixme and used the E0585 code in two new commits. :3

Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
… list

Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
@xizheyin
Copy link
Contributor Author

The current version is much better.
@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 Jun 14, 2025
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.

Missing comma in enum interacts badly with doc comment advice
5 participants