Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Suggest the usage of NonZeroU#::from where appropriate #7291

Open
leonardo-m opened this issue May 28, 2021 · 2 comments
Open

Suggest the usage of NonZeroU#::from where appropriate #7291

leonardo-m opened this issue May 28, 2021 · 2 comments
Assignees
Labels
A-lint Area: New lints good-first-issue These issues are a good way to get started with Clippy L-restriction Lint: Belongs in the restriction lint group

Comments

@leonardo-m
Copy link

leonardo-m commented May 28, 2021

I think Clippy should start suggesting the usage of NonZeroU#::from from smaller NonZeroU#, as in code like:

#![allow(unused_variables)]
use std::num::{NonZeroU32, NonZeroU64};

fn main() {
    let x: u64 = 100;
    let y = NonZeroU32::new(10).unwrap();

    // Given code:
    let r1 = x / u64::from(y.get());
    let r2 = x % u64::from(y.get());

    // Clippy should suggest:
    let r1 = x / NonZeroU64::from(y);
    let r2 = x % NonZeroU64::from(y);
}
@leonardo-m leonardo-m added the A-lint Area: New lints label May 28, 2021
@giraffate giraffate added good-first-issue These issues are a good way to get started with Clippy L-restriction Lint: Belongs in the restriction lint group labels Sep 15, 2021
@marekdownar
Copy link
Contributor

@rustbot claim

@Samarth1696
Copy link
Contributor

@rustbot claim

@rustbot rustbot assigned Samarth1696 and unassigned marekdownar Jul 22, 2024
bors added a commit that referenced this issue Sep 7, 2024
Added new `non_zero_suggestions` lint

Created lint based on the suggestions in #7291

- \[x] Followed [lint naming conventions][lint_naming]
- \[x] Added passing UI tests (including committed `.stderr` file)
- \[x] `cargo test` passes locally
- \[x] Executed `cargo dev update_lints`
- \[x] Added lint documentation
- \[x] Run `cargo dev fmt`

----

changelog: new [`non_zero_suggestions`] lint
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints good-first-issue These issues are a good way to get started with Clippy L-restriction Lint: Belongs in the restriction lint group
Projects
None yet
Development

No branches or pull requests

4 participants