Skip to content

match_single_binding is false positive on temporaries  #6614

Open
@MikailBag

Description

@MikailBag

Lint name: match_single_binding

I tried this code:

fn main() {
    match format_args!("hello {}", "world") {
        f => dbg!(f),
    };
}

(playground link)

Clippy prints a warning:

warning: this match could be written as a `let` statement

With a proposal:

let f = format_args!("hello {}", "world");
dbg!(f);

But suggested code does not compile, because f is bound to a temporary value and its lifetime ends before dbg!.

Meta

  • cargo clippy -V: 0.1.51 (2021-01-20 a4cbb44)
  • rustc -Vv:
rustc 1.49.0 (e1884a8e3 2020-12-29)
binary: rustc
commit-hash: e1884a8e3c3e813aada8254edfa120e85bf5ffca
commit-date: 2020-12-29
host: x86_64-unknown-linux-gnu
release: 1.49.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingE-hardCall for participation: This a hard problem and requires more experience or effort to work onI-false-positiveIssue: The lint was triggered on code it shouldn't haveI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when appliedT-MIRType: This lint will require working with the MIR

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions