Skip to content

Add lint IMPLICIT_SATURATING_ADD #9393

@alex-semenyuk

Description

@alex-semenyuk

What it does

Add lint similar to IMPLICIT_SATURATING_SUB, but for ADD. So it will be IMPLICIT_SATURATING_ADD

Lint Name

IMPLICIT_SATURATING_ADD

Category

pedantic

Advantage

No response

Drawbacks

No response

Example

#![warn(clippy::implicit_saturating_add)]

fn main() {
    let mut i: u32 = 3;

    if i != MAX {
        i += 1;
    }
    println!("{}", i);
}

Could be written as:

#![warn(clippy::implicit_saturating_add)]

fn main() {
    let mut i: u32 = 3;

    if i != MAX {
        i = i.saturating_add(1);
    }
    println!("{}", i);
}

Metadata

Metadata

Assignees

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