Skip to content

Use NonZero<T> instead of NonZeroT #13019

Open
@sorairolake

Description

@sorairolake

What it does

NonZero<T> stabilized with Rust 1.79.0. This allows NonZeroI32 to be written as NonZero<i32>.

Advantage

  • More readable.
  • Reduce imports.
  • Can specify aliases for primitive integer types (e.g., NonZero<c_int>).

Drawbacks

MSRV is 1.79.0.

Example

let x = NonZeroI32::new(42).unwrap();

Could be written as:

let x = NonZero::<i32>::new(42).unwrap();

Metadata

Metadata

Assignees

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