mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-28 02:57:37 +00:00
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>; ```
This commit is contained in:
commit
1d9ab77eb7
@ -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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user