rust-lang / rust-lang/rust-clippy

Use `NonZero<T>` instead of `NonZeroT`

Open
#13,019 4 comments 4 reactions 1 assignee View on GitHub

@TennyZhuang is already working on this.

Since Jul 3, 2024.

A-lint
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.