Skip to content

Confusing suggestion on incorrect closing } #70583

Closed
@RalfJung

Description

@RalfJung

I tried this code:

pub enum ErrorHandled {
    Reported,
    TooGeneric,
}

impl ErrorHandled {
    pub fn assert_reported(self) {
        match self {
            ErrorHandled::Reported => {}
            ErrorHandled::TooGeneric => panic!(),
        }
    }
}

fn struct_generic(x: Vec<i32>) {
    for v in x {
        println!("{}", v);
    }
    } // <-- incorrect closing brace
}

I expected to see this happen: Some more or less helpful message about the imbalanced braces.

Instead, this happened: I got a rather confusing suggestion:

error: unexpected closing delimiter: `}`
  --> src/lib.rs:20:1
   |
9  |             ErrorHandled::Reported => {}
   |                                       -- this block is empty, you might have not meant to close it
...
20 | }
   | ^ unexpected closing delimiter

The empty block it points to is not even in the same function, so this suggestion is more confusing than helpful.

This issue has been assigned to @kper via this comment.

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.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