diff options
| author | Scott McMurray <scottmcm@users.noreply.github.com> | 2022-10-09 15:12:43 -0700 |
|---|---|---|
| committer | Scott McMurray <scottmcm@users.noreply.github.com> | 2022-10-09 15:44:49 -0700 |
| commit | 0718aeceb3b739e467381d1b95a3748ed9ec6bc2 (patch) | |
| tree | 247b9106d552c81252ae4e17641ac8f91261dcc2 | |
| parent | 81f391930301afbc121b7c468138069daa354bf8 (diff) | |
| download | rust-0718aeceb3b739e467381d1b95a3748ed9ec6bc2.tar.gz rust-0718aeceb3b739e467381d1b95a3748ed9ec6bc2.zip | |
From<Alignment> for usize & NonZeroUsize
| -rw-r--r-- | library/core/src/ptr/alignment.rs | 16 | ||||
| -rw-r--r-- | src/test/ui/try-trait/bad-interconversion.stderr | 2 |
2 files changed, 17 insertions, 1 deletions
diff --git a/library/core/src/ptr/alignment.rs b/library/core/src/ptr/alignment.rs index bdebf8baabe..56c5e6cb724 100644 --- a/library/core/src/ptr/alignment.rs +++ b/library/core/src/ptr/alignment.rs @@ -147,6 +147,22 @@ impl TryFrom<usize> for Alignment { } #[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] fn cmp(&self, other: &Self) -> cmp::Ordering { diff --git a/src/test/ui/try-trait/bad-interconversion.stderr b/src/test/ui/try-trait/bad-interconversion.stderr index 27e6a603acd..419a86bf33b 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)?) <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` |
