Skip to content

Commit 1d9ab77

Browse files
authored
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>; ```
2 parents 6471682 + b1b873f commit 1d9ab77

File tree

1 file changed

+15
-10
lines changed
  • library/core/src/convert

1 file changed

+15
-10
lines changed

library/core/src/convert/mod.rs

+15-10
Original file line numberDiff line numberDiff line change
@@ -481,9 +481,10 @@ pub trait TryFrom<T>: Sized {
481481

482482
// As lifts over &
483483
#[stable(feature = "rust1", since = "1.0.0")]
484-
impl<T: ?Sized, U: ?Sized> AsRef<U> for &T
484+
#[rustc_const_unstable(feature = "const_convert", issue = "88674")]
485+
impl<T: ?Sized, U: ?Sized> const AsRef<U> for &T
485486
where
486-
T: AsRef<U>,
487+
T: ~const AsRef<U>,
487488
{
488489
fn as_ref(&self) -> &U {
489490
<T as AsRef<U>>::as_ref(*self)
@@ -492,9 +493,10 @@ where
492493

493494
// As lifts over &mut
494495
#[stable(feature = "rust1", since = "1.0.0")]
495-
impl<T: ?Sized, U: ?Sized> AsRef<U> for &mut T
496+
#[rustc_const_unstable(feature = "const_convert", issue = "88674")]
497+
impl<T: ?Sized, U: ?Sized> const AsRef<U> for &mut T
496498
where
497-
T: AsRef<U>,
499+
T: ~const AsRef<U>,
498500
{
499501
fn as_ref(&self) -> &U {
500502
<T as AsRef<U>>::as_ref(*self)
@@ -511,9 +513,10 @@ where
511513

512514
// AsMut lifts over &mut
513515
#[stable(feature = "rust1", since = "1.0.0")]
514-
impl<T: ?Sized, U: ?Sized> AsMut<U> for &mut T
516+
#[rustc_const_unstable(feature = "const_convert", issue = "88674")]
517+
impl<T: ?Sized, U: ?Sized> const AsMut<U> for &mut T
515518
where
516-
T: AsMut<U>,
519+
T: ~const AsMut<U>,
517520
{
518521
fn as_mut(&mut self) -> &mut U {
519522
(*self).as_mut()
@@ -567,9 +570,10 @@ impl<T> const From<!> for T {
567570

568571
// TryFrom implies TryInto
569572
#[stable(feature = "try_from", since = "1.34.0")]
570-
impl<T, U> TryInto<U> for T
573+
#[rustc_const_unstable(feature = "const_convert", issue = "88674")]
574+
impl<T, U> const TryInto<U> for T
571575
where
572-
U: TryFrom<T>,
576+
U: ~const TryFrom<T>,
573577
{
574578
type Error = U::Error;
575579

@@ -581,9 +585,10 @@ where
581585
// Infallible conversions are semantically equivalent to fallible conversions
582586
// with an uninhabited error type.
583587
#[stable(feature = "try_from", since = "1.34.0")]
584-
impl<T, U> TryFrom<U> for T
588+
#[rustc_const_unstable(feature = "const_convert", issue = "88674")]
589+
impl<T, U> const TryFrom<U> for T
585590
where
586-
U: Into<T>,
591+
U: ~const Into<T>,
587592
{
588593
type Error = Infallible;
589594

0 commit comments

Comments
 (0)