rust-lang / rust-lang/rustfmt

rustfmt switches `;` around causing type error

Open
#7,061 1 comment 0 reactions 1 assignee View on GitHub

@AsthaMishra is already working on this.

Since Aug 25, 2026.

A-control-flow C-bug I-invalid-code
Dominant language
Rust
Stars
7k
Forks
1.1k
Avg merge
2d 13h
Merged PRs (30d)
24

Description

this compiles:

unsafe fn foo()  ->  i32  {  42  }

fn  main  ()  {
        'label:  loop  {
                break  'label  unsafe  {  foo()  }
        };
}

rusfmt will put the ; from the outer loop into the inner break line which causes a type error

unsafe fn foo() -> i32 {
    42
}

fn main() {
    'label: loop {
        break 'label unsafe { foo() };
    }
}

error[E0308]: mismatched types
 --> 215954736694087965021913531671331578058.rs:7:31
  |
5 | fn main() {
  |          - expected `()` because of this return type
6 |     'label: loop {
  |             ---- this loop is expected to be of type `()`
7 |         break 'label unsafe { foo() };
  |                               ^^^^^- help: consider using a semicolon here: `;`
  |                               |
  |                               expected `()`, found `i32`

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0308`.

rustc 1.100.0-nightly (fb6531d55 2026-08-23)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.