]> git.proxmox.com Git - rustc.git/blobdiff - library/core/tests/nonzero.rs
New upstream version 1.58.1+dfsg1
[rustc.git] / library / core / tests / nonzero.rs
index c2c08522d0cae13d058b3f32d94f0040d071cb9b..a0ca919a851c36c15762c45e1001263f769dffe2 100644 (file)
@@ -204,9 +204,9 @@ fn nonzero_const() {
     // test that the methods of `NonZeroX>` are usable in a const context
     // Note: only tests NonZero8
 
-    const NONZERO: NonZeroU8 = unsafe { NonZeroU8::new_unchecked(5) };
+    const NONZERO_U8: NonZeroU8 = unsafe { NonZeroU8::new_unchecked(5) };
 
-    const GET: u8 = NONZERO.get();
+    const GET: u8 = NONZERO_U8.get();
     assert_eq!(GET, 5);
 
     const ZERO: Option<NonZeroU8> = NonZeroU8::new(0);
@@ -214,6 +214,12 @@ fn nonzero_const() {
 
     const ONE: Option<NonZeroU8> = NonZeroU8::new(1);
     assert!(ONE.is_some());
+
+    const FROM_NONZERO_U8: u8 = u8::from(NONZERO_U8);
+    assert_eq!(FROM_NONZERO_U8, 5);
+
+    const NONZERO_CONVERT: NonZeroU32 = NonZeroU32::from(NONZERO_U8);
+    assert_eq!(NONZERO_CONVERT.get(), 5);
 }
 
 #[test]