diff options
Diffstat (limited to 'library/core')
| -rw-r--r-- | library/core/src/array/mod.rs | 3 | ||||
| -rw-r--r-- | library/core/src/ascii/ascii_char.rs | 3 | ||||
| -rw-r--r-- | library/core/src/char/convert.rs | 15 | ||||
| -rw-r--r-- | library/core/src/convert/mod.rs | 40 | ||||
| -rw-r--r-- | library/core/src/convert/num.rs | 24 | ||||
| -rw-r--r-- | library/core/src/net/ip_addr.rs | 36 | ||||
| -rw-r--r-- | library/core/src/net/socket_addr.rs | 9 | ||||
| -rw-r--r-- | library/core/src/num/error.rs | 6 | ||||
| -rw-r--r-- | library/core/src/num/mod.rs | 3 | ||||
| -rw-r--r-- | library/core/src/num/nonzero.rs | 3 | ||||
| -rw-r--r-- | library/core/src/ops/try_trait.rs | 8 | ||||
| -rw-r--r-- | library/core/src/option.rs | 28 | ||||
| -rw-r--r-- | library/core/src/ptr/alignment.rs | 6 | ||||
| -rw-r--r-- | library/core/src/ptr/unique.rs | 2 | ||||
| -rw-r--r-- | library/core/src/result.rs | 26 | ||||
| -rw-r--r-- | library/core/src/str/traits.rs | 2 | ||||
| -rw-r--r-- | library/core/src/sync/atomic.rs | 6 |
17 files changed, 149 insertions, 71 deletions
diff --git a/library/core/src/array/mod.rs b/library/core/src/array/mod.rs index 62203e132b7..1c23218552a 100644 --- a/library/core/src/array/mod.rs +++ b/library/core/src/array/mod.rs @@ -198,7 +198,8 @@ impl Error for TryFromSliceError { } #[stable(feature = "try_from_slice_error", since = "1.36.0")] -impl From<Infallible> for TryFromSliceError { +#[rustc_const_unstable(feature = "const_try", issue = "74935")] +impl const From<Infallible> for TryFromSliceError { fn from(x: Infallible) -> TryFromSliceError { match x {} } diff --git a/library/core/src/ascii/ascii_char.rs b/library/core/src/ascii/ascii_char.rs index 0b72b4780f1..054ddf84470 100644 --- a/library/core/src/ascii/ascii_char.rs +++ b/library/core/src/ascii/ascii_char.rs @@ -546,7 +546,8 @@ macro_rules! into_int_impl { ($($ty:ty)*) => { $( #[unstable(feature = "ascii_char", issue = "110998")] - impl From<AsciiChar> for $ty { + #[rustc_const_unstable(feature = "const_try", issue = "74935")] + impl const From<AsciiChar> for $ty { #[inline] fn from(chr: AsciiChar) -> $ty { chr as u8 as $ty diff --git a/library/core/src/char/convert.rs b/library/core/src/char/convert.rs index 78cd89fefae..23061cb663b 100644 --- a/library/core/src/char/convert.rs +++ b/library/core/src/char/convert.rs @@ -36,7 +36,8 @@ pub(super) const unsafe fn from_u32_unchecked(i: u32) -> char { } #[stable(feature = "char_convert", since = "1.13.0")] -impl From<char> for u32 { +#[rustc_const_unstable(feature = "const_try", issue = "74935")] +impl const From<char> for u32 { /// Converts a [`char`] into a [`u32`]. /// /// # Examples @@ -53,7 +54,8 @@ impl From<char> for u32 { } #[stable(feature = "more_char_conversions", since = "1.51.0")] -impl From<char> for u64 { +#[rustc_const_unstable(feature = "const_try", issue = "74935")] +impl const From<char> for u64 { /// Converts a [`char`] into a [`u64`]. /// /// # Examples @@ -72,7 +74,8 @@ impl From<char> for u64 { } #[stable(feature = "more_char_conversions", since = "1.51.0")] -impl From<char> for u128 { +#[rustc_const_unstable(feature = "const_try", issue = "74935")] +impl const From<char> for u128 { /// Converts a [`char`] into a [`u128`]. /// /// # Examples @@ -157,7 +160,8 @@ impl TryFrom<char> for u16 { /// for a superset of Windows-1252 that fills the remaining blanks with corresponding /// C0 and C1 control codes. #[stable(feature = "char_convert", since = "1.13.0")] -impl From<u8> for char { +#[rustc_const_unstable(feature = "const_try", issue = "74935")] +impl const From<u8> for char { /// Converts a [`u8`] into a [`char`]. /// /// # Examples @@ -247,7 +251,8 @@ const fn char_try_from_u32(i: u32) -> Result<char, CharTryFromError> { } #[stable(feature = "try_from", since = "1.34.0")] -impl TryFrom<u32> for char { +#[rustc_const_unstable(feature = "const_try", issue = "74935")] +impl const TryFrom<u32> for char { type Error = CharTryFromError; #[inline] diff --git a/library/core/src/convert/mod.rs b/library/core/src/convert/mod.rs index 38381dbdf23..220a24caf09 100644 --- a/library/core/src/convert/mod.rs +++ b/library/core/src/convert/mod.rs @@ -216,6 +216,8 @@ pub const fn identity<T>(x: T) -> T { /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[rustc_diagnostic_item = "AsRef"] +#[const_trait] +#[rustc_const_unstable(feature = "const_try", issue = "74935")] pub trait AsRef<T: PointeeSized>: PointeeSized { /// Converts this type into a shared reference of the (usually inferred) input type. #[stable(feature = "rust1", since = "1.0.0")] @@ -367,6 +369,8 @@ pub trait AsRef<T: PointeeSized>: PointeeSized { /// `&mut Vec<u8>`, for example, is the better choice (callers need to pass the correct type then). #[stable(feature = "rust1", since = "1.0.0")] #[rustc_diagnostic_item = "AsMut"] +#[const_trait] +#[rustc_const_unstable(feature = "const_try", issue = "74935")] pub trait AsMut<T: PointeeSized>: PointeeSized { /// Converts this type into a mutable reference of the (usually inferred) input type. #[stable(feature = "rust1", since = "1.0.0")] @@ -710,9 +714,10 @@ pub trait TryFrom<T>: Sized { // As lifts over & #[stable(feature = "rust1", since = "1.0.0")] -impl<T: PointeeSized, U: PointeeSized> AsRef<U> for &T +#[rustc_const_unstable(feature = "const_try", issue = "74935")] +impl<T: PointeeSized, U: PointeeSized> const AsRef<U> for &T where - T: AsRef<U>, + T: ~const AsRef<U>, { #[inline] fn as_ref(&self) -> &U { @@ -722,9 +727,10 @@ where // As lifts over &mut #[stable(feature = "rust1", since = "1.0.0")] -impl<T: PointeeSized, U: PointeeSized> AsRef<U> for &mut T +#[rustc_const_unstable(feature = "const_try", issue = "74935")] +impl<T: PointeeSized, U: PointeeSized> const AsRef<U> for &mut T where - T: AsRef<U>, + T: ~const AsRef<U>, { #[inline] fn as_ref(&self) -> &U { @@ -742,9 +748,10 @@ where // AsMut lifts over &mut #[stable(feature = "rust1", since = "1.0.0")] -impl<T: PointeeSized, U: PointeeSized> AsMut<U> for &mut T +#[rustc_const_unstable(feature = "const_try", issue = "74935")] +impl<T: PointeeSized, U: PointeeSized> const AsMut<U> for &mut T where - T: AsMut<U>, + T: ~const AsMut<U>, { #[inline] fn as_mut(&mut self) -> &mut U { @@ -840,7 +847,8 @@ where //////////////////////////////////////////////////////////////////////////////// #[stable(feature = "rust1", since = "1.0.0")] -impl<T> AsRef<[T]> for [T] { +#[rustc_const_unstable(feature = "const_try", issue = "74935")] +impl<T> const AsRef<[T]> for [T] { #[inline(always)] fn as_ref(&self) -> &[T] { self @@ -848,7 +856,8 @@ impl<T> AsRef<[T]> for [T] { } #[stable(feature = "rust1", since = "1.0.0")] -impl<T> AsMut<[T]> for [T] { +#[rustc_const_unstable(feature = "const_try", issue = "74935")] +impl<T> const AsMut<[T]> for [T] { #[inline(always)] fn as_mut(&mut self) -> &mut [T] { self @@ -856,7 +865,8 @@ impl<T> AsMut<[T]> for [T] { } #[stable(feature = "rust1", since = "1.0.0")] -impl AsRef<str> for str { +#[rustc_const_unstable(feature = "const_try", issue = "74935")] +impl const AsRef<str> for str { #[inline(always)] fn as_ref(&self) -> &str { self @@ -864,7 +874,8 @@ impl AsRef<str> for str { } #[stable(feature = "as_mut_str_for_str", since = "1.51.0")] -impl AsMut<str> for str { +#[rustc_const_unstable(feature = "const_try", issue = "74935")] +impl const AsMut<str> for str { #[inline(always)] fn as_mut(&mut self) -> &mut str { self @@ -925,7 +936,8 @@ impl AsMut<str> for str { pub enum Infallible {} #[stable(feature = "convert_infallible", since = "1.34.0")] -impl Clone for Infallible { +#[rustc_const_unstable(feature = "const_try", issue = "74935")] +impl const Clone for Infallible { fn clone(&self) -> Infallible { match *self {} } @@ -953,7 +965,8 @@ impl Error for Infallible { } #[stable(feature = "convert_infallible", since = "1.34.0")] -impl PartialEq for Infallible { +#[rustc_const_unstable(feature = "const_cmp", issue = "143800")] +impl const PartialEq for Infallible { fn eq(&self, _: &Infallible) -> bool { match *self {} } @@ -977,7 +990,8 @@ impl Ord for Infallible { } #[stable(feature = "convert_infallible", since = "1.34.0")] -impl From<!> for Infallible { +#[rustc_const_unstable(feature = "const_try", issue = "74935")] +impl const From<!> for Infallible { #[inline] fn from(x: !) -> Self { x diff --git a/library/core/src/convert/num.rs b/library/core/src/convert/num.rs index 50616732b77..affb4eb64d3 100644 --- a/library/core/src/convert/num.rs +++ b/library/core/src/convert/num.rs @@ -69,7 +69,8 @@ macro_rules! impl_from { }; ($Small:ty => $Large:ty, #[$attr:meta], $doc:expr $(,)?) => { #[$attr] - impl From<$Small> for $Large { + #[rustc_const_unstable(feature = "const_try", issue = "74935")] + impl const From<$Small> for $Large { // Rustdocs on the impl block show a "[+] show undocumented items" toggle. // Rustdocs on functions do not. #[doc = $doc] @@ -200,7 +201,8 @@ macro_rules! impl_float_from_bool { )? ) => { #[stable(feature = "float_from_bool", since = "1.68.0")] - impl From<bool> for $float { + #[rustc_const_unstable(feature = "const_try", issue = "74935")] + impl const From<bool> for $float { #[doc = concat!("Converts a [`bool`] to [`", stringify!($float),"`] losslessly.")] /// The resulting value is positive `0.0` for `false` and `1.0` for `true` values. /// @@ -250,7 +252,8 @@ impl_float_from_bool!( macro_rules! impl_try_from_unbounded { ($source:ty => $($target:ty),+) => {$( #[stable(feature = "try_from", since = "1.34.0")] - impl TryFrom<$source> for $target { + #[rustc_const_unstable(feature = "const_try", issue = "74935")] + impl const TryFrom<$source> for $target { type Error = TryFromIntError; /// Tries to create the target number type from a source @@ -268,7 +271,8 @@ macro_rules! impl_try_from_unbounded { macro_rules! impl_try_from_lower_bounded { ($source:ty => $($target:ty),+) => {$( #[stable(feature = "try_from", since = "1.34.0")] - impl TryFrom<$source> for $target { + #[rustc_const_unstable(feature = "const_try", issue = "74935")] + impl const TryFrom<$source> for $target { type Error = TryFromIntError; /// Tries to create the target number type from a source @@ -290,7 +294,8 @@ macro_rules! impl_try_from_lower_bounded { macro_rules! impl_try_from_upper_bounded { ($source:ty => $($target:ty),+) => {$( #[stable(feature = "try_from", since = "1.34.0")] - impl TryFrom<$source> for $target { + #[rustc_const_unstable(feature = "const_try", issue = "74935")] + impl const TryFrom<$source> for $target { type Error = TryFromIntError; /// Tries to create the target number type from a source @@ -312,7 +317,8 @@ macro_rules! impl_try_from_upper_bounded { macro_rules! impl_try_from_both_bounded { ($source:ty => $($target:ty),+) => {$( #[stable(feature = "try_from", since = "1.34.0")] - impl TryFrom<$source> for $target { + #[rustc_const_unstable(feature = "const_try", issue = "74935")] + impl const TryFrom<$source> for $target { type Error = TryFromIntError; /// Tries to create the target number type from a source @@ -450,7 +456,8 @@ use crate::num::NonZero; macro_rules! impl_nonzero_int_from_nonzero_int { ($Small:ty => $Large:ty) => { #[stable(feature = "nz_int_conv", since = "1.41.0")] - impl From<NonZero<$Small>> for NonZero<$Large> { + #[rustc_const_unstable(feature = "const_try", issue = "74935")] + impl const From<NonZero<$Small>> for NonZero<$Large> { // Rustdocs on the impl block show a "[+] show undocumented items" toggle. // Rustdocs on functions do not. #[doc = concat!("Converts <code>[NonZero]\\<[", stringify!($Small), "]></code> ")] @@ -540,7 +547,8 @@ impl_nonzero_int_try_from_int!(isize); macro_rules! impl_nonzero_int_try_from_nonzero_int { ($source:ty => $($target:ty),+) => {$( #[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")] - impl TryFrom<NonZero<$source>> for NonZero<$target> { + #[rustc_const_unstable(feature = "const_try", issue = "74935")] + impl const TryFrom<NonZero<$source>> for NonZero<$target> { type Error = TryFromIntError; // Rustdocs on the impl block show a "[+] show undocumented items" toggle. diff --git a/library/core/src/net/ip_addr.rs b/library/core/src/net/ip_addr.rs index 49a7ae5de5c..6adeb2aa3fd 100644 --- a/library/core/src/net/ip_addr.rs +++ b/library/core/src/net/ip_addr.rs @@ -1088,7 +1088,8 @@ impl fmt::Debug for IpAddr { } #[stable(feature = "ip_from_ip", since = "1.16.0")] -impl From<Ipv4Addr> for IpAddr { +#[rustc_const_unstable(feature = "const_try", issue = "74935")] +impl const From<Ipv4Addr> for IpAddr { /// Copies this address to a new `IpAddr::V4`. /// /// # Examples @@ -1110,7 +1111,8 @@ impl From<Ipv4Addr> for IpAddr { } #[stable(feature = "ip_from_ip", since = "1.16.0")] -impl From<Ipv6Addr> for IpAddr { +#[rustc_const_unstable(feature = "const_try", issue = "74935")] +impl const From<Ipv6Addr> for IpAddr { /// Copies this address to a new `IpAddr::V6`. /// /// # Examples @@ -1220,7 +1222,8 @@ impl Ord for Ipv4Addr { } #[stable(feature = "ip_u32", since = "1.1.0")] -impl From<Ipv4Addr> for u32 { +#[rustc_const_unstable(feature = "const_try", issue = "74935")] +impl const From<Ipv4Addr> for u32 { /// Uses [`Ipv4Addr::to_bits`] to convert an IPv4 address to a host byte order `u32`. #[inline] fn from(ip: Ipv4Addr) -> u32 { @@ -1229,7 +1232,8 @@ impl From<Ipv4Addr> for u32 { } #[stable(feature = "ip_u32", since = "1.1.0")] -impl From<u32> for Ipv4Addr { +#[rustc_const_unstable(feature = "const_try", issue = "74935")] +impl const From<u32> for Ipv4Addr { /// Uses [`Ipv4Addr::from_bits`] to convert a host byte order `u32` into an IPv4 address. #[inline] fn from(ip: u32) -> Ipv4Addr { @@ -1238,7 +1242,8 @@ impl From<u32> for Ipv4Addr { } #[stable(feature = "from_slice_v4", since = "1.9.0")] -impl From<[u8; 4]> for Ipv4Addr { +#[rustc_const_unstable(feature = "const_try", issue = "74935")] +impl const From<[u8; 4]> for Ipv4Addr { /// Creates an `Ipv4Addr` from a four element byte array. /// /// # Examples @@ -1256,7 +1261,8 @@ impl From<[u8; 4]> for Ipv4Addr { } #[stable(feature = "ip_from_slice", since = "1.17.0")] -impl From<[u8; 4]> for IpAddr { +#[rustc_const_unstable(feature = "const_try", issue = "74935")] +impl const From<[u8; 4]> for IpAddr { /// Creates an `IpAddr::V4` from a four element byte array. /// /// # Examples @@ -2210,7 +2216,8 @@ impl Ord for Ipv6Addr { } #[stable(feature = "i128", since = "1.26.0")] -impl From<Ipv6Addr> for u128 { +#[rustc_const_unstable(feature = "const_try", issue = "74935")] +impl const From<Ipv6Addr> for u128 { /// Uses [`Ipv6Addr::to_bits`] to convert an IPv6 address to a host byte order `u128`. #[inline] fn from(ip: Ipv6Addr) -> u128 { @@ -2218,7 +2225,8 @@ impl From<Ipv6Addr> for u128 { } } #[stable(feature = "i128", since = "1.26.0")] -impl From<u128> for Ipv6Addr { +#[rustc_const_unstable(feature = "const_try", issue = "74935")] +impl const From<u128> for Ipv6Addr { /// Uses [`Ipv6Addr::from_bits`] to convert a host byte order `u128` to an IPv6 address. #[inline] fn from(ip: u128) -> Ipv6Addr { @@ -2227,7 +2235,8 @@ impl From<u128> for Ipv6Addr { } #[stable(feature = "ipv6_from_octets", since = "1.9.0")] -impl From<[u8; 16]> for Ipv6Addr { +#[rustc_const_unstable(feature = "const_try", issue = "74935")] +impl const From<[u8; 16]> for Ipv6Addr { /// Creates an `Ipv6Addr` from a sixteen element byte array. /// /// # Examples @@ -2254,7 +2263,8 @@ impl From<[u8; 16]> for Ipv6Addr { } #[stable(feature = "ipv6_from_segments", since = "1.16.0")] -impl From<[u16; 8]> for Ipv6Addr { +#[rustc_const_unstable(feature = "const_try", issue = "74935")] +impl const From<[u16; 8]> for Ipv6Addr { /// Creates an `Ipv6Addr` from an eight element 16-bit array. /// /// # Examples @@ -2282,7 +2292,8 @@ impl From<[u16; 8]> for Ipv6Addr { } #[stable(feature = "ip_from_slice", since = "1.17.0")] -impl From<[u8; 16]> for IpAddr { +#[rustc_const_unstable(feature = "const_try", issue = "74935")] +impl const From<[u8; 16]> for IpAddr { /// Creates an `IpAddr::V6` from a sixteen element byte array. /// /// # Examples @@ -2309,7 +2320,8 @@ impl From<[u8; 16]> for IpAddr { } #[stable(feature = "ip_from_slice", since = "1.17.0")] -impl From<[u16; 8]> for IpAddr { +#[rustc_const_unstable(feature = "const_try", issue = "74935")] +impl const From<[u16; 8]> for IpAddr { /// Creates an `IpAddr::V6` from an eight element 16-bit array. /// /// # Examples diff --git a/library/core/src/net/socket_addr.rs b/library/core/src/net/socket_addr.rs index 936f9f64930..69924199f99 100644 --- a/library/core/src/net/socket_addr.rs +++ b/library/core/src/net/socket_addr.rs @@ -592,7 +592,8 @@ impl SocketAddrV6 { } #[stable(feature = "ip_from_ip", since = "1.16.0")] -impl From<SocketAddrV4> for SocketAddr { +#[rustc_const_unstable(feature = "const_try", issue = "74935")] +impl const From<SocketAddrV4> for SocketAddr { /// Converts a [`SocketAddrV4`] into a [`SocketAddr::V4`]. #[inline] fn from(sock4: SocketAddrV4) -> SocketAddr { @@ -601,7 +602,8 @@ impl From<SocketAddrV4> for SocketAddr { } #[stable(feature = "ip_from_ip", since = "1.16.0")] -impl From<SocketAddrV6> for SocketAddr { +#[rustc_const_unstable(feature = "const_try", issue = "74935")] +impl const From<SocketAddrV6> for SocketAddr { /// Converts a [`SocketAddrV6`] into a [`SocketAddr::V6`]. #[inline] fn from(sock6: SocketAddrV6) -> SocketAddr { @@ -610,7 +612,8 @@ impl From<SocketAddrV6> for SocketAddr { } #[stable(feature = "addr_from_into_ip", since = "1.17.0")] -impl<I: Into<IpAddr>> From<(I, u16)> for SocketAddr { +#[rustc_const_unstable(feature = "const_try", issue = "74935")] +impl<I: ~const Into<IpAddr>> const From<(I, u16)> for SocketAddr { /// Converts a tuple struct (Into<[`IpAddr`]>, `u16`) into a [`SocketAddr`]. /// /// This conversion creates a [`SocketAddr::V4`] for an [`IpAddr::V4`] diff --git a/library/core/src/num/error.rs b/library/core/src/num/error.rs index f9c4cdd0ebe..cfedd465cab 100644 --- a/library/core/src/num/error.rs +++ b/library/core/src/num/error.rs @@ -26,14 +26,16 @@ impl Error for TryFromIntError { } #[stable(feature = "try_from", since = "1.34.0")] -impl From<Infallible> for TryFromIntError { +#[rustc_const_unstable(feature = "const_try", issue = "74935")] +impl const From<Infallible> for TryFromIntError { fn from(x: Infallible) -> TryFromIntError { match x {} } } #[unstable(feature = "never_type", issue = "35121")] -impl From<!> for TryFromIntError { +#[rustc_const_unstable(feature = "const_try", issue = "74935")] +impl const From<!> for TryFromIntError { #[inline] fn from(never: !) -> TryFromIntError { // Match rather than coerce to make sure that code like diff --git a/library/core/src/num/mod.rs b/library/core/src/num/mod.rs index faa41ddf13c..acfe38b7a37 100644 --- a/library/core/src/num/mod.rs +++ b/library/core/src/num/mod.rs @@ -1378,7 +1378,8 @@ const fn from_ascii_radix_panic(radix: u32) -> ! { macro_rules! from_str_int_impl { ($signedness:ident $($int_ty:ty)+) => {$( #[stable(feature = "rust1", since = "1.0.0")] - impl FromStr for $int_ty { + #[rustc_const_unstable(feature = "const_try", issue = "74935")] + impl const FromStr for $int_ty { type Err = ParseIntError; /// Parses an integer from a string slice with decimal digits. diff --git a/library/core/src/num/nonzero.rs b/library/core/src/num/nonzero.rs index b8900c4113a..f793602de50 100644 --- a/library/core/src/num/nonzero.rs +++ b/library/core/src/num/nonzero.rs @@ -297,7 +297,8 @@ where } #[stable(feature = "from_nonzero", since = "1.31.0")] -impl<T> From<NonZero<T>> for T +#[rustc_const_unstable(feature = "const_try", issue = "74935")] +impl<T> const From<NonZero<T>> for T where T: ZeroablePrimitive, { diff --git a/library/core/src/ops/try_trait.rs b/library/core/src/ops/try_trait.rs index aebbddb4f1c..a889c824be5 100644 --- a/library/core/src/ops/try_trait.rs +++ b/library/core/src/ops/try_trait.rs @@ -128,7 +128,9 @@ use crate::ops::ControlFlow; )] #[doc(alias = "?")] #[lang = "Try"] -pub trait Try: FromResidual { +#[const_trait] +#[rustc_const_unstable(feature = "const_try", issue = "74935")] +pub trait Try: ~const FromResidual { /// The type of the value produced by `?` when *not* short-circuiting. #[unstable(feature = "try_trait_v2", issue = "84277", old_name = "try_trait")] type Output; @@ -304,6 +306,8 @@ pub trait Try: FromResidual { )] #[rustc_diagnostic_item = "FromResidual"] #[unstable(feature = "try_trait_v2", issue = "84277", old_name = "try_trait")] +#[const_trait] +#[rustc_const_unstable(feature = "const_try", issue = "74935")] pub trait FromResidual<R = <Self as Try>::Residual> { /// Constructs the type from a compatible `Residual` type. /// @@ -357,6 +361,8 @@ where /// and in the other direction, /// `<Result<Infallible, E> as Residual<T>>::TryType = Result<T, E>`. #[unstable(feature = "try_trait_v2_residual", issue = "91285")] +#[const_trait] +#[rustc_const_unstable(feature = "const_try", issue = "74935")] pub trait Residual<O> { /// The "return" type of this meta-function. #[unstable(feature = "try_trait_v2_residual", issue = "91285")] diff --git a/library/core/src/option.rs b/library/core/src/option.rs index 0e481519f76..ed070fbd227 100644 --- a/library/core/src/option.rs +++ b/library/core/src/option.rs @@ -2144,9 +2144,12 @@ const fn expect_failed(msg: &str) -> ! { ///////////////////////////////////////////////////////////////////////////// #[stable(feature = "rust1", since = "1.0.0")] -impl<T> Clone for Option<T> +#[rustc_const_unstable(feature = "const_try", issue = "74935")] +impl<T> const Clone for Option<T> where - T: Clone, + // FIXME(const_hack): the T: ~const Destruct should be inferred from the Self: ~const Destruct in clone_from. + // See https://github.com/rust-lang/rust/issues/144207 + T: ~const Clone + ~const Destruct, { #[inline] fn clone(&self) -> Self { @@ -2230,7 +2233,8 @@ impl<'a, T> IntoIterator for &'a mut Option<T> { } #[stable(since = "1.12.0", feature = "option_from")] -impl<T> From<T> for Option<T> { +#[rustc_const_unstable(feature = "const_try", issue = "74935")] +impl<T> const From<T> for Option<T> { /// Moves `val` into a new [`Some`]. /// /// # Examples @@ -2246,7 +2250,8 @@ impl<T> From<T> for Option<T> { } #[stable(feature = "option_ref_from_ref_option", since = "1.30.0")] -impl<'a, T> From<&'a Option<T>> for Option<&'a T> { +#[rustc_const_unstable(feature = "const_try", issue = "74935")] +impl<'a, T> const From<&'a Option<T>> for Option<&'a T> { /// Converts from `&Option<T>` to `Option<&T>`. /// /// # Examples @@ -2273,7 +2278,8 @@ impl<'a, T> From<&'a Option<T>> for Option<&'a T> { } #[stable(feature = "option_ref_from_ref_option", since = "1.30.0")] -impl<'a, T> From<&'a mut Option<T>> for Option<&'a mut T> { +#[rustc_const_unstable(feature = "const_try", issue = "74935")] +impl<'a, T> const From<&'a mut Option<T>> for Option<&'a mut T> { /// Converts from `&mut Option<T>` to `Option<&mut T>` /// /// # Examples @@ -2593,7 +2599,8 @@ impl<A, V: FromIterator<A>> FromIterator<Option<A>> for Option<V> { } #[unstable(feature = "try_trait_v2", issue = "84277", old_name = "try_trait")] -impl<T> ops::Try for Option<T> { +#[rustc_const_unstable(feature = "const_try", issue = "74935")] +impl<T> const ops::Try for Option<T> { type Output = T; type Residual = Option<convert::Infallible>; @@ -2612,9 +2619,10 @@ impl<T> ops::Try for Option<T> { } #[unstable(feature = "try_trait_v2", issue = "84277", old_name = "try_trait")] +#[rustc_const_unstable(feature = "const_try", issue = "74935")] // Note: manually specifying the residual type instead of using the default to work around // https://github.com/rust-lang/rust/issues/99940 -impl<T> ops::FromResidual<Option<convert::Infallible>> for Option<T> { +impl<T> const ops::FromResidual<Option<convert::Infallible>> for Option<T> { #[inline] fn from_residual(residual: Option<convert::Infallible>) -> Self { match residual { @@ -2625,7 +2633,8 @@ impl<T> ops::FromResidual<Option<convert::Infallible>> for Option<T> { #[diagnostic::do_not_recommend] #[unstable(feature = "try_trait_v2_yeet", issue = "96374")] -impl<T> ops::FromResidual<ops::Yeet<()>> for Option<T> { +#[rustc_const_unstable(feature = "const_try", issue = "74935")] +impl<T> const ops::FromResidual<ops::Yeet<()>> for Option<T> { #[inline] fn from_residual(ops::Yeet(()): ops::Yeet<()>) -> Self { None @@ -2633,7 +2642,8 @@ impl<T> ops::FromResidual<ops::Yeet<()>> for Option<T> { } #[unstable(feature = "try_trait_v2_residual", issue = "91285")] -impl<T> ops::Residual<T> for Option<convert::Infallible> { +#[rustc_const_unstable(feature = "const_try", issue = "74935")] +impl<T> const ops::Residual<T> for Option<convert::Infallible> { type TryType = Option<T>; } diff --git a/library/core/src/ptr/alignment.rs b/library/core/src/ptr/alignment.rs index 6d473a4bd56..bd5b4e21baa 100644 --- a/library/core/src/ptr/alignment.rs +++ b/library/core/src/ptr/alignment.rs @@ -189,7 +189,8 @@ impl TryFrom<usize> for Alignment { } #[unstable(feature = "ptr_alignment_type", issue = "102070")] -impl From<Alignment> for NonZero<usize> { +#[rustc_const_unstable(feature = "const_try", issue = "74935")] +impl const From<Alignment> for NonZero<usize> { #[inline] fn from(align: Alignment) -> NonZero<usize> { align.as_nonzero() @@ -197,7 +198,8 @@ impl From<Alignment> for NonZero<usize> { } #[unstable(feature = "ptr_alignment_type", issue = "102070")] -impl From<Alignment> for usize { +#[rustc_const_unstable(feature = "const_try", issue = "74935")] +impl const From<Alignment> for usize { #[inline] fn from(align: Alignment) -> usize { align.as_usize() diff --git a/library/core/src/ptr/unique.rs b/library/core/src/ptr/unique.rs index c069314ff7d..e9e13f9e97f 100644 --- a/library/core/src/ptr/unique.rs +++ b/library/core/src/ptr/unique.rs @@ -32,8 +32,6 @@ use crate::ptr::NonNull; )] #[doc(hidden)] #[repr(transparent)] -// Lang item used experimentally by Miri to define the semantics of `Unique`. -#[lang = "ptr_unique"] pub struct Unique<T: PointeeSized> { pointer: NonNull<T>, // NOTE: this marker has no consequences for variance, but is necessary diff --git a/library/core/src/result.rs b/library/core/src/result.rs index 7f3f2964985..f65257ff59b 100644 --- a/library/core/src/result.rs +++ b/library/core/src/result.rs @@ -1288,9 +1288,11 @@ impl<T, E> Result<T, E> { /// ``` #[unstable(feature = "unwrap_infallible", reason = "newly added", issue = "61695")] #[inline] - pub fn into_ok(self) -> T + #[rustc_allow_const_fn_unstable(const_precise_live_drops)] + #[rustc_const_unstable(feature = "const_try", issue = "74935")] + pub const fn into_ok(self) -> T where - E: Into<!>, + E: ~const Into<!>, { match self { Ok(x) => x, @@ -1323,9 +1325,11 @@ impl<T, E> Result<T, E> { /// ``` #[unstable(feature = "unwrap_infallible", reason = "newly added", issue = "61695")] #[inline] - pub fn into_err(self) -> E + #[rustc_allow_const_fn_unstable(const_precise_live_drops)] + #[rustc_const_unstable(feature = "const_try", issue = "74935")] + pub const fn into_err(self) -> E where - T: Into<!>, + T: ~const Into<!>, { match self { Ok(x) => x.into(), @@ -2052,7 +2056,8 @@ impl<A, E, V: FromIterator<A>> FromIterator<Result<A, E>> for Result<V, E> { } #[unstable(feature = "try_trait_v2", issue = "84277", old_name = "try_trait")] -impl<T, E> ops::Try for Result<T, E> { +#[rustc_const_unstable(feature = "const_try", issue = "74935")] +impl<T, E> const ops::Try for Result<T, E> { type Output = T; type Residual = Result<convert::Infallible, E>; @@ -2071,7 +2076,10 @@ impl<T, E> ops::Try for Result<T, E> { } #[unstable(feature = "try_trait_v2", issue = "84277", old_name = "try_trait")] -impl<T, E, F: From<E>> ops::FromResidual<Result<convert::Infallible, E>> for Result<T, F> { +#[rustc_const_unstable(feature = "const_try", issue = "74935")] +impl<T, E, F: ~const From<E>> const ops::FromResidual<Result<convert::Infallible, E>> + for Result<T, F> +{ #[inline] #[track_caller] fn from_residual(residual: Result<convert::Infallible, E>) -> Self { @@ -2082,7 +2090,8 @@ impl<T, E, F: From<E>> ops::FromResidual<Result<convert::Infallible, E>> for Res } #[diagnostic::do_not_recommend] #[unstable(feature = "try_trait_v2_yeet", issue = "96374")] -impl<T, E, F: From<E>> ops::FromResidual<ops::Yeet<E>> for Result<T, F> { +#[rustc_const_unstable(feature = "const_try", issue = "74935")] +impl<T, E, F: ~const From<E>> const ops::FromResidual<ops::Yeet<E>> for Result<T, F> { #[inline] fn from_residual(ops::Yeet(e): ops::Yeet<E>) -> Self { Err(From::from(e)) @@ -2090,6 +2099,7 @@ impl<T, E, F: From<E>> ops::FromResidual<ops::Yeet<E>> for Result<T, F> { } #[unstable(feature = "try_trait_v2_residual", issue = "91285")] -impl<T, E> ops::Residual<T> for Result<convert::Infallible, E> { +#[rustc_const_unstable(feature = "const_try", issue = "74935")] +impl<T, E> const ops::Residual<T> for Result<convert::Infallible, E> { type TryType = Result<T, E>; } diff --git a/library/core/src/str/traits.rs b/library/core/src/str/traits.rs index d0f2b9226bf..1597d1c1fa8 100644 --- a/library/core/src/str/traits.rs +++ b/library/core/src/str/traits.rs @@ -825,6 +825,8 @@ unsafe impl const SliceIndex<str> for ops::RangeToInclusive<usize> { /// assert!(Point::from_str("(1 2)").is_err()); /// ``` #[stable(feature = "rust1", since = "1.0.0")] +#[const_trait] +#[rustc_const_unstable(feature = "const_try", issue = "74935")] pub trait FromStr: Sized { /// The associated error which can be returned from parsing. #[stable(feature = "rust1", since = "1.0.0")] diff --git a/library/core/src/sync/atomic.rs b/library/core/src/sync/atomic.rs index 04c8d1473b0..546f3d91a80 100644 --- a/library/core/src/sync/atomic.rs +++ b/library/core/src/sync/atomic.rs @@ -2518,7 +2518,8 @@ impl<T> AtomicPtr<T> { #[cfg(target_has_atomic_load_store = "8")] #[stable(feature = "atomic_bool_from", since = "1.24.0")] -impl From<bool> for AtomicBool { +#[rustc_const_unstable(feature = "const_try", issue = "74935")] +impl const From<bool> for AtomicBool { /// Converts a `bool` into an `AtomicBool`. /// /// # Examples @@ -2615,7 +2616,8 @@ macro_rules! atomic_int { } #[$stable_from] - impl From<$int_type> for $atomic_type { + #[rustc_const_unstable(feature = "const_try", issue = "74935")] + impl const From<$int_type> for $atomic_type { #[doc = concat!("Converts an `", stringify!($int_type), "` into an `", stringify!($atomic_type), "`.")] #[inline] fn from(v: $int_type) -> Self { Self::new(v) } |
