-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Improve unexpected close and mismatch delimiter hint in TokenTreesReader #104012
Improve unexpected close and mismatch delimiter hint in TokenTreesReader #104012
Conversation
r? @wesleywiser (rustbot has picked a reviewer for you, use r? to override) |
This is an issue I found from rustc dev experience, for example this file: We have an extra '{' at line 1420, but the first error report from compiler is: --> e3.rs:2605:3
|
38 | impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
| - unclosed delimiter
...
110 | sugg_span: Span| {
| - this delimiter might not be properly closed...
...
240 | };
| - ...as it matches this but it has different indentation
...
2605 | }
| ^
error: expected expression, found `let` statement
--> e3.rs:1421:12
|
1421 | && let Some((fields, substs)) =
| ^^^
The first diagnostic's tip |
Oops, find a better solution.... |
83c0934
to
1a8e69a
Compare
@estebank |
It will report out this, we have narrowed the scope of root-cause: error: this file contains an unclosed delimiter
--> src/test/ui/parser/deli-ident-issue-1.rs:27:65
|
7 | impl dyn Demo {
| - unclosed delimiter
...
19 | && let Some(c) = num {
| - this delimiter might not be properly closed...
...
24 | }
| - ...as it matches this but it has different indentation
...
27 | fn main() { } //~ ERROR this file contains an unclosed delimiter
| ^ |
But we still can not handle well for this kind of case: fn f(i: u32, j: u32) {
let res = String::new();
let mut cnt = i;
while cnt < j {
write!&mut res, " ");
}
} Current error is: error: unexpected closing delimiter: `}`
--> bug3.rs:7:1
|
1 | fn f(i: u32, j: u32) {
| - this delimiter might not be properly closed...
...
6 | }
| - ...as it matches this but it has different indentation
7 | }
| ^ unexpected closing delimiter
error: mismatched closing delimiter: `)` And this code: async fn obstest() -> Result<> {
let obs_connect = || -> Result<(), MyError) {
async {
}
}
if let Ok(version, scene_list) = obs_connect() {
} else {
}
} report: error: unexpected closing delimiter: `}`
--> bug2.rs:12:1
|
12 | }
| ^ unexpected closing delimiter
error: mismatched closing delimiter: `)`
--> bug2.rs:1:32
|
1 | async fn obstest() -> Result<> {
| ^ unclosed delimiter
2 | let obs_connect = || -> Result<(), MyError) {
| ^ mismatched closing delimiter
error: aborting due to 2 previous errors This is because we currently may use ')' to match '{' as a close delimiter. |
I'm not very familiar with the reporting code here so r? @estebank |
19a7695
to
01babdc
Compare
I made some more changes in another branch, I'm not sure whether it's Ok for merging it. The main idea is reducing later errors when delimiter mismatch error happens. It is somewhat common to ignore all but the first error when you have mismatched delimiters. I read the source code, we exit when
So for code like this: }
fn main() {
x = 1;
} Compiler will exit with the only first error:
But we only report an error when this
In real dev practice, if the file is somehow very long, My change also returning I'm not sure whether we have any other special considertaion about this, seems there are some recovery code in |
Yeah, let's create a PR for chenyukang@479fdb5 and land it. Sadly delimiter recovery is quite hard and the current behavior isn't what's best for our users. |
01babdc
to
1f1062c
Compare
Conflict is fixed, |
d030739
to
18c2937
Compare
I didn't read too much into the details of |
a1fc3d5
to
8f2ce1e
Compare
r=me after addressing #104012 (comment). |
7a3d767
to
cd23323
Compare
@rustbot ready |
@bors r+ |
…indentation, r=petrochenkov Improve unexpected close and mismatch delimiter hint in TokenTreesReader Fixes rust-lang#103882 Fixes rust-lang#68987 Fixes rust-lang#69259 The inner indentation mismatching will be covered by outer block, the new added function `report_error_prone_delim_block` will find out the error prone candidates for reporting.
…indentation, r=petrochenkov Improve unexpected close and mismatch delimiter hint in TokenTreesReader Fixes rust-lang#103882 Fixes rust-lang#68987 Fixes rust-lang#69259 The inner indentation mismatching will be covered by outer block, the new added function `report_error_prone_delim_block` will find out the error prone candidates for reporting.
…iaskrgr Rollup of 9 pull requests Successful merges: - rust-lang#104012 (Improve unexpected close and mismatch delimiter hint in TokenTreesReader) - rust-lang#104252 (Stabilize the const_socketaddr feature) - rust-lang#105524 (Replace libc::{type} with crate::ffi::{type}) - rust-lang#107096 (Detect references to non-existant messages in Fluent resources) - rust-lang#107355 (Add regression test for rust-lang#60755) - rust-lang#107384 (Remove `BOOL_TY_FOR_UNIT_TESTING`) - rust-lang#107385 (Use `FallibleTypeFolder` for `ConstInferUnifier` not `TypeRelation`) - rust-lang#107391 (rustdoc: remove inline javascript from copy-path button) - rust-lang#107398 (Remove `ControlFlow::{BREAK, CONTINUE}`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
…iaskrgr Rollup of 9 pull requests Successful merges: - rust-lang#104012 (Improve unexpected close and mismatch delimiter hint in TokenTreesReader) - rust-lang#104252 (Stabilize the const_socketaddr feature) - rust-lang#105524 (Replace libc::{type} with crate::ffi::{type}) - rust-lang#107096 (Detect references to non-existant messages in Fluent resources) - rust-lang#107355 (Add regression test for rust-lang#60755) - rust-lang#107384 (Remove `BOOL_TY_FOR_UNIT_TESTING`) - rust-lang#107385 (Use `FallibleTypeFolder` for `ConstInferUnifier` not `TypeRelation`) - rust-lang#107391 (rustdoc: remove inline javascript from copy-path button) - rust-lang#107398 (Remove `ControlFlow::{BREAK, CONTINUE}`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
…, r=petrochenkov Exit when there are unmatched delims to avoid noisy diagnostics From rust-lang#104012 (comment) r? `@petrochenkov`
…, r=petrochenkov Exit when there are unmatched delims to avoid noisy diagnostics From rust-lang#104012 (comment) r? ``@petrochenkov``
Fixes #103882
Fixes #68987
Fixes #69259
The inner indentation mismatching will be covered by outer block, the new added function
report_error_prone_delim_block
will find out the error prone candidates for reporting.