-
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.
I marked potential matched unclosed delimiter when emit |
@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. |
That makes sense. Different situations are treated differently. I will investigate further. |
☔ The latest upstream changes (presumably #143526) made this pull request unmergeable. Please resolve the merge conflicts. |
Signed-off-by: xizheyin <[email protected]>
1c4382c
to
ce088f0
Compare
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
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. |
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.
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 |
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.
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 `(`.
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.
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
{)}
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.
Thank you, I understand it. I'll try to do it only in this case.
The job Click to see the possible cause of the failure (guessed by this bot)
|
LL | #![w,) | ||
| ^ ^ mismatched closing delimiter | ||
| | | ||
| unclosed delimiter |
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 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.
Fixes #138401