Skip to content

manual_unwrap_or_default does not consider type changes and suggests wrong code #12928

@sdroege

Description

@sdroege

Summary

See code below

Lint Name

manual_unwrap_or_default

Reproducer

I tried this code:

fn main() { let x = Some((1, 2)); let y = if let Some((a, _)) = x { a } else { 0 }; println!("{y}"); }

I saw this happen:

warning: if let can be simplified with `.unwrap_or_default()` --> src/main.rs:3:13 | 3 | let y = if let Some((a, _)) = x { | _____________^ 4 | | a 5 | | } else { 6 | | 0 7 | | }; | |_____^ help: replace it with: `x.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 

I expected to see this happen: [nothing]

Version

rustc 1.79.0 (129f3b996 2024-06-10) binary: rustc commit-hash: 129f3b9964af4d4a709d1383930ade12dfe7c081 commit-date: 2024-06-10 host: x86_64-unknown-linux-gnu release: 1.79.0 LLVM version: 18.1.7 

Additional Labels

@rustbot label +I-suggestion-causes-error

Metadata

Metadata

Labels

C-bugCategory: Clippy is not doing the correct thingI-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 applied

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions