Skip to content

collapsible_match suggestion on labeled match arm block causes syntax error #17427

Description

@Harini0924

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions