diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2022-01-15 02:25:14 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-01-15 02:25:14 +0100 |
| commit | 1d9ab77eb75b4fa71883831ce883ce8ff508bda1 (patch) | |
| tree | 3c98dae6709c78ba477df68258c7b06c7fb58b20 | |
| parent | 64716825b01daedf8eb97b14b128bdab8b3b0f45 (diff) | |
| parent | b1b873f3659fb8f9c6fd64b7c78126152694495d (diff) | |
| download | rust-1d9ab77eb75b4fa71883831ce883ce8ff508bda1.tar.gz rust-1d9ab77eb75b4fa71883831ce883ce8ff508bda1.zip | |
Rollup merge of #92382 - clarfonthey:const_convert, r=scottmcm
Extend const_convert to rest of blanket core::convert impls This adds constness to all the blanket impls in `core::convert` under the existing `const_convert` feature, tracked by #88674. Existing impls under that feature: ```rust impl<T> const From<T> for T; impl<T, U> const Into<U> for T where U: ~const From<T>; impl<T> const ops::Try for Option<T>; impl<T> const ops::FromResidual for Option<T>; impl<T, E> const ops::Try for Result<T, E>; impl<T, E, F> const ops::FromResidual<Result<convert::Infallible, E>> for Result<T, F> where F: ~const From<E>; ``` Additional impls: ```rust impl<T: ?Sized, U: ?Sized> const AsRef<U> for &T where T: ~const AsRef<U>; impl<T: ?Sized, U: ?Sized> const AsRef<U> for &mut T where T: ~const AsRef<U>; impl<T: ?Sized, U: ?Sized> const AsMut<U> for &mut T where T: ~const AsMut<U>; impl<T, U> const TryInto<U> for T where U: ~const TryFrom<T>; impl<T, U> const TryFrom<U> for T where U: ~const Into<T>; ```
| -rw-r--r-- | library/core/src/convert/mod.rs | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/library/core/src/convert/mod.rs b/library/core/src/convert/mod.rs index 3a149afd771..5566c2ffe87 100644 --- a/library/core/src/convert/mod.rs +++ b/library/core/src/convert/mod.rs @@ -481,9 +481,10 @@ pub trait TryFrom<T>: Sized { // As lifts over & #[stable(feature = "rust1", since = "1.0.0")] -impl<T: ?Sized, U: ?Sized> AsRef<U> for &T +#[rustc_const_unstable(feature = "const_convert", issue = "88674")] +impl<T: ?Sized, U: ?Sized> const AsRef<U> for &T where - T: AsRef<U>, + T: ~const AsRef<U>, { fn as_ref(&self) -> &U { <T as AsRef<U>>::as_ref(*self) @@ -492,9 +493,10 @@ where // As lifts over &mut #[stable(feature = "rust1", since = "1.0.0")] -impl<T: ?Sized, U: ?Sized> AsRef<U> for &mut T +#[rustc_const_unstable(feature = "const_convert", issue = "88674")] +impl<T: ?Sized, U: ?Sized> const AsRef<U> for &mut T where - T: AsRef<U>, + T: ~const AsRef<U>, { fn as_ref(&self) -> &U { <T as AsRef<U>>::as_ref(*self) @@ -511,9 +513,10 @@ where // AsMut lifts over &mut #[stable(feature = "rust1", since = "1.0.0")] -impl<T: ?Sized, U: ?Sized> AsMut<U> for &mut T +#[rustc_const_unstable(feature = "const_convert", issue = "88674")] +impl<T: ?Sized, U: ?Sized> const AsMut<U> for &mut T where - T: AsMut<U>, + T: ~const AsMut<U>, { fn as_mut(&mut self) -> &mut U { (*self).as_mut() @@ -567,9 +570,10 @@ impl<T> const From<!> for T { // TryFrom implies TryInto #[stable(feature = "try_from", since = "1.34.0")] -impl<T, U> TryInto<U> for T +#[rustc_const_unstable(feature = "const_convert", issue = "88674")] +impl<T, U> const TryInto<U> for T where - U: TryFrom<T>, + U: ~const TryFrom<T>, { type Error = U::Error; @@ -581,9 +585,10 @@ where // Infallible conversions are semantically equivalent to fallible conversions // with an uninhabited error type. #[stable(feature = "try_from", since = "1.34.0")] -impl<T, U> TryFrom<U> for T +#[rustc_const_unstable(feature = "const_convert", issue = "88674")] +impl<T, U> const TryFrom<U> for T where - U: Into<T>, + U: ~const Into<T>, { type Error = Infallible; |
