-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Diagnostic for early closing delimiter incorrectly blames empty block #98601
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
Comments
Maybe we could form a heuristic around tokens that we know should eventually be followed by If we see one of those, (then some random other tokens), then we see e.g. if we see |
The problem is that the error happens in the lexer, not the parser. Ideally we'd rework the lexer to have a token stream mode of operation instead of a token tree mode of operation, only for code that is being passed to the parser (i.e., not coming from a macro). |
This is particularly confusing when the fn main() {
todo!();
}
fn other(_: i32)) {} gives
on 1.65.0-nightly (2022-08-31 9243168) |
the output now changed to: error: unexpected closing delimiter: `}`
--> <source>:7:1
|
1 | fn foo() {
| - this delimiter might not be properly closed...
2 | match 0 {
3 | _ => {}
| -- block is empty, you might have not meant to close it
...
6 | }
| - ...as it matches this but it has different indentation
7 | }
| ^ unexpected closing delimiter
error: aborting due to previous error Do you think the |
This is changed to: error: unexpected closing delimiter: `)`
--> <source>:5:17
|
1 | fn main() {
| - this opening brace...
2 | todo!();
3 | }
| - ...matches this closing brace
4 |
5 | fn other(_: i32)) {}
| ^ unexpected closing delimiter it seems more helpful now. |
Let's close this ticket after adding these two cases to the test suite then. I'm sure there are outstanding issues in this area, but we can |
Rollup merge of rust-lang#116034 - chenyukang:yukang-98601-add-ui-testcase, r=estebank add UI test for delimiter errors Fixes rust-lang#98601 from rust-lang#98601 (comment) r? `@estebank`
See: https://godbolt.org/z/rPxvYMf1h
This code:
produces
on latest stable (1.61.0). @estebank
The text was updated successfully, but these errors were encountered: