Uh oh!
There was an error while loading. Please reload this page.
Improve unexpected close and mismatch delimiter hint in TokenTreesReader - #104012
Conversation
rustbot
commented
Nov 5, 2022
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 |
chenyukang
commented
Nov 7, 2022
Oops, find a better solution.... |
83c0934 to
1a8e69aComparechenyukang
commented
Nov 7, 2022
@estebank |
chenyukang
commented
Nov 7, 2022
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: fnf(i:u32,j:u32){let res = String::new();letmut 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 indentation7 | } | ^ unexpected closing delimitererror: mismatched closing delimiter: `)`And this code: asyncfn obstest() -> Result<> {let obs_connect = || -> Result<(),MyError){async{}}ifletOk(version, scene_list) = obs_connect(){}else{}}report: error: unexpected closing delimiter: `}` --> bug2.rs:12:1 |12 | } | ^ unexpected closing delimitererror: mismatched closing delimiter: `)` --> bug2.rs:1:32 |1 | async fn obstest() -> Result<> { | ^ unclosed delimiter2 | let obs_connect = || -> Result<(), MyError) { | ^ mismatched closing delimitererror: aborting due to 2 previous errorsThis is because we currently may use ')' to match '{' as a close delimiter. |
wesleywiser
commented
Nov 10, 2022
I'm not very familiar with the reporting code here so r? @estebank |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
19a7695 to
01babdcCompareI 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: }fnmain(){
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 |
estebank
commented
Nov 11, 2022
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. |
Uh oh!
There was an error while loading. Please reload this page.
01babdc to
1f1062cComparechenyukang
commented
Jan 18, 2023
Conflict is fixed, |
d030739 to
18c2937Comparepetrochenkov
commented
Jan 27, 2023
I didn't read too much into the details of |
a1fc3d5 to
8f2ce1eCompareUh oh!
There was an error while loading. Please reload this page.
petrochenkov
commented
Jan 27, 2023
r=me after addressing #104012 (comment). |
7a3d767 to
cd23323Comparechenyukang
commented
Jan 27, 2023
@rustbot ready |
petrochenkov
commented
Jan 27, 2023
@bors r+ |
bors
commented
Jan 27, 2023
…indentation, r=petrochenkov Improve unexpected close and mismatch delimiter hint in TokenTreesReader Fixesrust-lang#103882Fixesrust-lang#68987Fixesrust-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 Fixesrust-lang#103882Fixesrust-lang#68987Fixesrust-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_blockwill find out the error prone candidates for reporting.