-
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
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.
tests/ui/macros/issue-102878.stderr
Outdated
@@ -2,7 +2,7 @@ error: mismatched closing delimiter: `)` | |||
--> $DIR/issue-102878.rs:1:35 | |||
| | |||
LL | macro_rules!test{($l:expr,$_:r)=>({const:y y)} | |||
| -^ ^ mismatched closing delimiter | |||
| -^ ^ mismatched closing delimiter, may missing open `(` | |||
| || |
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 worse too, we are not sure we should replace the left {
to (
or replace the right )
to }
.
so, the better way is do not suggest any direction.
I think we should only suggest missing a open(or closing) delimiter in the scenario that if we added a open(or closing) delimiter, there will be no error.
I don't have a good way to judge whether adding the open delimiter is a better way. As in the previous implementation, there will always be some false positives. If we have to make a balance, should we make suggestions as comprehensively as possible, or would we rather not make suggestions and minimize false positives? Maybe I need to refactor this code more. |
LL | pub fn foo(x: i64) -> i64 { | ||
| ^ unclosed delimiter | ||
LL | x.abs) | ||
| ^ mismatched closing delimiter, may missing open `(` |
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 better to suggest like this:
missing open `(` for this delimiter
as the origin issue reported wrote in #138401
I have a look at the current code, current output is:
The first diagnostic message is reported at here(you moved it into lexer, it is ok): The second diagnostic is reported at here: To resolve the issue in #138401, can we just remove the first diagnostic if we could report the second one? or at least reorder these two diagnostics, which could also reduce the confusion. |
This part of the code conflicted with master, so I submitted the PR #140147 first to do some cleanup, otherwise the code for this PR would have been rather messy. @chenyukang |
Yes, I haven't had time to deal with this pr yet. Thanks for reminding me.😁 |
They review some old PRs every week in the weekly meeting. If you don't plan to move forward with this PR for the time being, you can close it first and reopen it later. This can prevent this PR from appearing in the review list. |
yeah I will take it later. Let me remove it out of the review list first |
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
…eport to reduce confusion Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
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.
@rustbot ready
let mut reported_missing_open = false; | ||
for unmatch_brace in unmatched_delims.iter() { | ||
unmatched_delims.retain(|unmatch_brace| { |
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.
When missing open xxx for this delimiter
is reported in the unexpected closing delimiter: xxx
error, I remove the corresponding unmatched_delims
so that make_unclosed_delims_error
doesn't get double report.
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.
First of all, thank you for all your changes and your patience to improve this output!
Do we have any test left where the lexer diagnostic is still emitted?
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.
Yes, such as
https://github.com/xizheyin/rust/blob/issue-138401/tests/ui/parser/issues/issue-58856-2.stderr
https://github.com/xizheyin/rust/blob/issue-138401/tests/ui/parser/issues/issue-58856-1.stderr
https://github.com/xizheyin/rust/blob/issue-138401/tests/ui/parser/unclosed-delimiter-in-dep.stderr
I found 27 results after searching.
LL | async fn obstest() -> Result<> { | ||
| ^ unclosed delimiter | ||
LL | let obs_connect = || -> Result<(), MyError) { | ||
| ^ mismatched closing 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 might make sense to also collect the unclosed opening delimiter to be included in the later error:
error: unexpected closing delimiter: `}`
--> $DIR/issue-68987-unmatch-issue-2.rs:14:1
|
LL | async fn obstest() -> Result<> {
| ^ the mismatched closing `)` matches this `{`
LL | let obs_connect = || -> Result<(), MyError) {
| - missing open `(` for this delimiter
...
LL | }
| ^ unexpected closing delimiter
…ng delimiter` Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
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. |
if open_delim == close_delim { | ||
err.span_label( | ||
open_delim_span, | ||
format!("the mismatchd closing `{}` may be matched here", token_str), |
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 message has a typo, and I'd like to tweak the wording here a bit, I just don't have a good idea for what the ideal text would be in context.
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.
Maybe something "the mismatched closing {token_str}
may be meant for this opening delimiter"?
#![c={#![c[)x | ||
//~ ERROR this file contains an 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 should make the .stderr
output a bit easier to read:
#![c={#![c[)x | |
//~ ERROR this file contains an unclosed delimiter | |
//~v ERROR this file contains an unclosed delimiter | |
#![c={#![c[)x |
error: unexpected closing delimiter: `}` | ||
--> $DIR/deli-ident-issue-2.rs:5:1 | ||
| | ||
LL | fn main() { | ||
| - the mismatchd closing `}` may be matched here | ||
LL | if 1 < 2 { |
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.
I feel like we should still have a label pointing at this opening {
, stating that the closing ]
matches it.
Fixes #138401