Skip to content

unnecessary call to max function #11901

Closed
@FelixMaetzler

Description

@FelixMaetzler

What it does

In todays AdventOfCode i caught myself using the below example.
The max() call of an unsigned number with 0 is unnecessary.
It would be nice if clippy would say something about that.

the maximum between 0 and an unsigned number is always the number.

Please let me know if i did anything wrong.
Have a nice day.

Advantage

  • Remove of unnecessary function call
  • Reduction of Code Complexity

Drawbacks

No response

Example

let x: usize = 5;
let y: usize = 8;
let ret = 0.max(x.saturating_sub(y));

Could be written as:

let x: usize = 5;
let y: usize = 8;
let ret = x.saturating_sub(y);

Metadata

Metadata

Labels

A-lintArea: New lintsgood first issueThese issues are a good way to get started with Clippy

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions