-
Notifications
You must be signed in to change notification settings - Fork 13.5k
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
base: master
Are you sure you want to change the base?
Conversation
rustbot has assigned @compiler-errors. Use |
r? compiler |
I changed this part last year, will review this PR later. r? @chenyukang |
tests/ui/parser/issues/issue-67377-invalid-syntax-in-enum-discriminant.stderr
Outdated
Show resolved
Hide resolved
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:
|
@rustbot author |
Reminder, once the PR becomes ready for a review, use |
Thanks, I will revise it soon! |
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 In the third commit, I make a distinction between the different delimiters before triggering a |
I've combined them into one line so it's more aesthetically pleasing.
Since the |
This comment has been minimized.
This comment has been minimized.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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 '{' ?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
tests/ui/parser/issues/issue-67377-invalid-syntax-in-enum-discriminant.stderr
Outdated
Show resolved
Hide resolved
LL | V = [PhantomData; { [ () ].len() ].len() as isize, | ||
| - missing open `[` for this delimiter | ||
... | ||
LL | mod b { | ||
| - unclosed delimiter | ||
LL | enum Bug { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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. :)
I need to clarify the direction of the modification. |
per my understanding, the issue #138554 (comment) refers to is introduced by the code in this PR, not a old one? |
Oh! That makes sense. This seems to require finer control. |
There was a problem hiding this 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.
tests/ui/parser/issues/issue-67377-invalid-syntax-in-enum-discriminant.stderr
Outdated
Show resolved
Hide resolved
This comment has been minimized.
This comment has been minimized.
Signed-off-by: xizheyin <[email protected]>
Signed-off-by: xizheyin <[email protected]>
Signed-off-by: xizheyin <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This time, I reserve the mismatched
error when the situation is like {[)}
.
And I remove the mismatched
error only when close_delim_err
, which means double close delims.
Meanwhile, I remove duplicate missing open ... for this delimiter
in this file contains an unclosed delimiter
error because mismatched
errors have already emitted it.
Fixes #138401