Skip to content

match_single_binding on match on closure causes syntax error #14991

Closed
@matthiaskrgr

Description

@matthiaskrgr

Using the following flags

--force-warn clippy::match_single_binding

this code:

// Tests that no ICE occurs when a closure appears inside a node
// that does not have a body when compiling with
//@ check-pass

#![allow(dead_code)]

struct Bug {
    inner: [(); match || 1 {
        _n => 42, // we may not call the closure here (E0015)
    }],
}

enum E {
    V([(); { let _ = || 1; 42 }]),
}

type Ty = [(); { let _ = || 1; 42 }];

fn main() {}

caused the following diagnostics:

    Checking _thir-unsafeck-issue-85871 v0.1.0 (/tmp/icemaker_global_tempdir.o4hDRjvshrmO/icemaker_clippyfix_tempdir.NH5F7xmlFPeq/_thir-unsafeck-issue-85871)
warning: this match could be written as a `let` statement
  --> src/main.rs:8:17
   |
8  |       inner: [(); match || 1 {
   |  _________________^
9  | |         _n => 42, // we may not call the closure here (E0015)
10 | |     }],
   | |_____^
   |
   = 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 a `let` statement
   |
8  ~     inner: [(); let _n = || 1;
9  ~     42],
   |

warning: `_thir-unsafeck-issue-85871` (bin "_thir-unsafeck-issue-85871") generated 1 warning
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.12s

However after applying these diagnostics, the resulting code:

// Tests that no ICE occurs when a closure appears inside a node
// that does not have a body when compiling with
//@ check-pass

#![allow(dead_code)]

struct Bug {
    inner: [(); let _n = || 1;
    42],
}

enum E {
    V([(); { let _ = || 1; 42 }]),
}

type Ty = [(); { let _ = || 1; 42 }];

fn main() {}

no longer compiled:

    Checking _thir-unsafeck-issue-85871 v0.1.0 (/tmp/icemaker_global_tempdir.o4hDRjvshrmO/icemaker_clippyfix_tempdir.NH5F7xmlFPeq/_thir-unsafeck-issue-85871)
error: expected expression, found `let` statement
 --> src/main.rs:8:17
  |
8 |     inner: [(); let _n = || 1;
  |                 ^^^
  |
  = note: only supported directly in conditions of `if` and `while` expressions

error: expected one of `.`, `?`, `]`, or an operator, found `;`
 --> src/main.rs:8:30
  |
7 | struct Bug {
  |        --- while parsing this struct
8 |     inner: [(); let _n = || 1;
  |                              ^ expected one of `.`, `?`, `]`, or an operator

error: could not compile `_thir-unsafeck-issue-85871` (bin "_thir-unsafeck-issue-85871") due to 2 previous errors
warning: build failed, waiting for other jobs to finish...
error: could not compile `_thir-unsafeck-issue-85871` (bin "_thir-unsafeck-issue-85871" test) due to 2 previous errors

Version:

rustc 1.89.0-nightly (cf423712b 2025-06-05)
binary: rustc
commit-hash: cf423712b9e95e9f6ec84b1ecb3d125e55ac8d56
commit-date: 2025-06-05
host: x86_64-unknown-linux-gnu
release: 1.89.0-nightly
LLVM version: 20.1.5

Metadata

Metadata

Assignees

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