Skip to content

Commit 6bcbf85

Browse files
authored
Unrolled build for #143768
Rollup merge of #143768 - Randl:const-try, r=oli-obk Constify Try, From, TryFrom and relevant traits
2 parents 3f9f20f + 3c76e3d commit 6bcbf85

32 files changed

+204
-299
lines changed

library/core/src/array/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,8 @@ impl Error for TryFromSliceError {
198198
}
199199

200200
#[stable(feature = "try_from_slice_error", since = "1.36.0")]
201-
impl From<Infallible> for TryFromSliceError {
201+
#[rustc_const_unstable(feature = "const_try", issue = "74935")]
202+
impl const From<Infallible> for TryFromSliceError {
202203
fn from(x: Infallible) -> TryFromSliceError {
203204
match x {}
204205
}

library/core/src/ascii/ascii_char.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,8 @@ macro_rules! into_int_impl {
546546
($($ty:ty)*) => {
547547
$(
548548
#[unstable(feature = "ascii_char", issue = "110998")]
549-
impl From<AsciiChar> for $ty {
549+
#[rustc_const_unstable(feature = "const_try", issue = "74935")]
550+
impl const From<AsciiChar> for $ty {
550551
#[inline]
551552
fn from(chr: AsciiChar) -> $ty {
552553
chr as u8 as $ty

library/core/src/char/convert.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ pub(super) const unsafe fn from_u32_unchecked(i: u32) -> char {
3636
}
3737

3838
#[stable(feature = "char_convert", since = "1.13.0")]
39-
impl From<char> for u32 {
39+
#[rustc_const_unstable(feature = "const_try", issue = "74935")]
40+
impl const From<char> for u32 {
4041
/// Converts a [`char`] into a [`u32`].
4142
///
4243
/// # Examples
@@ -53,7 +54,8 @@ impl From<char> for u32 {
5354
}
5455

5556
#[stable(feature = "more_char_conversions", since = "1.51.0")]
56-
impl From<char> for u64 {
57+
#[rustc_const_unstable(feature = "const_try", issue = "74935")]
58+
impl const From<char> for u64 {
5759
/// Converts a [`char`] into a [`u64`].
5860
///
5961
/// # Examples
@@ -72,7 +74,8 @@ impl From<char> for u64 {
7274
}
7375

7476
#[stable(feature = "more_char_conversions", since = "1.51.0")]
75-
impl From<char> for u128 {
77+
#[rustc_const_unstable(feature = "const_try", issue = "74935")]
78+
impl const From<char> for u128 {
7679
/// Converts a [`char`] into a [`u128`].
7780
///
7881
/// # Examples
@@ -157,7 +160,8 @@ impl TryFrom<char> for u16 {
157160
/// for a superset of Windows-1252 that fills the remaining blanks with corresponding
158161
/// C0 and C1 control codes.
159162
#[stable(feature = "char_convert", since = "1.13.0")]
160-
impl From<u8> for char {
163+
#[rustc_const_unstable(feature = "const_try", issue = "74935")]
164+
impl const From<u8> for char {
161165
/// Converts a [`u8`] into a [`char`].
162166
///
163167
/// # Examples
@@ -247,7 +251,8 @@ const fn char_try_from_u32(i: u32) -> Result<char, CharTryFromError> {
247251
}
248252

249253
#[stable(feature = "try_from", since = "1.34.0")]
250-
impl TryFrom<u32> for char {
254+
#[rustc_const_unstable(feature = "const_try", issue = "74935")]
255+
impl const TryFrom<u32> for char {
251256
type Error = CharTryFromError;
252257

253258
#[inline]

library/core/src/convert/mod.rs

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,8 @@ pub const fn identity<T>(x: T) -> T {
216216
/// ```
217217
#[stable(feature = "rust1", since = "1.0.0")]
218218
#[rustc_diagnostic_item = "AsRef"]
219+
#[const_trait]
220+
#[rustc_const_unstable(feature = "const_try", issue = "74935")]
219221
pub trait AsRef<T: PointeeSized>: PointeeSized {
220222
/// Converts this type into a shared reference of the (usually inferred) input type.
221223
#[stable(feature = "rust1", since = "1.0.0")]
@@ -367,6 +369,8 @@ pub trait AsRef<T: PointeeSized>: PointeeSized {
367369
/// `&mut Vec<u8>`, for example, is the better choice (callers need to pass the correct type then).
368370
#[stable(feature = "rust1", since = "1.0.0")]
369371
#[rustc_diagnostic_item = "AsMut"]
372+
#[const_trait]
373+
#[rustc_const_unstable(feature = "const_try", issue = "74935")]
370374
pub trait AsMut<T: PointeeSized>: PointeeSized {
371375
/// Converts this type into a mutable reference of the (usually inferred) input type.
372376
#[stable(feature = "rust1", since = "1.0.0")]
@@ -710,9 +714,10 @@ pub trait TryFrom<T>: Sized {
710714

711715
// As lifts over &
712716
#[stable(feature = "rust1", since = "1.0.0")]
713-
impl<T: PointeeSized, U: PointeeSized> AsRef<U> for &T
717+
#[rustc_const_unstable(feature = "const_try", issue = "74935")]
718+
impl<T: PointeeSized, U: PointeeSized> const AsRef<U> for &T
714719
where
715-
T: AsRef<U>,
720+
T: ~const AsRef<U>,
716721
{
717722
#[inline]
718723
fn as_ref(&self) -> &U {
@@ -722,9 +727,10 @@ where
722727

723728
// As lifts over &mut
724729
#[stable(feature = "rust1", since = "1.0.0")]
725-
impl<T: PointeeSized, U: PointeeSized> AsRef<U> for &mut T
730+
#[rustc_const_unstable(feature = "const_try", issue = "74935")]
731+
impl<T: PointeeSized, U: PointeeSized> const AsRef<U> for &mut T
726732
where
727-
T: AsRef<U>,
733+
T: ~const AsRef<U>,
728734
{
729735
#[inline]
730736
fn as_ref(&self) -> &U {
@@ -742,9 +748,10 @@ where
742748

743749
// AsMut lifts over &mut
744750
#[stable(feature = "rust1", since = "1.0.0")]
745-
impl<T: PointeeSized, U: PointeeSized> AsMut<U> for &mut T
751+
#[rustc_const_unstable(feature = "const_try", issue = "74935")]
752+
impl<T: PointeeSized, U: PointeeSized> const AsMut<U> for &mut T
746753
where
747-
T: AsMut<U>,
754+
T: ~const AsMut<U>,
748755
{
749756
#[inline]
750757
fn as_mut(&mut self) -> &mut U {
@@ -840,31 +847,35 @@ where
840847
////////////////////////////////////////////////////////////////////////////////
841848

842849
#[stable(feature = "rust1", since = "1.0.0")]
843-
impl<T> AsRef<[T]> for [T] {
850+
#[rustc_const_unstable(feature = "const_try", issue = "74935")]
851+
impl<T> const AsRef<[T]> for [T] {
844852
#[inline(always)]
845853
fn as_ref(&self) -> &[T] {
846854
self
847855
}
848856
}
849857

850858
#[stable(feature = "rust1", since = "1.0.0")]
851-
impl<T> AsMut<[T]> for [T] {
859+
#[rustc_const_unstable(feature = "const_try", issue = "74935")]
860+
impl<T> const AsMut<[T]> for [T] {
852861
#[inline(always)]
853862
fn as_mut(&mut self) -> &mut [T] {
854863
self
855864
}
856865
}
857866

858867
#[stable(feature = "rust1", since = "1.0.0")]
859-
impl AsRef<str> for str {
868+
#[rustc_const_unstable(feature = "const_try", issue = "74935")]
869+
impl const AsRef<str> for str {
860870
#[inline(always)]
861871
fn as_ref(&self) -> &str {
862872
self
863873
}
864874
}
865875

866876
#[stable(feature = "as_mut_str_for_str", since = "1.51.0")]
867-
impl AsMut<str> for str {
877+
#[rustc_const_unstable(feature = "const_try", issue = "74935")]
878+
impl const AsMut<str> for str {
868879
#[inline(always)]
869880
fn as_mut(&mut self) -> &mut str {
870881
self
@@ -925,7 +936,8 @@ impl AsMut<str> for str {
925936
pub enum Infallible {}
926937

927938
#[stable(feature = "convert_infallible", since = "1.34.0")]
928-
impl Clone for Infallible {
939+
#[rustc_const_unstable(feature = "const_try", issue = "74935")]
940+
impl const Clone for Infallible {
929941
fn clone(&self) -> Infallible {
930942
match *self {}
931943
}
@@ -953,7 +965,8 @@ impl Error for Infallible {
953965
}
954966

955967
#[stable(feature = "convert_infallible", since = "1.34.0")]
956-
impl PartialEq for Infallible {
968+
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
969+
impl const PartialEq for Infallible {
957970
fn eq(&self, _: &Infallible) -> bool {
958971
match *self {}
959972
}
@@ -977,7 +990,8 @@ impl Ord for Infallible {
977990
}
978991

979992
#[stable(feature = "convert_infallible", since = "1.34.0")]
980-
impl From<!> for Infallible {
993+
#[rustc_const_unstable(feature = "const_try", issue = "74935")]
994+
impl const From<!> for Infallible {
981995
#[inline]
982996
fn from(x: !) -> Self {
983997
x

library/core/src/convert/num.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ macro_rules! impl_from {
6969
};
7070
($Small:ty => $Large:ty, #[$attr:meta], $doc:expr $(,)?) => {
7171
#[$attr]
72-
impl From<$Small> for $Large {
72+
#[rustc_const_unstable(feature = "const_try", issue = "74935")]
73+
impl const From<$Small> for $Large {
7374
// Rustdocs on the impl block show a "[+] show undocumented items" toggle.
7475
// Rustdocs on functions do not.
7576
#[doc = $doc]
@@ -200,7 +201,8 @@ macro_rules! impl_float_from_bool {
200201
)?
201202
) => {
202203
#[stable(feature = "float_from_bool", since = "1.68.0")]
203-
impl From<bool> for $float {
204+
#[rustc_const_unstable(feature = "const_try", issue = "74935")]
205+
impl const From<bool> for $float {
204206
#[doc = concat!("Converts a [`bool`] to [`", stringify!($float),"`] losslessly.")]
205207
/// The resulting value is positive `0.0` for `false` and `1.0` for `true` values.
206208
///
@@ -250,7 +252,8 @@ impl_float_from_bool!(
250252
macro_rules! impl_try_from_unbounded {
251253
($source:ty => $($target:ty),+) => {$(
252254
#[stable(feature = "try_from", since = "1.34.0")]
253-
impl TryFrom<$source> for $target {
255+
#[rustc_const_unstable(feature = "const_try", issue = "74935")]
256+
impl const TryFrom<$source> for $target {
254257
type Error = TryFromIntError;
255258

256259
/// Tries to create the target number type from a source
@@ -268,7 +271,8 @@ macro_rules! impl_try_from_unbounded {
268271
macro_rules! impl_try_from_lower_bounded {
269272
($source:ty => $($target:ty),+) => {$(
270273
#[stable(feature = "try_from", since = "1.34.0")]
271-
impl TryFrom<$source> for $target {
274+
#[rustc_const_unstable(feature = "const_try", issue = "74935")]
275+
impl const TryFrom<$source> for $target {
272276
type Error = TryFromIntError;
273277

274278
/// Tries to create the target number type from a source
@@ -290,7 +294,8 @@ macro_rules! impl_try_from_lower_bounded {
290294
macro_rules! impl_try_from_upper_bounded {
291295
($source:ty => $($target:ty),+) => {$(
292296
#[stable(feature = "try_from", since = "1.34.0")]
293-
impl TryFrom<$source> for $target {
297+
#[rustc_const_unstable(feature = "const_try", issue = "74935")]
298+
impl const TryFrom<$source> for $target {
294299
type Error = TryFromIntError;
295300

296301
/// Tries to create the target number type from a source
@@ -312,7 +317,8 @@ macro_rules! impl_try_from_upper_bounded {
312317
macro_rules! impl_try_from_both_bounded {
313318
($source:ty => $($target:ty),+) => {$(
314319
#[stable(feature = "try_from", since = "1.34.0")]
315-
impl TryFrom<$source> for $target {
320+
#[rustc_const_unstable(feature = "const_try", issue = "74935")]
321+
impl const TryFrom<$source> for $target {
316322
type Error = TryFromIntError;
317323

318324
/// Tries to create the target number type from a source
@@ -450,7 +456,8 @@ use crate::num::NonZero;
450456
macro_rules! impl_nonzero_int_from_nonzero_int {
451457
($Small:ty => $Large:ty) => {
452458
#[stable(feature = "nz_int_conv", since = "1.41.0")]
453-
impl From<NonZero<$Small>> for NonZero<$Large> {
459+
#[rustc_const_unstable(feature = "const_try", issue = "74935")]
460+
impl const From<NonZero<$Small>> for NonZero<$Large> {
454461
// Rustdocs on the impl block show a "[+] show undocumented items" toggle.
455462
// Rustdocs on functions do not.
456463
#[doc = concat!("Converts <code>[NonZero]\\<[", stringify!($Small), "]></code> ")]
@@ -540,7 +547,8 @@ impl_nonzero_int_try_from_int!(isize);
540547
macro_rules! impl_nonzero_int_try_from_nonzero_int {
541548
($source:ty => $($target:ty),+) => {$(
542549
#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
543-
impl TryFrom<NonZero<$source>> for NonZero<$target> {
550+
#[rustc_const_unstable(feature = "const_try", issue = "74935")]
551+
impl const TryFrom<NonZero<$source>> for NonZero<$target> {
544552
type Error = TryFromIntError;
545553

546554
// Rustdocs on the impl block show a "[+] show undocumented items" toggle.

library/core/src/net/ip_addr.rs

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,7 +1088,8 @@ impl fmt::Debug for IpAddr {
10881088
}
10891089

10901090
#[stable(feature = "ip_from_ip", since = "1.16.0")]
1091-
impl From<Ipv4Addr> for IpAddr {
1091+
#[rustc_const_unstable(feature = "const_try", issue = "74935")]
1092+
impl const From<Ipv4Addr> for IpAddr {
10921093
/// Copies this address to a new `IpAddr::V4`.
10931094
///
10941095
/// # Examples
@@ -1110,7 +1111,8 @@ impl From<Ipv4Addr> for IpAddr {
11101111
}
11111112

11121113
#[stable(feature = "ip_from_ip", since = "1.16.0")]
1113-
impl From<Ipv6Addr> for IpAddr {
1114+
#[rustc_const_unstable(feature = "const_try", issue = "74935")]
1115+
impl const From<Ipv6Addr> for IpAddr {
11141116
/// Copies this address to a new `IpAddr::V6`.
11151117
///
11161118
/// # Examples
@@ -1220,7 +1222,8 @@ impl Ord for Ipv4Addr {
12201222
}
12211223

12221224
#[stable(feature = "ip_u32", since = "1.1.0")]
1223-
impl From<Ipv4Addr> for u32 {
1225+
#[rustc_const_unstable(feature = "const_try", issue = "74935")]
1226+
impl const From<Ipv4Addr> for u32 {
12241227
/// Uses [`Ipv4Addr::to_bits`] to convert an IPv4 address to a host byte order `u32`.
12251228
#[inline]
12261229
fn from(ip: Ipv4Addr) -> u32 {
@@ -1229,7 +1232,8 @@ impl From<Ipv4Addr> for u32 {
12291232
}
12301233

12311234
#[stable(feature = "ip_u32", since = "1.1.0")]
1232-
impl From<u32> for Ipv4Addr {
1235+
#[rustc_const_unstable(feature = "const_try", issue = "74935")]
1236+
impl const From<u32> for Ipv4Addr {
12331237
/// Uses [`Ipv4Addr::from_bits`] to convert a host byte order `u32` into an IPv4 address.
12341238
#[inline]
12351239
fn from(ip: u32) -> Ipv4Addr {
@@ -1238,7 +1242,8 @@ impl From<u32> for Ipv4Addr {
12381242
}
12391243

12401244
#[stable(feature = "from_slice_v4", since = "1.9.0")]
1241-
impl From<[u8; 4]> for Ipv4Addr {
1245+
#[rustc_const_unstable(feature = "const_try", issue = "74935")]
1246+
impl const From<[u8; 4]> for Ipv4Addr {
12421247
/// Creates an `Ipv4Addr` from a four element byte array.
12431248
///
12441249
/// # Examples
@@ -1256,7 +1261,8 @@ impl From<[u8; 4]> for Ipv4Addr {
12561261
}
12571262

12581263
#[stable(feature = "ip_from_slice", since = "1.17.0")]
1259-
impl From<[u8; 4]> for IpAddr {
1264+
#[rustc_const_unstable(feature = "const_try", issue = "74935")]
1265+
impl const From<[u8; 4]> for IpAddr {
12601266
/// Creates an `IpAddr::V4` from a four element byte array.
12611267
///
12621268
/// # Examples
@@ -2210,15 +2216,17 @@ impl Ord for Ipv6Addr {
22102216
}
22112217

22122218
#[stable(feature = "i128", since = "1.26.0")]
2213-
impl From<Ipv6Addr> for u128 {
2219+
#[rustc_const_unstable(feature = "const_try", issue = "74935")]
2220+
impl const From<Ipv6Addr> for u128 {
22142221
/// Uses [`Ipv6Addr::to_bits`] to convert an IPv6 address to a host byte order `u128`.
22152222
#[inline]
22162223
fn from(ip: Ipv6Addr) -> u128 {
22172224
ip.to_bits()
22182225
}
22192226
}
22202227
#[stable(feature = "i128", since = "1.26.0")]
2221-
impl From<u128> for Ipv6Addr {
2228+
#[rustc_const_unstable(feature = "const_try", issue = "74935")]
2229+
impl const From<u128> for Ipv6Addr {
22222230
/// Uses [`Ipv6Addr::from_bits`] to convert a host byte order `u128` to an IPv6 address.
22232231
#[inline]
22242232
fn from(ip: u128) -> Ipv6Addr {
@@ -2227,7 +2235,8 @@ impl From<u128> for Ipv6Addr {
22272235
}
22282236

22292237
#[stable(feature = "ipv6_from_octets", since = "1.9.0")]
2230-
impl From<[u8; 16]> for Ipv6Addr {
2238+
#[rustc_const_unstable(feature = "const_try", issue = "74935")]
2239+
impl const From<[u8; 16]> for Ipv6Addr {
22312240
/// Creates an `Ipv6Addr` from a sixteen element byte array.
22322241
///
22332242
/// # Examples
@@ -2254,7 +2263,8 @@ impl From<[u8; 16]> for Ipv6Addr {
22542263
}
22552264

22562265
#[stable(feature = "ipv6_from_segments", since = "1.16.0")]
2257-
impl From<[u16; 8]> for Ipv6Addr {
2266+
#[rustc_const_unstable(feature = "const_try", issue = "74935")]
2267+
impl const From<[u16; 8]> for Ipv6Addr {
22582268
/// Creates an `Ipv6Addr` from an eight element 16-bit array.
22592269
///
22602270
/// # Examples
@@ -2282,7 +2292,8 @@ impl From<[u16; 8]> for Ipv6Addr {
22822292
}
22832293

22842294
#[stable(feature = "ip_from_slice", since = "1.17.0")]
2285-
impl From<[u8; 16]> for IpAddr {
2295+
#[rustc_const_unstable(feature = "const_try", issue = "74935")]
2296+
impl const From<[u8; 16]> for IpAddr {
22862297
/// Creates an `IpAddr::V6` from a sixteen element byte array.
22872298
///
22882299
/// # Examples
@@ -2309,7 +2320,8 @@ impl From<[u8; 16]> for IpAddr {
23092320
}
23102321

23112322
#[stable(feature = "ip_from_slice", since = "1.17.0")]
2312-
impl From<[u16; 8]> for IpAddr {
2323+
#[rustc_const_unstable(feature = "const_try", issue = "74935")]
2324+
impl const From<[u16; 8]> for IpAddr {
23132325
/// Creates an `IpAddr::V6` from an eight element 16-bit array.
23142326
///
23152327
/// # Examples

0 commit comments

Comments
 (0)