rust-clippy icon indicating copy to clipboard operation
rust-clippy copied to clipboard

Unify `manual_unwrap_or_default` and `manual_unwrap_or` on the same file

Open lochetti opened this issue 2 years ago • 3 comments

Description

Basically, both manual_unwrap_or_default and manual_unwrap_or work on the same scenarios with the only difference being what they search on the else expression: if it's equivalent to a default() call, lint manual_unwrap_or_default, otherwise manual_unwrap_or.

Right now we have the situation where we might lint twice over the same code, for instance if we have

let x: Option<i32> = None;
match x {
    Some(v) => v,
    None => 0,
};

both lints could be fired.

If we change to have them at the same file, we can decide to lint just one or the other depending on the else expression and whether or not manual_unwrap_or_default is allowed (since it is more specific: a subset of manual_unwrap_or)

So, in the end, it will be something like:

  • Is the else a default and manual_unwrap_or_default is not allowed: Lint manual_unwrap_or_default
  • Otherwise (meaning that it is not a default OR it is but manual_unwrap_or_default is allowed): Lint manual_unwrap_or

Version

No response

Additional Labels

No response

lochetti avatar Jun 18 '24 15:06 lochetti

@rustbot claim

NullSpaceBoy avatar Jun 18 '24 16:06 NullSpaceBoy

@rustbot label C-enhancement

alex-semenyuk avatar Aug 29 '24 05:08 alex-semenyuk

@rustbot release-assignment

NullSpaceBoy avatar Jan 04 '25 16:01 NullSpaceBoy