Skip to content

match_single_binding can't add semicolon if expression is returned #15537

@matthiaskrgr

Description

@matthiaskrgr

Using the following flags

--force-warn clippy::match_single_binding

this code:

struct A;
struct B;

impl Drop for A {
    fn drop(&mut self) {}
}
impl Drop for B {
    fn drop(&mut self) {}
}

#[inline(always)]
fn no_unwind() {}

fn weird_temporary(a: A, b: B, nothing: ((), (), ()), x: bool) -> ((), (), ()) {
    'scope: {
        (
            {
                let _z = b;
                if x {
                    break 'scope nothing;
                }
            },
            match { a } {
                _ => (),
            },
            no_unwind(),
        )
    }
}

fn main() {}

caused the following diagnostics:

    Checking _104736 v0.1.0 (/tmp/icemaker_global_tempdir.Cuu53SxwZ7v9/icemaker_clippyfix_tempdir.IWeaSbA3kdqa/_104736)
warning: this match could be replaced by its scrutinee and body
  --> src/main.rs:23:13
   |
23 | /             match { a } {
24 | |                 _ => (),
25 | |             },
   | |_____________^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#match_single_binding
   = note: requested on the command line with `--force-warn clippy::match-single-binding`
help: consider using the scrutinee and body instead
   |
23 ~             { a };
24 ~             (),
   |

warning: `_104736` (bin "_104736") generated 1 warning
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.30s

However after applying these diagnostics, the resulting code:

struct A;
struct B;

impl Drop for A {
    fn drop(&mut self) {}
}
impl Drop for B {
    fn drop(&mut self) {}
}

#[inline(always)]
fn no_unwind() {}

fn weird_temporary(a: A, b: B, nothing: ((), (), ()), x: bool) -> ((), (), ()) {
    'scope: {
        (
            {
                let _z = b;
                if x {
                    break 'scope nothing;
                }
            },
            { a },;
            (),
            no_unwind(),
        )
    }
}

fn main() {}

no longer compiled:

    Checking _104736 v0.1.0 (/tmp/icemaker_global_tempdir.Cuu53SxwZ7v9/icemaker_clippyfix_tempdir.IWeaSbA3kdqa/_104736)
error: expected expression, found `;`
  --> src/main.rs:23:19
   |
23 |             { a },;
   |                   ^ expected expression

error: could not compile `_104736` (bin "_104736" test) due to 1 previous error
warning: build failed, waiting for other jobs to finish...
error: could not compile `_104736` (bin "_104736") due to 1 previous error

Version:

rustc 1.91.0-nightly (d20509c2a 2025-08-22)
binary: rustc
commit-hash: d20509c2a0c71b60aa2b51566e4d14920e8a1661
commit-date: 2025-08-22
host: x86_64-unknown-linux-gnu
release: 1.91.0-nightly
LLVM version: 21.1.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    I-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when applied

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions