Skip to content

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

Closed
@leonardo-m

Description

@leonardo-m

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);
}

Metadata

Metadata

Assignees

Labels

A-lintArea: New lintsL-restrictionLint: Belongs in the restriction lint groupgood 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