Skip to content

Distinguish delim kind to decide whether to emit unexpected closing delimiter - #138554

Merged
bors merged 2 commits into
rust-lang:masterfrom
xizheyin:issue-138401
Jul 19, 2025
Merged

Distinguish delim kind to decide whether to emit unexpected closing delimiter#138554
bors merged 2 commits into
rust-lang:masterfrom
xizheyin:issue-138401

Conversation

@xizheyin

@xizheyinxizheyin commented Mar 16, 2025

Copy link
Copy Markdown
Member

Fixes#138401

@rustbot

Copy link
Copy Markdown
Collaborator

r? @compiler-errors

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

@rustbotrustbot 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 Mar 16, 2025
@compiler-errors

Copy link
Copy Markdown
Contributor

r? compiler

@chenyukang

Copy link
Copy Markdown
Member

I changed this part last year, will review this PR later.

r? @chenyukang

@rustbotrustbot assigned chenyukang and unassigned estebankApr 7, 2025
Comment threadtests/ui/parser/issues/issue-68987-unmatch-issue-2.stderr
@rustbotrustbot 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 Apr 11, 2025
Comment threadtests/ui/parser/macro-mismatched-delim-paren-brace.stderr
Comment threadtests/ui/parser/issues/issue-68987-unmatch-issue-3.stderr
@chenyukang

Copy link
Copy Markdown
Member

I think this solution introduces some kind of regression on other scenarios(such as the cases I commented).

Maybe we should consider this as a special corner case and provide a special diagnostic for it, it is the pattern that one delimiter is missing the openning delimiter(it's in the inner part), except for this everything is ok, so we should suggest something like "missing openning delimiter ....".

such as:

{ ... {. ) ... }...} missing a inner (
{ ... [ ], ] ...} missing a inner [

@chenyukang

Copy link
Copy Markdown
Member

@rustbot author

@rustbot

Copy link
Copy Markdown
Collaborator

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

@xizheyin

Copy link
Copy Markdown
MemberAuthor

Thanks, I will revise it soon!

@xizheyinxizheyin changed the title [Lexer] Remove spurious unexpected delimiter error by matching remain…Distinguish delim kind to decide whether to emit unexpected closing delimiterApr 12, 2025
@xizheyin

Copy link
Copy Markdown
MemberAuthor

This seems like quite a lot of changes, I'll comment in the code to make it easier to REVIEW.

In the first commit, I added the test.

In the second commit I did some clean. I changed a variable name, the original name was inaccurate, I used open_delimiters instead of open_braces for identifying blocks, one should compare spans, not just brace'{'.

In the third commit, I make a distinction between the different delimiters before triggering a unexpected closing delimiter error. But I found that missing open delim note is what triggers in unexpected closing delimiter error.
Therefore, to emit missing open delim note, I also moved missing open delim note to
mismatched closing delimiter error, which can be emitted without delaying to
unexpected closing delimiter error.
And I moved function make_unclosed_delims_error
to src/lexer/diagnostics.rs for clean. And some other clean.

Comment threadcompiler/rustc_parse/src/lexer/diagnostics.rs
Comment threadcompiler/rustc_parse/src/lexer/diagnostics.rs
Comment threadcompiler/rustc_parse/src/lexer/diagnostics.rs Outdated
Comment threadcompiler/rustc_parse/src/lexer/diagnostics.rs
Comment threadcompiler/rustc_parse/src/lexer/tokentrees.rs Outdated
Comment threadtests/ui/parser/issues/issue-68987-unmatch-issue-2.stderr
Comment threadtests/ui/parser/issues/issue-68987-unmatch-issue-3.stderr
@rustbotrustbot 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 Apr 12, 2025
Comment threadtests/ui/parser/deli-ident-issue-2.stderr Outdated
@xizheyin

Copy link
Copy Markdown
MemberAuthor

I've combined them into one line so it's more aesthetically pleasing.

mismatched closing delimiter, may missing open `(`

Since the mismatched closing delimiter note and the unclosed delimiter note are related, it may be the better to keep it.

@rust-log-analyzer

This comment has been minimized.

@xizheyin

Copy link
Copy Markdown
MemberAuthor

This commit 0682e9e is for #138554 (comment). I use the nearest open delimiter.

The last commit a1d2557 is for comment #138554 (comment). In all the cases, we should emit missing open delimiter hints. Because,

  1. In mismatched error exists, the hint is not concrete enough.
  2. In mismatched error removed, the hint is then naturally needed.

Now, all the changes is

  1. Add a nearest open delimeter label in missing open delimeter hints
  2. remove false mismatched error in the cases like {}}

That's all we need.

But the code needs some clean. If everything is Ok, I will clean the code and squash commits. 😃

@xizheyin

Copy link
Copy Markdown
MemberAuthor

seems the latest commit #138554 add more noise.

The last commit is necessary if one is in a conservative consideration, as #138401 seems to be just to address cases like, {}}. The exact explanation is in my last comment #138554 (comment).

@chenyukang

Copy link
Copy Markdown
Member

#138554 (comment)

I think we can remove those hint, since we reported mismatch above.

@xizheyin

Copy link
Copy Markdown
MemberAuthor

Ok, I'll revise it later.

@xizheyin

Copy link
Copy Markdown
MemberAuthor

But I have a concern that we only reported what went wrong in the mismatched error, but we didn't mention how to correct it. I think this hint complements this.

If you think it should be removed, I will remove the last commit later.

@chenyukang

Copy link
Copy Markdown
Member

But I have a concern that we only reported what went wrong in the mismatched error, but we didn't mention how to correct it. I think this hint complements this.

If you think it should be removed, I will remove the last commit later.

for a mismatched scenario, the hint is not complementing it:

{ .... ] may be fixed as { ..... } or [ .... ].

perfer to remove it.

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

xizheyin commented Jul 18, 2025

Copy link
Copy Markdown
MemberAuthor

Make sense! I removed it.

And I cleaned the code, and squashed them to 2 commits. Now, it should be what we want!

@chenyukang

Copy link
Copy Markdown
Member

Thanks!

@bors r=chenyukang

@bors

bors commented Jul 18, 2025

Copy link
Copy Markdown
Collaborator

📌 Commit 181c1bd has been approved by chenyukang

It is now in the queue for this repository.

@borsbors 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 Jul 18, 2025
@xizheyin

Copy link
Copy Markdown
MemberAuthor

Thank you for your patient guidance! :)

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jul 18, 2025
Distinguish delim kind to decide whether to emit unexpected closing delimiter
Fixesrust-lang#138401
This was referenced Jul 18, 2025
bors added a commit that referenced this pull request Jul 18, 2025
Rollup of 9 pull requests
Successful merges:
- #138554 (Distinguish delim kind to decide whether to emit unexpected closing delimiter)
- #142673 (Show the offset, length and memory of uninit read errors)
- #142693 (More robustly deal with relaxed bounds and improve their diagnostics)
- #143382 (stabilize `const_slice_reverse`)
- #143928 (opt-dist: make llvm builds optional)
- #143961 (Correct which exploit mitigations are enabled by default)
- #144050 (Fix encoding of link_section and no_mangle cross crate)
- #144059 (Refactor `CrateLoader` into the `CStore`)
- #144123 (Generalize `unsize` and `unsize_into` destinations)
r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit that referenced this pull request Jul 19, 2025
Rollup of 9 pull requests
Successful merges:
- #138554 (Distinguish delim kind to decide whether to emit unexpected closing delimiter)
- #142673 (Show the offset, length and memory of uninit read errors)
- #142693 (More robustly deal with relaxed bounds and improve their diagnostics)
- #143382 (stabilize `const_slice_reverse`)
- #143928 (opt-dist: make llvm builds optional)
- #143961 (Correct which exploit mitigations are enabled by default)
- #144050 (Fix encoding of link_section and no_mangle cross crate)
- #144059 (Refactor `CrateLoader` into the `CStore`)
- #144123 (Generalize `unsize` and `unsize_into` destinations)
r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit that referenced this pull request Jul 19, 2025
Rollup of 9 pull requests
Successful merges:
- #138554 (Distinguish delim kind to decide whether to emit unexpected closing delimiter)
- #142673 (Show the offset, length and memory of uninit read errors)
- #142693 (More robustly deal with relaxed bounds and improve their diagnostics)
- #143382 (stabilize `const_slice_reverse`)
- #143928 (opt-dist: make llvm builds optional)
- #143961 (Correct which exploit mitigations are enabled by default)
- #144050 (Fix encoding of link_section and no_mangle cross crate)
- #144059 (Refactor `CrateLoader` into the `CStore`)
- #144123 (Generalize `unsize` and `unsize_into` destinations)
r? `@ghost`
`@rustbot` modify labels: rollup
@bors
bors merged commit 61285e2 into rust-lang:masterJul 19, 2025
11 checks passed
@rustbotrustbot added this to the 1.90.0 milestone Jul 19, 2025
rust-timer added a commit that referenced this pull request Jul 19, 2025
Rollup merge of #138554 - xizheyin:issue-138401, r=chenyukang
Distinguish delim kind to decide whether to emit unexpected closing delimiter
Fixes#138401
github-actionsBot pushed a commit to rust-lang/miri that referenced this pull request Jul 20, 2025
Rollup of 9 pull requests
Successful merges:
- rust-lang/rust#138554 (Distinguish delim kind to decide whether to emit unexpected closing delimiter)
- rust-lang/rust#142673 (Show the offset, length and memory of uninit read errors)
- rust-lang/rust#142693 (More robustly deal with relaxed bounds and improve their diagnostics)
- rust-lang/rust#143382 (stabilize `const_slice_reverse`)
- rust-lang/rust#143928 (opt-dist: make llvm builds optional)
- rust-lang/rust#143961 (Correct which exploit mitigations are enabled by default)
- rust-lang/rust#144050 (Fix encoding of link_section and no_mangle cross crate)
- rust-lang/rust#144059 (Refactor `CrateLoader` into the `CStore`)
- rust-lang/rust#144123 (Generalize `unsize` and `unsize_into` destinations)
r? `@ghost`
`@rustbot` modify labels: rollup
Muscraft pushed a commit to Muscraft/rust that referenced this pull request Jul 21, 2025
Distinguish delim kind to decide whether to emit unexpected closing delimiter
Fixesrust-lang#138401
Muscraft pushed a commit to Muscraft/rust that referenced this pull request Jul 21, 2025
…iaskrgr
Rollup of 9 pull requests
Successful merges:
- rust-lang#138554 (Distinguish delim kind to decide whether to emit unexpected closing delimiter)
- rust-lang#142673 (Show the offset, length and memory of uninit read errors)
- rust-lang#142693 (More robustly deal with relaxed bounds and improve their diagnostics)
- rust-lang#143382 (stabilize `const_slice_reverse`)
- rust-lang#143928 (opt-dist: make llvm builds optional)
- rust-lang#143961 (Correct which exploit mitigations are enabled by default)
- rust-lang#144050 (Fix encoding of link_section and no_mangle cross crate)
- rust-lang#144059 (Refactor `CrateLoader` into the `CStore`)
- rust-lang#144123 (Generalize `unsize` and `unsize_into` destinations)
r? `@ghost`
`@rustbot` modify labels: rollup
Kobzol pushed a commit to Kobzol/rustc_codegen_gcc that referenced this pull request Dec 21, 2025
Rollup of 9 pull requests
Successful merges:
- rust-lang/rust#138554 (Distinguish delim kind to decide whether to emit unexpected closing delimiter)
- rust-lang/rust#142673 (Show the offset, length and memory of uninit read errors)
- rust-lang/rust#142693 (More robustly deal with relaxed bounds and improve their diagnostics)
- rust-lang/rust#143382 (stabilize `const_slice_reverse`)
- rust-lang/rust#143928 (opt-dist: make llvm builds optional)
- rust-lang/rust#143961 (Correct which exploit mitigations are enabled by default)
- rust-lang/rust#144050 (Fix encoding of link_section and no_mangle cross crate)
- rust-lang/rust#144059 (Refactor `CrateLoader` into the `CStore`)
- rust-lang/rust#144123 (Generalize `unsize` and `unsize_into` destinations)
r? `@ghost`
`@rustbot` modify labels: rollup
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.T-compilerRelevant 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.

Better handling of missing closing or opening delimiters, well distinct by type of delimiter

8 participants

@xizheyin@rustbot@compiler-errors@chenyukang@rust-log-analyzer@wesleywiser@estebank@bors