Skip to content

extension to manual_saturating_arithmetic #10070

Closed
@tomtau

Description

@tomtau

What it does

Right now, the lint checks for patterns with checked_add and unwrap_or. It could perhaps be extended (or it could be a new lint which covers manual wrapping or checked arithmetic as well) to also check for other patterns that don't use checked_add. For example with unsigned integers:

let result = if a > b { a - b } else { 0 };

which could be rewritten as:

let result = a.saturating_sub(b);

Lint Name

manual_saturating_arithmetic

Category

complexity

Advantage

  • simpler code
  • more coverage over the original lint

Drawbacks

  • more complex checking

Example

let result = if a > b { a - b } else { 0 };

Could be written as:

let result = a.saturating_sub(b);

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions