Skip to content

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

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 Mar 16, 2025

Fixes #138401

@rustbot
Copy link
Collaborator

rustbot commented Mar 16, 2025

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

@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 Mar 16, 2025
@compiler-errors
Copy link
Member

r? compiler

@rustbot rustbot assigned estebank and unassigned compiler-errors Mar 21, 2025
@chenyukang
Copy link
Member

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

r? @chenyukang

@rustbot rustbot assigned chenyukang and unassigned estebank Apr 7, 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 Apr 11, 2025
@chenyukang
Copy link
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
Member

@rustbot author

@rustbot
Copy link
Collaborator

rustbot commented Apr 11, 2025

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

@xizheyin
Copy link
Contributor Author

Thanks, I will revise it soon!

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

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.

@xizheyin xizheyin requested a review from chenyukang April 12, 2025 11:02
@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 Apr 12, 2025
@xizheyin
Copy link
Contributor Author

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
Contributor Author

I marked potential matched unclosed delimiter when emit unexpected closing delimiter in the new commit.
But I am not sure it's appropriate, I think it has the potential to introduce noise into complex samples with lots of mixed delimiters.

@estebank
Copy link
Contributor

@xizheyin I see what you mean. I think some of the changes are a net positive, and some are not. We could try to get fancy and look at the number of unclosed delimiters we have in order to specialize the output. For cases where there's only a handful of mistakes, showing all of them is useful (like when someone deletes a line in the middle of a file). When there are "too many", we can only tell people "try to fix things, this is very broken". I'll try to take a look at this in more depth later with more specific feedback, but if you have the spare time to experiment with this idea, I think it can result on something quite usable.

@xizheyin
Copy link
Contributor Author

That makes sense. Different situations are treated differently. I will investigate further.

@bors
Copy link
Collaborator

bors commented Jul 6, 2025

☔ The latest upstream changes (presumably #143526) made this pull request unmergeable. Please resolve the merge conflicts.

@xizheyin xizheyin force-pushed the issue-138401 branch 2 times, most recently from 1c4382c to ce088f0 Compare July 7, 2025 07:38
@xizheyin
Copy link
Contributor Author

xizheyin commented Jul 9, 2025

Thanks for the guidance, I've learned much, this diagnosis involves a lot of regression testing so it's a little harder to deal with.

error: unexpected closing delimiter: `}`
--> $DIR/issue-68987-unmatch-issue-3.rs:8:1
|
LL | fn f(i: u32, j: u32) {
| - the closing `}` may be intended to match this
Copy link
Member

Choose a reason for hiding this comment

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

this new hint is unnecessary, how can we remove it?
since the root cause is only a missing '(', which we have already reported.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

estebank suggest me to add some hint. the closing ) may match this {, so we can get the general scope of how to add [. But I understood it. It should be "the mismatched closing ) may be meant for this opening delimiter".
See #138554 (comment) #138554 (comment)

Copy link
Member

@chenyukang chenyukang Jul 10, 2025

Choose a reason for hiding this comment

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

even if we change the words into the mismatched closing ) may be meant for this opening delimiter, it will also make a similar confusion like the origin issue #138401 described?

user will be confused why ')' meant for this opennning '{' ?

Copy link
Member

@chenyukang chenyukang Jul 10, 2025

Choose a reason for hiding this comment

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

this remind me maybe we should reconsider whether the original issue is worth to be resolved, the original hint in the issue description:

error: mismatched closing delimiter: `)`
 --> ...\test.rs:1:27
  |
1 | pub fn foo(x: i64) -> i64 {
  |                           ^ unclosed delimiter
2 |     x.abs)
  |          ^ mismatched closing delimiter

seems somehow confused, but it helps narrow the scope of span, if there are multiple nested scope, I think it's helpful in those scenarios.

error: unexpected closing delimiter: `}`
--> $DIR/issue-68987-unmatch-issue-2.rs:14:1
|
LL | async fn obstest() -> Result<> {
| - the closing `}` may be intended to match this
Copy link
Member

Choose a reason for hiding this comment

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

similar one.
it's better to remove it.

LL | V = [PhantomData; { [ () ].len() ].len() as isize,
| - missing open `[` for this delimiter
...
LL | mod b {
| - unclosed delimiter
LL | enum Bug {
Copy link
Member

Choose a reason for hiding this comment

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

this hint may makes user try to add a '}', while the root cause is we should remove the { where old diagnostic reported.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is because we merged the mismatched diagnostic into another diagnostic. The old diagnostic gave the wrong information because the real reason was the missing {} in { [].len() }. However, I think this PR is meant to address the duplicate error message, this false message can be addressed in another PR. :)

@xizheyin
Copy link
Contributor Author

xizheyin commented Jul 9, 2025

I need to clarify the direction of the modification.
As I understand it, for the current modification, I need to change the hint as suggested in this #138554 (comment) .
For the other, such as #138554 (comment) , it seems to need to be addressed in another PR, as this is not what #138401 is proposing, and it seems to be a new issue.

@chenyukang
Copy link
Member

I need to clarify the direction of the modification. As I understand it, for the current modification, I need to change the hint as suggested in this #138554 (comment) . For the other, such as #138554 (comment) , it seems to need to be addressed in another PR, as this is not what #138401 is proposing, and it seems to be a new issue.

per my understanding, the issue #138554 (comment) refers to is introduced by the code in this PR, not a old one?

@xizheyin
Copy link
Contributor Author

Oh! That makes sense. This seems to require finer control.

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.

There should be no regression this time.

The only thing I did was this: if the missing open hint is reported in report_missing_open_delim, it will not generate a separate mismatched error, reducing a lot of confusing errors. Meanwhile, this doesn't eat up the information in the mismatched error.

| - missing open `[` for this delimiter
| - - missing open `[` for this delimiter
| |
| the last unclosed delimiter before unmatched delimiter
Copy link
Member

@chenyukang chenyukang Jul 10, 2025

Choose a reason for hiding this comment

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

it's more clear only report as unclosed delimiter as before?

this is the mismatched scenario, means we have the same number openning delimiter and closing delimiter, but they are just not matched, for example:

({)) we have 2 open delimiter and 2 close delimiter, but it's a mismatched pair here
[{[)}] we have 3 open delimiter and 3 close, but there is a mismatchd pair

so in mismatch scenario, seems we should only report mismatch as before.

only for the scenario, that openning delimiter and closing delimiter is not same, for example:

[)] here we have 1 open, and 2 close delimiter, it's safe to report missing a `(`.

Copy link
Member

Choose a reason for hiding this comment

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

the issue described in #138401 is a special scenario that we are missing a openning delimiter:

pub fn foo(x: i64) -> i64 {
    x.abs)
}

it's

{)}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you, I understand it. I'll try to do it only in this case.

@rust-log-analyzer
Copy link
Collaborator

The job aarch64-gnu-llvm-19-1 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
3    |
4 LL |     if 1 < 2 {
-    |              - the last unclosed delimiter before unmatched delimiter
+    |              - unclosed delimiter before unmatched delimiter
6 LL |         let _a = vec!];
7    |                      - missing open `[` for this delimiter
8 LL |     }


The actual stderr differed from the expected stderr
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args parser/deli-ident-issue-2.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/parser/deli-ident-issue-2.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2" "--target=aarch64-unknown-linux-gnu" "--check-cfg" "cfg(test,FALSE)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/parser/deli-ident-issue-2" "-A" "unused" "-A" "internal_features" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/aarch64-unknown-linux-gnu/native/rust-test-helpers"
stdout: none
--- stderr -------------------------------
error: unexpected closing delimiter: `}`
##[error]  --> /checkout/tests/ui/parser/deli-ident-issue-2.rs:5:1
   |
LL |     if 1 < 2 {
   |              - unclosed delimiter before unmatched delimiter
LL |         let _a = vec!];
   |                      - missing open `[` for this delimiter
LL |     }
LL | } //~ ERROR unexpected closing delimiter
   | ^ unexpected closing delimiter

error: aborting due to 1 previous error
------------------------------------------


---- [ui] tests/ui/parser/issues/issue-104367.rs stdout ----
Saved the actual stderr to `/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/parser/issues/issue-104367/issue-104367.stderr`
diff of stderr:

12 LL |             #![w,)
13    |               -  - missing open `(` for this delimiter
14    |               |
-    |               the last unclosed delimiter before unmatched delimiter
+    |               unclosed delimiter before unmatched delimiter
16 LL |
17    |                                                                      ^
---
To only update this specific test, also pass `--test-args parser/issues/issue-104367.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/parser/issues/issue-104367.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2" "--target=aarch64-unknown-linux-gnu" "--check-cfg" "cfg(test,FALSE)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/parser/issues/issue-104367" "-A" "unused" "-A" "internal_features" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/aarch64-unknown-linux-gnu/native/rust-test-helpers"
stdout: none
--- stderr -------------------------------
error: this file contains an unclosed delimiter
##[error]  --> /checkout/tests/ui/parser/issues/issue-104367.rs:6:71
   |
---
   |        |
   |        unclosed delimiter
LL |         #![cfg] {
   |                 - unclosed delimiter
LL |             #![w,)
   |               -  - missing open `(` for this delimiter
   |               |
   |               unclosed delimiter before unmatched delimiter
LL |                    //~ ERROR this file contains an unclosed delimiter
   |                                                                      ^

---
---- [ui] tests/ui/parser/issues/issue-105209.rs stdout ----
Saved the actual stderr to `/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/parser/issues/issue-105209/issue-105209.stderr`
diff of stderr:

5    |   -  -  - -- ^
6    |   |  |  | ||
7    |   |  |  | |missing open `(` for this delimiter
-    |   |  |  | the last unclosed delimiter before unmatched delimiter
+    |   |  |  | unclosed delimiter before unmatched delimiter
9    |   |  |  unclosed delimiter
10    |   |  unclosed delimiter
11    |   unclosed delimiter


The actual stderr differed from the expected stderr
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args parser/issues/issue-105209.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/parser/issues/issue-105209.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2" "--target=aarch64-unknown-linux-gnu" "--check-cfg" "cfg(test,FALSE)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/parser/issues/issue-105209" "-A" "unused" "-A" "internal_features" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/aarch64-unknown-linux-gnu/native/rust-test-helpers" "-Zunpretty=ast-tree"
stdout: none
--- stderr -------------------------------
error: this file contains an unclosed delimiter
##[error]  --> /checkout/tests/ui/parser/issues/issue-105209.rs:3:15
   |
LL | #![c={#![c[)x
   |   -  -  - -- ^
   |   |  |  | ||
   |   |  |  | |missing open `(` for this delimiter
   |   |  |  | unclosed delimiter before unmatched delimiter
   |   |  |  unclosed delimiter
   |   |  unclosed delimiter
   |   unclosed delimiter

error: aborting due to 1 previous error
------------------------------------------


---- [ui] tests/ui/parser/issues/issue-62973.rs stdout ----
Saved the actual stderr to `/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/parser/issues/issue-62973/issue-62973.stderr`
diff of stderr:

4 LL | fn p() { match s { v, E { [) {) }
5    |        -         -        -- -- missing open `(` for this delimiter
6    |        |         |        || |
-    |        |         |        || the last unclosed delimiter before unmatched delimiter
+    |        |         |        || unclosed delimiter before unmatched delimiter
8    |        |         |        |missing open `(` for this delimiter
-    |        |         |        the last unclosed delimiter before unmatched delimiter
+    |        |         |        unclosed delimiter before unmatched delimiter
10    |        |         unclosed delimiter
11    |        unclosed delimiter
12 LL |


The actual stderr differed from the expected stderr
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args parser/issues/issue-62973.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/parser/issues/issue-62973.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2" "--target=aarch64-unknown-linux-gnu" "--check-cfg" "cfg(test,FALSE)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/parser/issues/issue-62973" "-A" "unused" "-A" "internal_features" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/aarch64-unknown-linux-gnu/native/rust-test-helpers"
stdout: none
--- stderr -------------------------------
error: this file contains an unclosed delimiter
##[error]  --> /checkout/tests/ui/parser/issues/issue-62973.rs:8:2
   |
LL | fn p() { match s { v, E { [) {) }
   |        -         -        -- -- missing open `(` for this delimiter
   |        |         |        || |
   |        |         |        || unclosed delimiter before unmatched delimiter
   |        |         |        |missing open `(` for this delimiter
   |        |         |        unclosed delimiter before unmatched delimiter
   |        |         unclosed delimiter
   |        unclosed delimiter
LL |
LL |
---
---- [ui] tests/ui/parser/issues/issue-63116.rs stdout ----
Saved the actual stderr to `/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/parser/issues/issue-63116/issue-63116.stderr`
diff of stderr:

5    |          -   - -^
6    |          |   | |
7    |          |   | missing open `[` for this delimiter
-    |          |   the last unclosed delimiter before unmatched delimiter
+    |          |   unclosed delimiter before unmatched delimiter
9    |          unclosed delimiter
10 
11 error: aborting due to 1 previous error


The actual stderr differed from the expected stderr
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args parser/issues/issue-63116.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/parser/issues/issue-63116.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2" "--target=aarch64-unknown-linux-gnu" "--check-cfg" "cfg(test,FALSE)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/parser/issues/issue-63116" "-A" "unused" "-A" "internal_features" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/aarch64-unknown-linux-gnu/native/rust-test-helpers"
stdout: none
--- stderr -------------------------------
error: this file contains an unclosed delimiter
##[error]  --> /checkout/tests/ui/parser/issues/issue-63116.rs:3:18
   |
LL | impl W <s(f;Y(;]
   |          -   - -^
   |          |   | |
   |          |   | missing open `[` for this delimiter
   |          |   unclosed delimiter before unmatched delimiter
   |          unclosed delimiter

error: aborting due to 1 previous error
------------------------------------------


---- [ui] tests/ui/parser/issues/issue-67377-invalid-syntax-in-enum-discriminant.rs stdout ----
Saved the actual stderr to `/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/parser/issues/issue-67377-invalid-syntax-in-enum-discriminant/issue-67377-invalid-syntax-in-enum-discriminant.stderr`
diff of stderr:

4 LL |         V = [PhantomData; { [ () ].len() ].len() as isize,
5    |                           -              - missing open `[` for this delimiter
6    |                           |
-    |                           the last unclosed delimiter before unmatched delimiter
+    |                           unclosed delimiter before unmatched delimiter
8 ...
9 LL |         V = [Vec::new; { [].len()  ].len() as isize,
10    |                        -           - missing open `[` for this delimiter

11    |                        |
-    |                        the last unclosed delimiter before unmatched delimiter
+    |                        unclosed delimiter before unmatched delimiter
13 ...
14 LL | mod c {
15    |       - unclosed delimiter

17 LL |         V = [Vec::new; { [0].len() ].len() as isize,
18    |                        -           - missing open `[` for this delimiter
19    |                        |
-    |                        the last unclosed delimiter before unmatched delimiter
+    |                        unclosed delimiter before unmatched delimiter
21 ...
22 LL | fn main() {}
---
To only update this specific test, also pass `--test-args parser/issues/issue-67377-invalid-syntax-in-enum-discriminant.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/parser/issues/issue-67377-invalid-syntax-in-enum-discriminant.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2" "--target=aarch64-unknown-linux-gnu" "--check-cfg" "cfg(test,FALSE)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/parser/issues/issue-67377-invalid-syntax-in-enum-discriminant" "-A" "unused" "-A" "internal_features" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/aarch64-unknown-linux-gnu/native/rust-test-helpers"
stdout: none
--- stderr -------------------------------
error: this file contains an unclosed delimiter
##[error]  --> /checkout/tests/ui/parser/issues/issue-67377-invalid-syntax-in-enum-discriminant.rs:20:65
   |
LL |         V = [PhantomData; { [ () ].len() ].len() as isize,
   |                           -              - missing open `[` for this delimiter
   |                           |
   |                           unclosed delimiter before unmatched delimiter
...
LL |         V = [Vec::new; { [].len()  ].len() as isize,
   |                        -           - missing open `[` for this delimiter
   |                        |
   |                        unclosed delimiter before unmatched delimiter
...
LL | mod c {
   |       - unclosed delimiter
LL |     enum Bug {
LL |         V = [Vec::new; { [0].len() ].len() as isize,
   |                        -           - missing open `[` for this delimiter
   |                        |
   |                        unclosed delimiter before unmatched delimiter
...
LL | fn main() {} //~ ERROR this file contains an unclosed delimiter
   |                                                                ^
---
diff of stderr:

2   --> $DIR/issue-68987-unmatch-issue-2.rs:14:1
3    |
4 LL | async fn obstest() -> Result<> {
-    |                                - the last unclosed delimiter before unmatched delimiter
+    |                                - unclosed delimiter before unmatched delimiter
6 LL |     let obs_connect = || -> Result<(), MyError) {
7    |                                               - missing open `(` for this delimiter
8 ...


The actual stderr differed from the expected stderr
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args parser/issues/issue-68987-unmatch-issue-2.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/parser/issues/issue-68987-unmatch-issue-2.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2" "--target=aarch64-unknown-linux-gnu" "--check-cfg" "cfg(test,FALSE)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/parser/issues/issue-68987-unmatch-issue-2" "-A" "unused" "-A" "internal_features" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/aarch64-unknown-linux-gnu/native/rust-test-helpers"
stdout: none
--- stderr -------------------------------
error: unexpected closing delimiter: `}`
##[error]  --> /checkout/tests/ui/parser/issues/issue-68987-unmatch-issue-2.rs:14:1
   |
LL | async fn obstest() -> Result<> {
   |                                - unclosed delimiter before unmatched delimiter
LL |     let obs_connect = || -> Result<(), MyError) {
   |                                               - missing open `(` for this delimiter
...
LL | } //~ ERROR unexpected closing delimiter
   | ^ unexpected closing delimiter

error: aborting due to 1 previous error
------------------------------------------


---- [ui] tests/ui/parser/issues/issue-68987-unmatch-issue-3.rs stdout ----
Saved the actual stderr to `/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/parser/issues/issue-68987-unmatch-issue-3/issue-68987-unmatch-issue-3.stderr`
diff of stderr:

2   --> $DIR/issue-68987-unmatch-issue-3.rs:8:1
3    |
4 LL |     while cnt < j {
-    |                   - the last unclosed delimiter before unmatched delimiter
+    |                   - unclosed delimiter before unmatched delimiter
6 LL |         write!&mut res, " ");
7    |                            - missing open `(` for this delimiter
8 LL |     }


The actual stderr differed from the expected stderr
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args parser/issues/issue-68987-unmatch-issue-3.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/parser/issues/issue-68987-unmatch-issue-3.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2" "--target=aarch64-unknown-linux-gnu" "--check-cfg" "cfg(test,FALSE)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/parser/issues/issue-68987-unmatch-issue-3" "-A" "unused" "-A" "internal_features" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/aarch64-unknown-linux-gnu/native/rust-test-helpers"
stdout: none
--- stderr -------------------------------
error: unexpected closing delimiter: `}`
##[error]  --> /checkout/tests/ui/parser/issues/issue-68987-unmatch-issue-3.rs:8:1
   |
LL |     while cnt < j {
   |                   - unclosed delimiter before unmatched delimiter
LL |         write!&mut res, " ");
   |                            - missing open `(` for this delimiter
LL |     }
LL | } //~ ERROR unexpected closing delimiter
   | ^ unexpected closing delimiter

error: aborting due to 1 previous error
------------------------------------------


---- [ui] tests/ui/parser/issues/issue-81827.rs stdout ----
Saved the actual stderr to `/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/parser/issues/issue-81827/issue-81827.stderr`
diff of stderr:

5    |          -  -         -- ^
6    |          |  |         ||
7    |          |  |         |missing open `[` for this delimiter
-    |          |  |         the last unclosed delimiter before unmatched delimiter
+    |          |  |         unclosed delimiter before unmatched delimiter
9    |          |  unclosed delimiter
10    |          unclosed delimiter
11 


The actual stderr differed from the expected stderr
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args parser/issues/issue-81827.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/parser/issues/issue-81827.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2" "--target=aarch64-unknown-linux-gnu" "--check-cfg" "cfg(test,FALSE)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/parser/issues/issue-81827" "-A" "unused" "-A" "internal_features" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/aarch64-unknown-linux-gnu/native/rust-test-helpers"
stdout: none
--- stderr -------------------------------
error: this file contains an unclosed delimiter
##[error]  --> /checkout/tests/ui/parser/issues/issue-81827.rs:6:27
   |
LL | fn r()->i{0|{#[cfg(r(0{]0
   |          -  -         -- ^
   |          |  |         ||
   |          |  |         |missing open `[` for this delimiter
   |          |  |         unclosed delimiter before unmatched delimiter
   |          |  unclosed delimiter
   |          unclosed delimiter

error: aborting due to 1 previous error
---
3    |
4 LL | pub fn foo(x: i64) -> i64 {
-    |                           - the last unclosed delimiter before unmatched delimiter
+    |                           - unclosed delimiter before unmatched delimiter
6 LL |     x.abs)
7    |          - missing open `(` for this delimiter
8 LL | }


The actual stderr differed from the expected stderr
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args parser/issues/unnessary-error-issue-138401.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/parser/issues/unnessary-error-issue-138401.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2" "--target=aarch64-unknown-linux-gnu" "--check-cfg" "cfg(test,FALSE)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/parser/issues/unnessary-error-issue-138401" "-A" "unused" "-A" "internal_features" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/aarch64-unknown-linux-gnu/native/rust-test-helpers"
stdout: none
--- stderr -------------------------------
error: unexpected closing delimiter: `}`
##[error]  --> /checkout/tests/ui/parser/issues/unnessary-error-issue-138401.rs:3:1
   |
LL | pub fn foo(x: i64) -> i64 {
   |                           - unclosed delimiter before unmatched delimiter
LL |     x.abs)
   |          - missing open `(` for this delimiter
LL | }
   | ^ unexpected closing delimiter

error: aborting due to 1 previous error
------------------------------------------
---
diff of stderr:

17    |     --- unclosed delimiter
18    |     ||
19    |     |missing open `[` for this delimiter
-    |     the last unclosed delimiter before unmatched delimiter
+    |     unclosed delimiter before unmatched delimiter
21 LL | (; {`
22    | -  - unclosed delimiter
23    | |


The actual stderr differed from the expected stderr
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args suggestions/issue-94171.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/suggestions/issue-94171.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2" "--target=aarch64-unknown-linux-gnu" "--check-cfg" "cfg(test,FALSE)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/suggestions/issue-94171" "-A" "unused" "-A" "internal_features" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/aarch64-unknown-linux-gnu/native/rust-test-helpers"
stdout: none
--- stderr -------------------------------
error: unknown start of token: `
##[error]  --> /checkout/tests/ui/suggestions/issue-94171.rs:2:5
   |
LL | (; {`
   |     ^
   |
help: Unicode character '`' (Grave Accent) looks like ''' (Single Quote), but it is not
   |
LL - (; {`
LL + (; {'
   |

error: this file contains an unclosed delimiter
##[error]  --> /checkout/tests/ui/suggestions/issue-94171.rs:4:52
   |
LL | fn L(]{match
   |     --- unclosed delimiter
   |     ||
   |     |missing open `[` for this delimiter
   |     unclosed delimiter before unmatched delimiter
LL | (; {`
   | -  - unclosed delimiter
   | |
   | unclosed delimiter
LL | //~^ ERROR unknown start of token: `
LL | //~ ERROR this file contains an unclosed delimiter
   |                                                   ^
---
Saved the actual stderr to `/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/typeck/issue-91334/issue-91334.stderr`
diff of stderr:

5    |       -       -   -- ^
6    |       |       |   ||
7    |       |       |   |missing open `(` for this delimiter
-    |       |       |   the last unclosed delimiter before unmatched delimiter
+    |       |       |   unclosed delimiter before unmatched delimiter
9    |       |       unclosed delimiter
10    |       unclosed delimiter
11 


The actual stderr differed from the expected stderr
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args typeck/issue-91334.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/typeck/issue-91334.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2" "--target=aarch64-unknown-linux-gnu" "--check-cfg" "cfg(test,FALSE)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/typeck/issue-91334" "-A" "unused" "-A" "internal_features" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/aarch64-unknown-linux-gnu/native/rust-test-helpers"
stdout: none
--- stderr -------------------------------
error: this file contains an unclosed delimiter
##[error]  --> /checkout/tests/ui/typeck/issue-91334.rs:6:23
   |
LL | fn f(){||yield(((){),
   |       -       -   -- ^
   |       |       |   ||
   |       |       |   |missing open `(` for this delimiter
   |       |       |   unclosed delimiter before unmatched delimiter
   |       |       unclosed delimiter
   |       unclosed delimiter

error: aborting due to 1 previous error

LL | #![w,)
| ^ ^ mismatched closing delimiter
| |
| unclosed delimiter
Copy link
Member

Choose a reason for hiding this comment

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

this is a typical mismatched one,
the right fix maybe [w,] or (w,),
it depends on the specific scenario.
but the new current hint is suggesting the second fix or adding another extra (?
seems the old diagnostics is better.

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.

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