rust-lang / rust-lang/rust-clippy

`collapsible_match` suggestion on labeled match arm block causes syntax error

Open
#17,427 2 comments 0 reactions 1 assignee View on GitHub

@Halloloid is already working on this.

Since Jul 17, 2026.

C-bug I-suggestion-causes-error
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

Description
Summary:

collapsible_match incorrectly transforms an if statement into a match guard when the outer match arm block has a label (=> 'label: { ... }). The suggestion replaces the wrong byte spans (specifically deleting the match arrow and the label's leading single quote => ') leaving the rest of the label name (label: {) in a syntactically invalid position, breaking compilation.

Reproducer Code:
#![allow(dead_code)]

use std::sync::{LazyLock};

static A: LazyLock<bool> = LazyLock::new(|| true);

struct LeAudioModule {}

fn from_bytes(_d: &[u8]) -> Result<Option<u8>, ()> {
    Ok(Some(0))
}

impl LeAudioModule {
    fn out_cmd(&self, data: &[u8]) {
        match from_bytes(data) {
            Ok(None) => {
                println!("()");
            }
            Ok(Some(_c)) => 'command: {
                if *A {
                    let Some(_stream) = Some(0) else {
                        break 'command;
                    };
                }
            }
            _ => (),
        }
    }
}

Godbolt Reproducer

Incorrect Current Suggestion:
            Ok(Some(_c))command: {
                if *A => {
                    let Some(_stream) = Some(0) else {
                        break 'command;
                    };
                }
This causes the compiler to fail with syntax/parsing errors:
error: this file contains an unclosed delimiter
   --> packages/modules/Bluetooth/offload/leaudio/hci/proxy.rs:679:3
   |
19 |             Ok(Some(_c))command: {
   |                                  - unclosed delimiter
20 |                 if *A => {
   |                            - this delimiter might not be properly closed...
...
27 | }
   | ^
Correct suggestion:
            Ok(Some(_c)) if *A => 'command: {
                let Some(_stream) = Some(0) else {
                    break 'command;
                };
            }

Correct Suggestion on Godbolt

Version
clippy 0.1.98 (af3d95584d 2026-07-09)
Additional Labels
  • C-Bug
  • I-invalid-suggestion

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.