Skip to content

Combination of try blocks, never type, and rustfmt is broken #140361

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 27, 2025 · 2 comments
Open

Combination of try blocks, never type, and rustfmt is broken #140361

kryptan opened this issue Apr 27, 2025 · 2 comments
Labels
A-rustfmt Area: Rustfmt C-bug Category: This is a bug. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged.

Comments

@kryptan
Copy link
Contributor

kryptan commented Apr 27, 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

I'm not sure if rustfmt shouldn't add a semicolon here or if rustc should accept a semicolon.

Playground link

Meta

Nightly channel

Build using the Nightly version: 1.88.0-nightly

(2025-04-26 10fa3c449f6b1613b352)
@kryptan kryptan added the C-bug Category: This is a bug. label Apr 27, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Apr 27, 2025
@moxian
Copy link
Contributor

moxian commented Apr 28, 2025

This is rustfmt bug, so should be filed under https://github.com/rust-lang/rustfmt/issues
Let me try moving it (i'm not sure i have perms)
@rustbot transfer rustfmt

welp, i don't..
@rustbot label: +A-rustfmt

@rustbot
Copy link
Collaborator

rustbot commented Apr 28, 2025

Only team members may use the transfer command.

@rustbot rustbot added the A-rustfmt Area: Rustfmt label Apr 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rustfmt Area: Rustfmt C-bug Category: This is a bug. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged.
Projects
None yet
Development

No branches or pull requests

3 participants