Skip to content

Add lint IMPLICIT_SATURATING_ADD #9393

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
alex-semenyuk opened this issue Aug 29, 2022 · 2 comments · Fixed by #9549
Closed

Add lint IMPLICIT_SATURATING_ADD #9393

alex-semenyuk opened this issue Aug 29, 2022 · 2 comments · Fixed by #9549
Assignees
Labels
A-lint Area: New lints good first issue These issues are a good way to get started with Clippy

Comments

@alex-semenyuk
Copy link
Member

alex-semenyuk commented Aug 29, 2022

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);
}
@alex-semenyuk alex-semenyuk added the A-lint Area: New lints label Aug 29, 2022
@Jarcho
Copy link
Contributor

Jarcho commented Aug 30, 2022

I'm assume you mean if i !=MAX { i += 1 } to i = i.saturating_add(1).

@giraffate giraffate added the good first issue These issues are a good way to get started with Clippy label Aug 30, 2022
@roynrishingha
Copy link
Contributor

@rustbot claim

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-lint Area: New lints good first issue These issues are a good way to get started with Clippy
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants