Skip to content

Unify manual_unwrap_or_default and manual_unwrap_or on the same file #12956

Open

Description

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

C-enhancementCategory: Enhancement of lints, like adding more cases or adding help messages

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions