Skip to content

Confusing suggestion on incorrect closing } #70583

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

Closed
RalfJung opened this issue Mar 30, 2020 · 4 comments
Closed

Confusing suggestion on incorrect closing } #70583

RalfJung opened this issue Mar 30, 2020 · 4 comments
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@RalfJung
Copy link
Member

RalfJung commented Mar 30, 2020

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.

@RalfJung RalfJung added the C-bug Category: This is a bug. label Mar 30, 2020
@jonas-schievink jonas-schievink added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 30, 2020
@kper
Copy link
Contributor

kper commented Mar 31, 2020

@rustbot claim

@rustbot rustbot self-assigned this Mar 31, 2020
@kper
Copy link
Contributor

kper commented Mar 31, 2020

In the last commit, I simply dropped the "block is empty..." message.
This leads to this error message now:

error: unexpected closing delimiter: `}`
  --> main.rs:20:1
   |
20 | }
   | ^ unexpected closing delimiter

error: aborting due to previous error

Any suggestions what to put there too?

@kper
Copy link
Contributor

kper commented Apr 24, 2020

@RalfJung the PR has been merged. Is the issue resolved for you now? Can you close it?

@RalfJung
Copy link
Member Author

Yes the new behavior is perfect, thanks. :)

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 C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants