Skip to content

match_single_binding suggests code with invalid syntax #15269

Open
@antonilol

Description

@antonilol

Summary

a suggestion from the match_single_binding lint includes invalid syntax

posted here but later thought "people with notifications for new issues won't notice that"
could be fixed by #15060

Reproducer

I tried this code:

fn what(a: usize, b: usize, c: usize) -> bool {
    a < b
        && match b {
            b => b < c,
        }
}

I expected to see this happen:
match_single_binding suggests something like this:

fn what(a: usize, b: usize, c: usize) -> bool {
    a < b
        && b < c
}

Instead, this happened:
match_single_binding suggests this:

fn what(a: usize, b: usize, c: usize) -> bool {
    a < b
        && let b = b;
        b < c
}

Version

rustc 1.88.0 (6b00bc388 2025-06-23)
binary: rustc
commit-hash: 6b00bc3880198600130e1cf62b8f8a93494488cc
commit-date: 2025-06-23
host: x86_64-unknown-linux-gnu
release: 1.88.0
LLVM version: 20.1.5

Additional Labels

@rustbot label +I-suggestion-causes-bug

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-suggestion-causes-bugIssue: The suggestion compiles but changes the code to behave in an unintended way

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions