Skip to content
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

Use indentation for delimiter mismatch detecting may get wrong help message #103882

Closed
chenyukang opened this issue Nov 2, 2022 · 5 comments · Fixed by #104012
Closed

Use indentation for delimiter mismatch detecting may get wrong help message #103882

chenyukang opened this issue Nov 2, 2022 · 5 comments · Fixed by #104012
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-confusing Diagnostics: Confusing error or lint that should be reworked. D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@chenyukang
Copy link
Member

chenyukang commented Nov 2, 2022

For code

#![feature(let_chains)]
trait FnCtxt {}

impl dyn FnCtxt {
    pub fn report(&self) -> u32 {
        let sum = |a: u32,
                   b: u32,
                   c: u32| {
            a + b + c
        };
        sum(1, 2, 3)
    }

    fn check(&self, val: Option<u32>, num: Option<u32>) {
        if let Some(b) = val
        && let Some(c) = num {
        && b == c {
        }
    }
}

fn main() { }

Current output is:

error: this file contains an unclosed delimiter
  --> src/main.rs:22:15
   |
4  | impl dyn FnCtxt {
   |                 - unclosed delimiter
...
8  |                    c: u32| {
   |                            - this delimiter might not be properly closed...
9  |             a + b + c
10 |         };
   |         - ...as it matches this but it has different indentation
...
22 | fn main() { }
   |               ^

It's error because indentation mismatch at line 8 and 10, ideally, we should report there is an extra { at line 16.

Or we only show line 4~22 has unclosed delimiter, wrong help message may mislead user.

The root cause is we use indentation width for checking possible position:

return delim == d && close_padding != open_padding;

@chenyukang
Copy link
Member Author

Related issue: #68987

@Rageking8
Copy link
Contributor

@rustbot label +A-diagnostics +T-compiler +D-confusing +D-papercut

@rustbot rustbot added A-diagnostics Area: Messages for errors, warnings, and lints D-confusing Diagnostics: Confusing error or lint that should be reworked. D-papercut Diagnostics: An error or lint that needs small tweaks. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 2, 2022
@compiler-errors compiler-errors added D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. and removed D-papercut Diagnostics: An error or lint that needs small tweaks. labels Nov 3, 2022
@chenyukang
Copy link
Member Author

For code:
image

The line at 68 will also detected as not match, because of the .

@chenyukang
Copy link
Member Author

chenyukang commented Nov 5, 2022

Generally, I think using indentation width for detecting possible mismatch position is not good in practice, since code will not be formatted perfectly as we assumed.

Give a wrong tip will make user spent more time to find the root cause.

@chenyukang
Copy link
Member Author

@rustbot claim

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jan 27, 2023
…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.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jan 28, 2023
…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.
@bors bors closed this as completed in e3048c7 Jan 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-confusing Diagnostics: Confusing error or lint that should be reworked. D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants