]> git.lizzy.rs Git - rust.git/commitdiff
From<Alignment> for usize & NonZeroUsize
authorScott McMurray <scottmcm@users.noreply.github.com>
Sun, 9 Oct 2022 22:12:43 +0000 (15:12 -0700)
committerScott McMurray <scottmcm@users.noreply.github.com>
Sun, 9 Oct 2022 22:44:49 +0000 (15:44 -0700)
library/core/src/ptr/alignment.rs
src/test/ui/try-trait/bad-interconversion.stderr

index bdebf8baabe489c2ba834e11b7ca874c3eac4871..56c5e6cb72462b9d586ba741228ae779a2d248a7 100644 (file)
@@ -146,6 +146,22 @@ fn try_from(align: usize) -> Result<Alignment, Self::Error> {
     }
 }
 
+#[unstable(feature = "ptr_alignment_type", issue = "102070")]
+impl From<Alignment> for NonZeroUsize {
+    #[inline]
+    fn from(align: Alignment) -> NonZeroUsize {
+        align.as_nonzero()
+    }
+}
+
+#[unstable(feature = "ptr_alignment_type", issue = "102070")]
+impl From<Alignment> for usize {
+    #[inline]
+    fn from(align: Alignment) -> usize {
+        align.as_usize()
+    }
+}
+
 #[unstable(feature = "ptr_alignment_type", issue = "102070")]
 impl cmp::Ord for Alignment {
     #[inline]
index 27e6a603acd91689accbfe1fbe4b6e19139170e3..419a86bf33bb4444b2c3582efc8c1247a86f33d9 100644 (file)
@@ -16,7 +16,7 @@ LL |     Ok(Err(123_i32)?)
              <f64 as From<i16>>
              <f64 as From<i32>>
              <f64 as From<i8>>
-           and 67 others
+           and 68 others
    = note: required for `Result<u64, u8>` to implement `FromResidual<Result<Infallible, i32>>`
 
 error[E0277]: the `?` operator can only be used on `Result`s, not `Option`s, in a function that returns `Result`