Skip to content

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

Closed
@chenyukang

Description

@chenyukang

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;

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsD-confusingDiagnostics: Confusing error or lint that should be reworked.D-incorrectDiagnostics: A diagnostic that is giving misleading or incorrect information.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions