Skip to content

match_single_binding: missing brackets #15018

Open
@samueltardieu

Description

@samueltardieu

Summary

The fix in #15017 is incomplete and only handles the particular issue that was reported. The problem is that brackets are needed in the general case to create a scope which will restrict the lifetime of created values.

Reproducer

I tried this code:

fn main() {
    let a = 10;
    match 11 {
        a => { println!("a = {a}"); }
    }
    println!("a = {a}");
}

Before autofix, this code prints:

a = 11
a = 10

After autofix, the code prints:

a = 11
a = 11

because the autofix, even with #15017 applied, reads:

fn main() {
    let a = 10;
    let a = 11;
    { println!("a = {a}"); }
    println!("a = {a}");
}

Version

Clippy master as of 9e7782b8

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