about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--clippy_lints/src/transmute/eager_transmute.rs2
-rw-r--r--clippy_lints/src/transmute/mod.rs10
-rw-r--r--clippy_lints/src/transmute/transmute_int_to_non_zero.rs35
-rw-r--r--lintcheck/src/config.rs4
-rw-r--r--tests/ui/arithmetic_side_effects.rs8
-rw-r--r--tests/ui/eager_transmute.fixed20
-rw-r--r--tests/ui/eager_transmute.rs20
-rw-r--r--tests/ui/eager_transmute.stderr18
-rw-r--r--tests/ui/transmute_int_to_non_zero.fixed62
-rw-r--r--tests/ui/transmute_int_to_non_zero.rs62
-rw-r--r--tests/ui/transmute_int_to_non_zero.stderr80
11 files changed, 149 insertions, 172 deletions
diff --git a/clippy_lints/src/transmute/eager_transmute.rs b/clippy_lints/src/transmute/eager_transmute.rs
index c44f5150dd1..1dfc9f7091e 100644
--- a/clippy_lints/src/transmute/eager_transmute.rs
+++ b/clippy_lints/src/transmute/eager_transmute.rs
@@ -87,7 +87,7 @@ pub(super) fn check<'tcx>(
         && is_normalizable(cx, cx.param_env, from_ty)
         && is_normalizable(cx, cx.param_env, to_ty)
         // we only want to lint if the target type has a niche that is larger than the one of the source type
-        // e.g. `u8` to `NonZeroU8` should lint, but `NonZeroU8` to `u8` should not
+        // e.g. `u8` to `NonZero<u8>` should lint, but `NonZero<u8>` to `u8` should not
         && let Ok(from_layout) = cx.tcx.layout_of(cx.param_env.and(from_ty))
         && let Ok(to_layout) = cx.tcx.layout_of(cx.param_env.and(to_ty))
         && match (from_layout.largest_niche, to_layout.largest_niche) {
diff --git a/clippy_lints/src/transmute/mod.rs b/clippy_lints/src/transmute/mod.rs
index 7fa536a1a29..598032ccdeb 100644
--- a/clippy_lints/src/transmute/mod.rs
+++ b/clippy_lints/src/transmute/mod.rs
@@ -257,7 +257,7 @@ declare_clippy_lint! {
 
 declare_clippy_lint! {
     /// ### What it does
-    /// Checks for transmutes from integers to `NonZero*` types, and suggests their `new_unchecked`
+    /// Checks for transmutes from `T` to `NonZero<T>`, and suggests the `new_unchecked`
     /// method instead.
     ///
     /// ### Why is this bad?
@@ -266,13 +266,13 @@ declare_clippy_lint! {
     ///
     /// ### Example
     /// ```no_run
-    /// # use core::num::NonZeroU32;
-    /// let _non_zero: NonZeroU32 = unsafe { std::mem::transmute(123) };
+    /// # use core::num::NonZero;
+    /// let _: NonZero<u32> = unsafe { std::mem::transmute(123) };
     /// ```
     /// Use instead:
     /// ```no_run
-    /// # use core::num::NonZeroU32;
-    /// let _non_zero = unsafe { NonZeroU32::new_unchecked(123) };
+    /// # use core::num::NonZero;
+    /// let _: NonZero<u32> = unsafe { NonZero::new_unchecked(123) };
     /// ```
     #[clippy::version = "1.69.0"]
     pub TRANSMUTE_INT_TO_NON_ZERO,
diff --git a/clippy_lints/src/transmute/transmute_int_to_non_zero.rs b/clippy_lints/src/transmute/transmute_int_to_non_zero.rs
index 2bea3be3d60..7d824ef2139 100644
--- a/clippy_lints/src/transmute/transmute_int_to_non_zero.rs
+++ b/clippy_lints/src/transmute/transmute_int_to_non_zero.rs
@@ -26,45 +26,22 @@ pub(super) fn check<'tcx>(
         return false;
     };
 
-    // FIXME: This can be simplified once `NonZero<T>` is stable.
-    let coercible_types = [
-        ("NonZeroU8", tcx.types.u8),
-        ("NonZeroU16", tcx.types.u16),
-        ("NonZeroU32", tcx.types.u32),
-        ("NonZeroU64", tcx.types.u64),
-        ("NonZeroU128", tcx.types.u128),
-        ("NonZeroUsize", tcx.types.usize),
-        ("NonZeroI8", tcx.types.i8),
-        ("NonZeroI16", tcx.types.i16),
-        ("NonZeroI32", tcx.types.i32),
-        ("NonZeroI64", tcx.types.i64),
-        ("NonZeroI128", tcx.types.i128),
-        ("NonZeroIsize", tcx.types.isize),
-    ];
-
-    let int_type = substs.type_at(0);
-
-    let Some(nonzero_alias) = coercible_types.iter().find_map(|(nonzero_alias, t)| {
-        if *t == int_type && *t == from_ty {
-            Some(nonzero_alias)
-        } else {
-            None
-        }
-    }) else {
-        return false;
-    };
+    let int_ty = substs.type_at(0);
+    if from_ty != int_ty {
+      return false;
+    }
 
     span_lint_and_then(
         cx,
         TRANSMUTE_INT_TO_NON_ZERO,
         e.span,
-        format!("transmute from a `{from_ty}` to a `{nonzero_alias}`"),
+        format!("transmute from a `{from_ty}` to a `{}<{int_ty}>`", sym::NonZero),
         |diag| {
             let arg = sugg::Sugg::hir(cx, arg, "..");
             diag.span_suggestion(
                 e.span,
                 "consider using",
-                format!("{nonzero_alias}::{}({arg})", sym::new_unchecked),
+                format!("{}::{}({arg})", sym::NonZero, sym::new_unchecked),
                 Applicability::Unspecified,
             );
         },
diff --git a/lintcheck/src/config.rs b/lintcheck/src/config.rs
index e678d40795e..3f712f453fa 100644
--- a/lintcheck/src/config.rs
+++ b/lintcheck/src/config.rs
@@ -1,5 +1,5 @@
 use clap::Parser;
-use std::num::NonZeroUsize;
+use std::num::NonZero;
 use std::path::PathBuf;
 
 #[derive(Clone, Debug, Parser)]
@@ -61,7 +61,7 @@ impl LintcheckConfig {
             config.max_jobs = if config.fix || config.recursive {
                 1
             } else {
-                std::thread::available_parallelism().map_or(1, NonZeroUsize::get)
+                std::thread::available_parallelism().map_or(1, NonZero::get)
             };
         };
 
diff --git a/tests/ui/arithmetic_side_effects.rs b/tests/ui/arithmetic_side_effects.rs
index 66d71f337f2..33a91e8bbbe 100644
--- a/tests/ui/arithmetic_side_effects.rs
+++ b/tests/ui/arithmetic_side_effects.rs
@@ -15,7 +15,7 @@
 
 extern crate proc_macro_derive;
 
-use core::num::{NonZeroUsize, Saturating, Wrapping};
+use core::num::{NonZero, Saturating, Wrapping};
 
 const ONE: i32 = 1;
 const ZERO: i32 = 0;
@@ -494,15 +494,15 @@ pub fn issue_11262() {
 }
 
 pub fn issue_11392() {
-    fn example_div(unsigned: usize, nonzero_unsigned: NonZeroUsize) -> usize {
+    fn example_div(unsigned: usize, nonzero_unsigned: NonZero<usize>) -> usize {
         unsigned / nonzero_unsigned
     }
 
-    fn example_rem(unsigned: usize, nonzero_unsigned: NonZeroUsize) -> usize {
+    fn example_rem(unsigned: usize, nonzero_unsigned: NonZero<usize>) -> usize {
         unsigned % nonzero_unsigned
     }
 
-    let (unsigned, nonzero_unsigned) = (0, NonZeroUsize::new(1).unwrap());
+    let (unsigned, nonzero_unsigned) = (0, NonZero::new(1).unwrap());
     example_div(unsigned, nonzero_unsigned);
     example_rem(unsigned, nonzero_unsigned);
 }
diff --git a/tests/ui/eager_transmute.fixed b/tests/ui/eager_transmute.fixed
index c29e7dd9ab3..ba4342462dc 100644
--- a/tests/ui/eager_transmute.fixed
+++ b/tests/ui/eager_transmute.fixed
@@ -2,7 +2,7 @@
 #![warn(clippy::eager_transmute)]
 #![allow(clippy::transmute_int_to_non_zero, clippy::missing_transmute_annotations)]
 
-use std::num::NonZeroU8;
+use std::num::NonZero;
 
 #[repr(u8)]
 enum Opcode {
@@ -85,21 +85,21 @@ macro_rules! impls {
 }
 impls!(NonMaxU8, NonZeroNonMaxU8);
 
-fn niche_tests(v1: u8, v2: NonZeroU8, v3: NonZeroNonMaxU8) {
-    // u8 -> NonZeroU8, do lint
-    let _: Option<NonZeroU8> = (v1 > 0).then(|| unsafe { std::mem::transmute(v1) });
+fn niche_tests(v1: u8, v2: NonZero<u8>, v3: NonZeroNonMaxU8) {
+    // u8 -> NonZero<u8>, do lint
+    let _: Option<NonZero<u8>> = (v1 > 0).then(|| unsafe { std::mem::transmute(v1) });
 
-    // NonZeroU8 -> u8, don't lint, target type has no niche and therefore a higher validity range
-    let _: Option<u8> = (v2 > NonZeroU8::new(1).unwrap()).then_some(unsafe { std::mem::transmute(v2) });
+    // NonZero<u8> -> u8, don't lint, target type has no niche and therefore a higher validity range
+    let _: Option<u8> = (v2 > NonZero::new(1u8).unwrap()).then_some(unsafe { std::mem::transmute(v2) });
 
-    // NonZeroU8 -> NonMaxU8, do lint, different niche
-    let _: Option<NonMaxU8> = (v2 < NonZeroU8::new(255).unwrap()).then(|| unsafe { std::mem::transmute(v2) });
+    // NonZero<u8> -> NonMaxU8, do lint, different niche
+    let _: Option<NonMaxU8> = (v2 < NonZero::new(255u8).unwrap()).then(|| unsafe { std::mem::transmute(v2) });
 
     // NonZeroNonMaxU8 -> NonMaxU8, don't lint, target type has more validity
     let _: Option<NonMaxU8> = (v3 < 255).then_some(unsafe { std::mem::transmute(v2) });
 
-    // NonZeroU8 -> NonZeroNonMaxU8, do lint, target type has less validity
-    let _: Option<NonZeroNonMaxU8> = (v2 < NonZeroU8::new(255).unwrap()).then(|| unsafe { std::mem::transmute(v2) });
+    // NonZero<u8> -> NonZeroNonMaxU8, do lint, target type has less validity
+    let _: Option<NonZeroNonMaxU8> = (v2 < NonZero::new(255u8).unwrap()).then(|| unsafe { std::mem::transmute(v2) });
 }
 
 fn main() {}
diff --git a/tests/ui/eager_transmute.rs b/tests/ui/eager_transmute.rs
index 491a9485c93..9750e87ce57 100644
--- a/tests/ui/eager_transmute.rs
+++ b/tests/ui/eager_transmute.rs
@@ -2,7 +2,7 @@
 #![warn(clippy::eager_transmute)]
 #![allow(clippy::transmute_int_to_non_zero, clippy::missing_transmute_annotations)]
 
-use std::num::NonZeroU8;
+use std::num::NonZero;
 
 #[repr(u8)]
 enum Opcode {
@@ -85,21 +85,21 @@ macro_rules! impls {
 }
 impls!(NonMaxU8, NonZeroNonMaxU8);
 
-fn niche_tests(v1: u8, v2: NonZeroU8, v3: NonZeroNonMaxU8) {
-    // u8 -> NonZeroU8, do lint
-    let _: Option<NonZeroU8> = (v1 > 0).then_some(unsafe { std::mem::transmute(v1) });
+fn niche_tests(v1: u8, v2: NonZero<u8>, v3: NonZeroNonMaxU8) {
+    // u8 -> NonZero<u8>, do lint
+    let _: Option<NonZero<u8>> = (v1 > 0).then_some(unsafe { std::mem::transmute(v1) });
 
-    // NonZeroU8 -> u8, don't lint, target type has no niche and therefore a higher validity range
-    let _: Option<u8> = (v2 > NonZeroU8::new(1).unwrap()).then_some(unsafe { std::mem::transmute(v2) });
+    // NonZero<u8> -> u8, don't lint, target type has no niche and therefore a higher validity range
+    let _: Option<u8> = (v2 > NonZero::new(1u8).unwrap()).then_some(unsafe { std::mem::transmute(v2) });
 
-    // NonZeroU8 -> NonMaxU8, do lint, different niche
-    let _: Option<NonMaxU8> = (v2 < NonZeroU8::new(255).unwrap()).then_some(unsafe { std::mem::transmute(v2) });
+    // NonZero<u8> -> NonMaxU8, do lint, different niche
+    let _: Option<NonMaxU8> = (v2 < NonZero::new(255u8).unwrap()).then_some(unsafe { std::mem::transmute(v2) });
 
     // NonZeroNonMaxU8 -> NonMaxU8, don't lint, target type has more validity
     let _: Option<NonMaxU8> = (v3 < 255).then_some(unsafe { std::mem::transmute(v2) });
 
-    // NonZeroU8 -> NonZeroNonMaxU8, do lint, target type has less validity
-    let _: Option<NonZeroNonMaxU8> = (v2 < NonZeroU8::new(255).unwrap()).then_some(unsafe { std::mem::transmute(v2) });
+    // NonZero<u8> -> NonZeroNonMaxU8, do lint, target type has less validity
+    let _: Option<NonZeroNonMaxU8> = (v2 < NonZero::new(255u8).unwrap()).then_some(unsafe { std::mem::transmute(v2) });
 }
 
 fn main() {}
diff --git a/tests/ui/eager_transmute.stderr b/tests/ui/eager_transmute.stderr
index b9a4321d99e..5cf7bd49a92 100644
--- a/tests/ui/eager_transmute.stderr
+++ b/tests/ui/eager_transmute.stderr
@@ -155,36 +155,36 @@ LL |     (op < 4).then(|| std::mem::transmute::<_, Opcode>(op));
    |              ~~~~ ++
 
 error: this transmute is always evaluated eagerly, even if the condition is false
-  --> tests/ui/eager_transmute.rs:90:60
+  --> tests/ui/eager_transmute.rs:90:62
    |
-LL |     let _: Option<NonZeroU8> = (v1 > 0).then_some(unsafe { std::mem::transmute(v1) });
-   |                                                            ^^^^^^^^^^^^^^^^^^^^^^^
+LL |     let _: Option<NonZero<u8>> = (v1 > 0).then_some(unsafe { std::mem::transmute(v1) });
+   |                                                              ^^^^^^^^^^^^^^^^^^^^^^^
    |
 help: consider using `bool::then` to only transmute if the condition holds
    |
-LL |     let _: Option<NonZeroU8> = (v1 > 0).then(|| unsafe { std::mem::transmute(v1) });
-   |                                         ~~~~ ++
+LL |     let _: Option<NonZero<u8>> = (v1 > 0).then(|| unsafe { std::mem::transmute(v1) });
+   |                                           ~~~~ ++
 
 error: this transmute is always evaluated eagerly, even if the condition is false
   --> tests/ui/eager_transmute.rs:96:86
    |
-LL |     let _: Option<NonMaxU8> = (v2 < NonZeroU8::new(255).unwrap()).then_some(unsafe { std::mem::transmute(v2) });
+LL |     let _: Option<NonMaxU8> = (v2 < NonZero::new(255u8).unwrap()).then_some(unsafe { std::mem::transmute(v2) });
    |                                                                                      ^^^^^^^^^^^^^^^^^^^^^^^
    |
 help: consider using `bool::then` to only transmute if the condition holds
    |
-LL |     let _: Option<NonMaxU8> = (v2 < NonZeroU8::new(255).unwrap()).then(|| unsafe { std::mem::transmute(v2) });
+LL |     let _: Option<NonMaxU8> = (v2 < NonZero::new(255u8).unwrap()).then(|| unsafe { std::mem::transmute(v2) });
    |                                                                   ~~~~ ++
 
 error: this transmute is always evaluated eagerly, even if the condition is false
   --> tests/ui/eager_transmute.rs:102:93
    |
-LL |     let _: Option<NonZeroNonMaxU8> = (v2 < NonZeroU8::new(255).unwrap()).then_some(unsafe { std::mem::transmute(v2) });
+LL |     let _: Option<NonZeroNonMaxU8> = (v2 < NonZero::new(255u8).unwrap()).then_some(unsafe { std::mem::transmute(v2) });
    |                                                                                             ^^^^^^^^^^^^^^^^^^^^^^^
    |
 help: consider using `bool::then` to only transmute if the condition holds
    |
-LL |     let _: Option<NonZeroNonMaxU8> = (v2 < NonZeroU8::new(255).unwrap()).then(|| unsafe { std::mem::transmute(v2) });
+LL |     let _: Option<NonZeroNonMaxU8> = (v2 < NonZero::new(255u8).unwrap()).then(|| unsafe { std::mem::transmute(v2) });
    |                                                                          ~~~~ ++
 
 error: aborting due to 17 previous errors
diff --git a/tests/ui/transmute_int_to_non_zero.fixed b/tests/ui/transmute_int_to_non_zero.fixed
index fe8db3dcb0c..1a48051ec8c 100644
--- a/tests/ui/transmute_int_to_non_zero.fixed
+++ b/tests/ui/transmute_int_to_non_zero.fixed
@@ -1,7 +1,7 @@
 #![warn(clippy::transmute_int_to_non_zero)]
 #![allow(clippy::missing_transmute_annotations)]
 
-use core::num::*;
+use core::num::NonZero;
 
 fn main() {
     let int_u8: u8 = 1;
@@ -16,38 +16,38 @@ fn main() {
     let int_i64: i64 = 1;
     let int_i128: i128 = 1;
 
-    let _: NonZeroU8 = unsafe { NonZeroU8::new_unchecked(int_u8) };
-    //~^ ERROR: transmute from a `u8` to a `NonZeroU8`
+    let _: NonZero<u8> = unsafe { NonZero::new_unchecked(int_u8) };
+    //~^ ERROR: transmute from a `u8` to a `NonZero<u8>`
     //~| NOTE: `-D clippy::transmute-int-to-non-zero` implied by `-D warnings`
-    let _: NonZeroU16 = unsafe { NonZeroU16::new_unchecked(int_u16) };
-    //~^ ERROR: transmute from a `u16` to a `NonZeroU16`
-    let _: NonZeroU32 = unsafe { NonZeroU32::new_unchecked(int_u32) };
-    //~^ ERROR: transmute from a `u32` to a `NonZeroU32`
-    let _: NonZeroU64 = unsafe { NonZeroU64::new_unchecked(int_u64) };
-    //~^ ERROR: transmute from a `u64` to a `NonZeroU64`
-    let _: NonZeroU128 = unsafe { NonZeroU128::new_unchecked(int_u128) };
-    //~^ ERROR: transmute from a `u128` to a `NonZeroU128`
+    let _: NonZero<u16> = unsafe { NonZero::new_unchecked(int_u16) };
+    //~^ ERROR: transmute from a `u16` to a `NonZero<u16>`
+    let _: NonZero<u32> = unsafe { NonZero::new_unchecked(int_u32) };
+    //~^ ERROR: transmute from a `u32` to a `NonZero<u32>`
+    let _: NonZero<u64> = unsafe { NonZero::new_unchecked(int_u64) };
+    //~^ ERROR: transmute from a `u64` to a `NonZero<u64>`
+    let _: NonZero<u128> = unsafe { NonZero::new_unchecked(int_u128) };
+    //~^ ERROR: transmute from a `u128` to a `NonZero<u128>`
 
-    let _: NonZeroI8 = unsafe { NonZeroI8::new_unchecked(int_i8) };
-    //~^ ERROR: transmute from a `i8` to a `NonZeroI8`
-    let _: NonZeroI16 = unsafe { NonZeroI16::new_unchecked(int_i16) };
-    //~^ ERROR: transmute from a `i16` to a `NonZeroI16`
-    let _: NonZeroI32 = unsafe { NonZeroI32::new_unchecked(int_i32) };
-    //~^ ERROR: transmute from a `i32` to a `NonZeroI32`
-    let _: NonZeroI64 = unsafe { NonZeroI64::new_unchecked(int_i64) };
-    //~^ ERROR: transmute from a `i64` to a `NonZeroI64`
-    let _: NonZeroI128 = unsafe { NonZeroI128::new_unchecked(int_i128) };
-    //~^ ERROR: transmute from a `i128` to a `NonZeroI128`
+    let _: NonZero<i8> = unsafe { NonZero::new_unchecked(int_i8) };
+    //~^ ERROR: transmute from a `i8` to a `NonZero<i8>`
+    let _: NonZero<i16> = unsafe { NonZero::new_unchecked(int_i16) };
+    //~^ ERROR: transmute from a `i16` to a `NonZero<i16>`
+    let _: NonZero<i32> = unsafe { NonZero::new_unchecked(int_i32) };
+    //~^ ERROR: transmute from a `i32` to a `NonZero<i32>`
+    let _: NonZero<i64> = unsafe { NonZero::new_unchecked(int_i64) };
+    //~^ ERROR: transmute from a `i64` to a `NonZero<i64>`
+    let _: NonZero<i128> = unsafe { NonZero::new_unchecked(int_i128) };
+    //~^ ERROR: transmute from a `i128` to a `NonZero<i128>`
 
-    let _: NonZeroU8 = unsafe { NonZeroU8::new_unchecked(int_u8) };
-    let _: NonZeroU16 = unsafe { NonZeroU16::new_unchecked(int_u16) };
-    let _: NonZeroU32 = unsafe { NonZeroU32::new_unchecked(int_u32) };
-    let _: NonZeroU64 = unsafe { NonZeroU64::new_unchecked(int_u64) };
-    let _: NonZeroU128 = unsafe { NonZeroU128::new_unchecked(int_u128) };
+    let _: NonZero<u8> = unsafe { NonZero::new_unchecked(int_u8) };
+    let _: NonZero<u16> = unsafe { NonZero::new_unchecked(int_u16) };
+    let _: NonZero<u32> = unsafe { NonZero::new_unchecked(int_u32) };
+    let _: NonZero<u64> = unsafe { NonZero::new_unchecked(int_u64) };
+    let _: NonZero<u128> = unsafe { NonZero::new_unchecked(int_u128) };
 
-    let _: NonZeroI8 = unsafe { NonZeroI8::new_unchecked(int_i8) };
-    let _: NonZeroI16 = unsafe { NonZeroI16::new_unchecked(int_i16) };
-    let _: NonZeroI32 = unsafe { NonZeroI32::new_unchecked(int_i32) };
-    let _: NonZeroI64 = unsafe { NonZeroI64::new_unchecked(int_i64) };
-    let _: NonZeroI128 = unsafe { NonZeroI128::new_unchecked(int_i128) };
+    let _: NonZero<i8> = unsafe { NonZero::new_unchecked(int_i8) };
+    let _: NonZero<i16> = unsafe { NonZero::new_unchecked(int_i16) };
+    let _: NonZero<i32> = unsafe { NonZero::new_unchecked(int_i32) };
+    let _: NonZero<i64> = unsafe { NonZero::new_unchecked(int_i64) };
+    let _: NonZero<i128> = unsafe { NonZero::new_unchecked(int_i128) };
 }
diff --git a/tests/ui/transmute_int_to_non_zero.rs b/tests/ui/transmute_int_to_non_zero.rs
index a79ed5279b1..d8e842fb99c 100644
--- a/tests/ui/transmute_int_to_non_zero.rs
+++ b/tests/ui/transmute_int_to_non_zero.rs
@@ -1,7 +1,7 @@
 #![warn(clippy::transmute_int_to_non_zero)]
 #![allow(clippy::missing_transmute_annotations)]
 
-use core::num::*;
+use core::num::NonZero;
 
 fn main() {
     let int_u8: u8 = 1;
@@ -16,38 +16,38 @@ fn main() {
     let int_i64: i64 = 1;
     let int_i128: i128 = 1;
 
-    let _: NonZeroU8 = unsafe { std::mem::transmute(int_u8) };
-    //~^ ERROR: transmute from a `u8` to a `NonZeroU8`
+    let _: NonZero<u8> = unsafe { std::mem::transmute(int_u8) };
+    //~^ ERROR: transmute from a `u8` to a `NonZero<u8>`
     //~| NOTE: `-D clippy::transmute-int-to-non-zero` implied by `-D warnings`
-    let _: NonZeroU16 = unsafe { std::mem::transmute(int_u16) };
-    //~^ ERROR: transmute from a `u16` to a `NonZeroU16`
-    let _: NonZeroU32 = unsafe { std::mem::transmute(int_u32) };
-    //~^ ERROR: transmute from a `u32` to a `NonZeroU32`
-    let _: NonZeroU64 = unsafe { std::mem::transmute(int_u64) };
-    //~^ ERROR: transmute from a `u64` to a `NonZeroU64`
-    let _: NonZeroU128 = unsafe { std::mem::transmute(int_u128) };
-    //~^ ERROR: transmute from a `u128` to a `NonZeroU128`
+    let _: NonZero<u16> = unsafe { std::mem::transmute(int_u16) };
+    //~^ ERROR: transmute from a `u16` to a `NonZero<u16>`
+    let _: NonZero<u32> = unsafe { std::mem::transmute(int_u32) };
+    //~^ ERROR: transmute from a `u32` to a `NonZero<u32>`
+    let _: NonZero<u64> = unsafe { std::mem::transmute(int_u64) };
+    //~^ ERROR: transmute from a `u64` to a `NonZero<u64>`
+    let _: NonZero<u128> = unsafe { std::mem::transmute(int_u128) };
+    //~^ ERROR: transmute from a `u128` to a `NonZero<u128>`
 
-    let _: NonZeroI8 = unsafe { std::mem::transmute(int_i8) };
-    //~^ ERROR: transmute from a `i8` to a `NonZeroI8`
-    let _: NonZeroI16 = unsafe { std::mem::transmute(int_i16) };
-    //~^ ERROR: transmute from a `i16` to a `NonZeroI16`
-    let _: NonZeroI32 = unsafe { std::mem::transmute(int_i32) };
-    //~^ ERROR: transmute from a `i32` to a `NonZeroI32`
-    let _: NonZeroI64 = unsafe { std::mem::transmute(int_i64) };
-    //~^ ERROR: transmute from a `i64` to a `NonZeroI64`
-    let _: NonZeroI128 = unsafe { std::mem::transmute(int_i128) };
-    //~^ ERROR: transmute from a `i128` to a `NonZeroI128`
+    let _: NonZero<i8> = unsafe { std::mem::transmute(int_i8) };
+    //~^ ERROR: transmute from a `i8` to a `NonZero<i8>`
+    let _: NonZero<i16> = unsafe { std::mem::transmute(int_i16) };
+    //~^ ERROR: transmute from a `i16` to a `NonZero<i16>`
+    let _: NonZero<i32> = unsafe { std::mem::transmute(int_i32) };
+    //~^ ERROR: transmute from a `i32` to a `NonZero<i32>`
+    let _: NonZero<i64> = unsafe { std::mem::transmute(int_i64) };
+    //~^ ERROR: transmute from a `i64` to a `NonZero<i64>`
+    let _: NonZero<i128> = unsafe { std::mem::transmute(int_i128) };
+    //~^ ERROR: transmute from a `i128` to a `NonZero<i128>`
 
-    let _: NonZeroU8 = unsafe { NonZeroU8::new_unchecked(int_u8) };
-    let _: NonZeroU16 = unsafe { NonZeroU16::new_unchecked(int_u16) };
-    let _: NonZeroU32 = unsafe { NonZeroU32::new_unchecked(int_u32) };
-    let _: NonZeroU64 = unsafe { NonZeroU64::new_unchecked(int_u64) };
-    let _: NonZeroU128 = unsafe { NonZeroU128::new_unchecked(int_u128) };
+    let _: NonZero<u8> = unsafe { NonZero::new_unchecked(int_u8) };
+    let _: NonZero<u16> = unsafe { NonZero::new_unchecked(int_u16) };
+    let _: NonZero<u32> = unsafe { NonZero::new_unchecked(int_u32) };
+    let _: NonZero<u64> = unsafe { NonZero::new_unchecked(int_u64) };
+    let _: NonZero<u128> = unsafe { NonZero::new_unchecked(int_u128) };
 
-    let _: NonZeroI8 = unsafe { NonZeroI8::new_unchecked(int_i8) };
-    let _: NonZeroI16 = unsafe { NonZeroI16::new_unchecked(int_i16) };
-    let _: NonZeroI32 = unsafe { NonZeroI32::new_unchecked(int_i32) };
-    let _: NonZeroI64 = unsafe { NonZeroI64::new_unchecked(int_i64) };
-    let _: NonZeroI128 = unsafe { NonZeroI128::new_unchecked(int_i128) };
+    let _: NonZero<i8> = unsafe { NonZero::new_unchecked(int_i8) };
+    let _: NonZero<i16> = unsafe { NonZero::new_unchecked(int_i16) };
+    let _: NonZero<i32> = unsafe { NonZero::new_unchecked(int_i32) };
+    let _: NonZero<i64> = unsafe { NonZero::new_unchecked(int_i64) };
+    let _: NonZero<i128> = unsafe { NonZero::new_unchecked(int_i128) };
 }
diff --git a/tests/ui/transmute_int_to_non_zero.stderr b/tests/ui/transmute_int_to_non_zero.stderr
index bb0b0d0ff4f..199b8ec59d0 100644
--- a/tests/ui/transmute_int_to_non_zero.stderr
+++ b/tests/ui/transmute_int_to_non_zero.stderr
@@ -1,65 +1,65 @@
-error: transmute from a `u8` to a `NonZeroU8`
-  --> tests/ui/transmute_int_to_non_zero.rs:19:33
+error: transmute from a `u8` to a `NonZero<u8>`
+  --> tests/ui/transmute_int_to_non_zero.rs:19:35
    |
-LL |     let _: NonZeroU8 = unsafe { std::mem::transmute(int_u8) };
-   |                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZeroU8::new_unchecked(int_u8)`
+LL |     let _: NonZero<u8> = unsafe { std::mem::transmute(int_u8) };
+   |                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZero::new_unchecked(int_u8)`
    |
    = note: `-D clippy::transmute-int-to-non-zero` implied by `-D warnings`
    = help: to override `-D warnings` add `#[allow(clippy::transmute_int_to_non_zero)]`
 
-error: transmute from a `u16` to a `NonZeroU16`
-  --> tests/ui/transmute_int_to_non_zero.rs:22:34
+error: transmute from a `u16` to a `NonZero<u16>`
+  --> tests/ui/transmute_int_to_non_zero.rs:22:36
    |
-LL |     let _: NonZeroU16 = unsafe { std::mem::transmute(int_u16) };
-   |                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZeroU16::new_unchecked(int_u16)`
+LL |     let _: NonZero<u16> = unsafe { std::mem::transmute(int_u16) };
+   |                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZero::new_unchecked(int_u16)`
 
-error: transmute from a `u32` to a `NonZeroU32`
-  --> tests/ui/transmute_int_to_non_zero.rs:24:34
+error: transmute from a `u32` to a `NonZero<u32>`
+  --> tests/ui/transmute_int_to_non_zero.rs:24:36
    |
-LL |     let _: NonZeroU32 = unsafe { std::mem::transmute(int_u32) };
-   |                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZeroU32::new_unchecked(int_u32)`
+LL |     let _: NonZero<u32> = unsafe { std::mem::transmute(int_u32) };
+   |                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZero::new_unchecked(int_u32)`
 
-error: transmute from a `u64` to a `NonZeroU64`
-  --> tests/ui/transmute_int_to_non_zero.rs:26:34
+error: transmute from a `u64` to a `NonZero<u64>`
+  --> tests/ui/transmute_int_to_non_zero.rs:26:36
    |
-LL |     let _: NonZeroU64 = unsafe { std::mem::transmute(int_u64) };
-   |                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZeroU64::new_unchecked(int_u64)`
+LL |     let _: NonZero<u64> = unsafe { std::mem::transmute(int_u64) };
+   |                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZero::new_unchecked(int_u64)`
 
-error: transmute from a `u128` to a `NonZeroU128`
-  --> tests/ui/transmute_int_to_non_zero.rs:28:35
+error: transmute from a `u128` to a `NonZero<u128>`
+  --> tests/ui/transmute_int_to_non_zero.rs:28:37
    |
-LL |     let _: NonZeroU128 = unsafe { std::mem::transmute(int_u128) };
-   |                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZeroU128::new_unchecked(int_u128)`
+LL |     let _: NonZero<u128> = unsafe { std::mem::transmute(int_u128) };
+   |                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZero::new_unchecked(int_u128)`
 
-error: transmute from a `i8` to a `NonZeroI8`
-  --> tests/ui/transmute_int_to_non_zero.rs:31:33
+error: transmute from a `i8` to a `NonZero<i8>`
+  --> tests/ui/transmute_int_to_non_zero.rs:31:35
    |
-LL |     let _: NonZeroI8 = unsafe { std::mem::transmute(int_i8) };
-   |                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZeroI8::new_unchecked(int_i8)`
+LL |     let _: NonZero<i8> = unsafe { std::mem::transmute(int_i8) };
+   |                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZero::new_unchecked(int_i8)`
 
-error: transmute from a `i16` to a `NonZeroI16`
-  --> tests/ui/transmute_int_to_non_zero.rs:33:34
+error: transmute from a `i16` to a `NonZero<i16>`
+  --> tests/ui/transmute_int_to_non_zero.rs:33:36
    |
-LL |     let _: NonZeroI16 = unsafe { std::mem::transmute(int_i16) };
-   |                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZeroI16::new_unchecked(int_i16)`
+LL |     let _: NonZero<i16> = unsafe { std::mem::transmute(int_i16) };
+   |                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZero::new_unchecked(int_i16)`
 
-error: transmute from a `i32` to a `NonZeroI32`
-  --> tests/ui/transmute_int_to_non_zero.rs:35:34
+error: transmute from a `i32` to a `NonZero<i32>`
+  --> tests/ui/transmute_int_to_non_zero.rs:35:36
    |
-LL |     let _: NonZeroI32 = unsafe { std::mem::transmute(int_i32) };
-   |                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZeroI32::new_unchecked(int_i32)`
+LL |     let _: NonZero<i32> = unsafe { std::mem::transmute(int_i32) };
+   |                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZero::new_unchecked(int_i32)`
 
-error: transmute from a `i64` to a `NonZeroI64`
-  --> tests/ui/transmute_int_to_non_zero.rs:37:34
+error: transmute from a `i64` to a `NonZero<i64>`
+  --> tests/ui/transmute_int_to_non_zero.rs:37:36
    |
-LL |     let _: NonZeroI64 = unsafe { std::mem::transmute(int_i64) };
-   |                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZeroI64::new_unchecked(int_i64)`
+LL |     let _: NonZero<i64> = unsafe { std::mem::transmute(int_i64) };
+   |                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZero::new_unchecked(int_i64)`
 
-error: transmute from a `i128` to a `NonZeroI128`
-  --> tests/ui/transmute_int_to_non_zero.rs:39:35
+error: transmute from a `i128` to a `NonZero<i128>`
+  --> tests/ui/transmute_int_to_non_zero.rs:39:37
    |
-LL |     let _: NonZeroI128 = unsafe { std::mem::transmute(int_i128) };
-   |                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZeroI128::new_unchecked(int_i128)`
+LL |     let _: NonZero<i128> = unsafe { std::mem::transmute(int_i128) };
+   |                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZero::new_unchecked(int_i128)`
 
 error: aborting due to 10 previous errors