Skip to content

Suggest adding a comma when () followed by a closure is parsed as bitor - #165455

Closed
raushan728 wants to merge 2 commits into
rust-lang:mainfrom
raushan728:issues/165386
Closed

raushan728 wants to merge 2 commits into
rust-lang:mainfrom
raushan728:issues/165386

Conversation

@raushan728

@raushan728 raushan728 commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Part of #165386.

When t(() |c| c) is parsed as (() | c) | c and an argument is missing, suggest adding a comma after ().

@rustbot

rustbot commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator

The parser was modified, potentially altering the grammar of (stable) Rust
which would be a breaking change.

cc @fmease

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

rustbot commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator

r? @chenyukang

rustbot has assigned @chenyukang.
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 77 candidates
  • Random selection from 21 candidates

@fmease fmease left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm sorry but you can't modify the stable Rust grammar like that. That'd be a breaking change. Moreover, the change is ad hoc & complicates the grammar to an unreasonable degree just to improve diagnostics in a niche scenario likely preventing real world use cases in the process. Thus, it's highly unlikely that this would ever get accepted by T-lang.

View changes since this review

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

rustbot commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator

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

@fmease fmease assigned fmease and unassigned chenyukang Nov 4, 2026
@raushan728

raushan728 commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks! changing the grammar for this isn't the right approach

Would a diagnostic only change be acceptable instead? For example,when E0061 fires and the only argument is a BitOr chain rooted atliteral (), emit a suggestion like "did you mean to add a comma?". purely a diagnostic improvement in typeck.

Or should I close this PR and move on?

@fmease

fmease commented Nov 4, 2026

Copy link
Copy Markdown
Member

Would a diagnostic only change be acceptable instead? For example,when E0061 fires and the only argument is a BitOr chain rooted atliteral (), emit a suggestion like "did you mean to add a comma?". purely a diagnostic improvement in typeck.

Yes, that would be acceptable.

Feel free to update this PR or to close it and open a new one.

@raushan728

Copy link
Copy Markdown
Contributor Author

Thanks, I'll update this.

@raushan728 raushan728 changed the title fix(parser): recover missing comma before closure in expression lists Suggest adding a comma when () followed by a closure is parsed as bitor Nov 5, 2026

@raushan728 raushan728 left a comment •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Feel free to update this PR or to close it and open a new one.

Hi, I've updated this. Please take another look. Thanks!

View changes since this review

@raushan728
raushan728 requested a review from fmease November 5, 2026 08:24
@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 Nov 5, 2026
@inkreasing

Copy link
Copy Markdown
Contributor

I don't think the issue should be closed when this is merged, because the name resolution errors (which are a lot more confusing that the wrong help note) are still emitted.

@raushan728

Copy link
Copy Markdown
Contributor Author

The issue should stay open. The parse as bitor is correct, so the E0425 noise would likely need a separate resolve side diagnostic. This PR only adds the comma suggestion.

@theemathas

Copy link
Copy Markdown
Contributor

What's the reason you're doing this specifically after a () ?

@raushan728

Copy link
Copy Markdown
Contributor Author

() is the one case where we can be confident it's a mistake. std has no BitOr impl for (), so () | ... practically never typechecks. For other leading expressions the same shape can be valid code (e.g. t(2 |c| c) with a c in scope compiles), so a suggestion there would be a false positive. It could be broadened later if there's a reliable way to tell the cases apart.

@inkreasing

Copy link
Copy Markdown
Contributor

I didn't encounter this with (), that was just to simplify my issue report. I think passing () to a function is extremely rare, so i don't know useful this is.

@raushan728

Copy link
Copy Markdown
Contributor Author

Thanks, () was the conservative choice since () | ... practically never typechecks, so there is no risk of a false positive. Since the E0425 errors are the confusing part, a resolve side change would likely help more, but that would be separate from this PR.

Could you share the code where you hit this, or at least the type of the leading argument? That would help judge whether the suggestion should be broader than ().

@theemathas

Copy link
Copy Markdown
Contributor

@raushan728 You mentioned elsewhere that you use LLMs. Have you read the LLM policy? Are you following the policy? If so, could you please elaborate more on your LLM usage in more detail, and not just "learn the codebase and move faster"?

@raushan728

Copy link
Copy Markdown
Contributor Author

Here is how I use LLMs in more detail.

English is not my first language, so I use AI in the browser to understand issue text, translation and technical wording, and to explain code that I do not understand. I also use it to discussion because there is a lot things I don't know, so for its discussion... I use it as an assistant.

In my IDE I use free models (in opencode) only, because I do not have a paid subscription of claude code, codex etc. The rust codebase is very large, so I use them to find where something is implemented.

I can explain the code in my PRs. If you have a question about a specific change or decision, please ask

@oli-obk

oli-obk commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

#165642 (comment)

@oli-obk oli-obk closed this Nov 9, 2026
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

7 participants