rustfmt switches `;` around causing type error
Open
@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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.