Skip to content

manual_unwrap_or_default triggered for tuple unpacked with _ #12994

@ReagentX

Description

@ReagentX

Summary

https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=4014b05f3e3204cd215b16803e5fcbf7

fn returns_tuple() -> Option<(usize, usize)> {
    todo!()
}

fn passes() -> usize {
    match returns_tuple() {
        Some((x, _z)) => x,
        None => 0,
    }
}

fn fails() -> usize {
    match returns_tuple() {
        Some((x, _)) => x,
        None => 0,
    }
}

fn main() {
    passes();
    fails();
}
    Checking playground v0.0.1 (/playground)
warning: match can be simplified with `.unwrap_or_default()`
  --> src/main.rs:13:5
   |
13 | /     match returns_tuple() {
14 | |         Some((x, _)) => x,
15 | |         None => 0,
16 | |     }
   | |_____^ help: replace it with: `returns_tuple().unwrap_or_default()`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_unwrap_or_default
   = note: `#[warn(clippy::manual_unwrap_or_default)]` on by default

Lint Name

manual_unwrap_or_default

Reproducer

I tried this code:

<code>

I saw this happen:

<output>

I expected to see this happen:

Version

rustc 1.79.0 (129f3b996 2024-06-10)
binary: rustc
commit-hash: 129f3b9964af4d4a709d1383930ade12dfe7c081
commit-date: 2024-06-10
host: aarch64-apple-darwin
release: 1.79.0
LLVM version: 18.1.7

Additional Labels

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't have

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions