Skip to content

Semicolon after a return statement breaks code with try blocks and never type #6553

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

Open
kryptan opened this issue Apr 30, 2025 · 0 comments
Labels
bug Panic, non-idempotency, invalid code, etc.

Comments

@kryptan
Copy link

kryptan commented Apr 30, 2025

Consider this code:

#![feature(never_type, try_blocks)]

fn main() {
    let _: Result<!, ()> = try {
        ();
        return
    };
}

It compiles.

Rustfmt adds a semicolon here:

#![feature(never_type, try_blocks)]

fn main() {
    let _: Result<!, ()> = try {
        ();
        return;
    };
}

This causes a compilation error:

   Compiling playground v0.0.1 (/playground)
error[E0271]: type mismatch resolving `<Result<!, ()> as Try>::Output == ()`
 --> src/main.rs:7:5
  |
7 |     };
  |     ^ expected `()`, found `!`
  |
  = note: expected unit type `()`
                  found type `!`

For more information about this error, try `rustc --explain E0271`.
error: could not compile `playground` (bin "playground") due to 1 previous error

Playground link

Previously reported here.

Meta

Nightly channel

Build using the Nightly version: 1.88.0-nightly

(2025-04-26 10fa3c449f6b1613b352)
@calebcartwright calebcartwright added the bug Panic, non-idempotency, invalid code, etc. label May 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Panic, non-idempotency, invalid code, etc.
Projects
None yet
Development

No branches or pull requests

2 participants