From 0718aeceb3b739e467381d1b95a3748ed9ec6bc2 Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Sun, 9 Oct 2022 15:12:43 -0700 Subject: [PATCH] From for usize & NonZeroUsize --- library/core/src/ptr/alignment.rs | 16 ++++++++++++++++ src/test/ui/try-trait/bad-interconversion.stderr | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/library/core/src/ptr/alignment.rs b/library/core/src/ptr/alignment.rs index bdebf8baabe48..56c5e6cb72462 100644 --- a/library/core/src/ptr/alignment.rs +++ b/library/core/src/ptr/alignment.rs @@ -146,6 +146,22 @@ impl TryFrom for Alignment { } } +#[unstable(feature = "ptr_alignment_type", issue = "102070")] +impl From for NonZeroUsize { + #[inline] + fn from(align: Alignment) -> NonZeroUsize { + align.as_nonzero() + } +} + +#[unstable(feature = "ptr_alignment_type", issue = "102070")] +impl From for usize { + #[inline] + fn from(align: Alignment) -> usize { + align.as_usize() + } +} + #[unstable(feature = "ptr_alignment_type", issue = "102070")] impl cmp::Ord for Alignment { #[inline] diff --git a/src/test/ui/try-trait/bad-interconversion.stderr b/src/test/ui/try-trait/bad-interconversion.stderr index 27e6a603acd91..419a86bf33bb4 100644 --- a/src/test/ui/try-trait/bad-interconversion.stderr +++ b/src/test/ui/try-trait/bad-interconversion.stderr @@ -16,7 +16,7 @@ LL | Ok(Err(123_i32)?) > > > - and 67 others + and 68 others = note: required for `Result` to implement `FromResidual>` error[E0277]: the `?` operator can only be used on `Result`s, not `Option`s, in a function that returns `Result`