Skip to content

Commit 605ea7c

Browse files
committed
Rollup merge of #49426 - lukaslueg:patch-1, r=kennytm
Update CONTRIBUTING.md The current link is a 404, just link to the main repo page
2 parents 19fe9d1 + f513fbd commit 605ea7c

File tree

31 files changed

+344
-342
lines changed

31 files changed

+344
-342
lines changed

Diff for: CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ If you're looking for somewhere to start, check out the [E-easy][eeasy] tag.
594594
[inom]: https://github.com/rust-lang/rust/issues?q=is%3Aopen+is%3Aissue+label%3AI-nominated
595595
[eeasy]: https://github.com/rust-lang/rust/issues?q=is%3Aopen+is%3Aissue+label%3AE-easy
596596
[lru]: https://github.com/rust-lang/rust/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-asc
597-
[rfcbot]: https://github.com/dikaiosune/rust-dashboard/blob/master/RFCBOT.md
597+
[rfcbot]: https://github.com/anp/rfcbot-rs/
598598

599599
## Out-of-tree Contributions
600600
[out-of-tree-contributions]: #out-of-tree-contributions

Diff for: src/libcore/array.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ unsafe impl<T, A: Unsize<[T]>> FixedSizeArray<T> for A {
5959
}
6060

6161
/// The error type returned when a conversion from a slice to an array fails.
62-
#[unstable(feature = "try_from", issue = "33417")]
62+
#[stable(feature = "try_from", since = "1.26.0")]
6363
#[derive(Debug, Copy, Clone)]
6464
pub struct TryFromSliceError(());
6565

@@ -148,7 +148,7 @@ macro_rules! array_impls {
148148
}
149149
}
150150

151-
#[unstable(feature = "try_from", issue = "33417")]
151+
#[stable(feature = "try_from", since = "1.26.0")]
152152
impl<'a, T> TryFrom<&'a [T]> for &'a [T; $N] {
153153
type Error = TryFromSliceError;
154154

@@ -162,7 +162,7 @@ macro_rules! array_impls {
162162
}
163163
}
164164

165-
#[unstable(feature = "try_from", issue = "33417")]
165+
#[stable(feature = "try_from", since = "1.26.0")]
166166
impl<'a, T> TryFrom<&'a mut [T]> for &'a mut [T; $N] {
167167
type Error = TryFromSliceError;
168168

Diff for: src/libcore/char.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ impl FromStr for char {
265265
}
266266

267267

268-
#[unstable(feature = "try_from", issue = "33417")]
268+
#[stable(feature = "try_from", since = "1.26.0")]
269269
impl TryFrom<u32> for char {
270270
type Error = CharTryFromError;
271271

@@ -280,11 +280,11 @@ impl TryFrom<u32> for char {
280280
}
281281

282282
/// The error type returned when a conversion from u32 to char fails.
283-
#[unstable(feature = "try_from", issue = "33417")]
283+
#[stable(feature = "try_from", since = "1.26.0")]
284284
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
285285
pub struct CharTryFromError(());
286286

287-
#[unstable(feature = "try_from", issue = "33417")]
287+
#[stable(feature = "try_from", since = "1.26.0")]
288288
impl fmt::Display for CharTryFromError {
289289
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
290290
"converted integer out of range for `char`".fmt(f)

Diff for: src/libcore/convert.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -322,22 +322,26 @@ pub trait From<T>: Sized {
322322
///
323323
/// [`TryFrom`]: trait.TryFrom.html
324324
/// [`Into`]: trait.Into.html
325-
#[unstable(feature = "try_from", issue = "33417")]
325+
#[stable(feature = "try_from", since = "1.26.0")]
326326
pub trait TryInto<T>: Sized {
327327
/// The type returned in the event of a conversion error.
328+
#[stable(feature = "try_from", since = "1.26.0")]
328329
type Error;
329330

330331
/// Performs the conversion.
332+
#[stable(feature = "try_from", since = "1.26.0")]
331333
fn try_into(self) -> Result<T, Self::Error>;
332334
}
333335

334336
/// Attempt to construct `Self` via a conversion.
335-
#[unstable(feature = "try_from", issue = "33417")]
337+
#[stable(feature = "try_from", since = "1.26.0")]
336338
pub trait TryFrom<T>: Sized {
337339
/// The type returned in the event of a conversion error.
340+
#[stable(feature = "try_from", since = "1.26.0")]
338341
type Error;
339342

340343
/// Performs the conversion.
344+
#[stable(feature = "try_from", since = "1.26.0")]
341345
fn try_from(value: T) -> Result<Self, Self::Error>;
342346
}
343347

@@ -405,7 +409,7 @@ impl<T> From<T> for T {
405409

406410

407411
// TryFrom implies TryInto
408-
#[unstable(feature = "try_from", issue = "33417")]
412+
#[stable(feature = "try_from", since = "1.26.0")]
409413
impl<T, U> TryInto<U> for T where U: TryFrom<T>
410414
{
411415
type Error = U::Error;
@@ -417,7 +421,7 @@ impl<T, U> TryInto<U> for T where U: TryFrom<T>
417421

418422
// Infallible conversions are semantically equivalent to fallible conversions
419423
// with an uninhabited error type.
420-
#[unstable(feature = "try_from", issue = "33417")]
424+
#[stable(feature = "try_from", since = "1.26.0")]
421425
impl<T, U> TryFrom<U> for T where T: From<U> {
422426
type Error = !;
423427

Diff for: src/libcore/iter/range.rs

+72-2
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ macro_rules! step_impl_unsigned {
9191
#[inline]
9292
#[allow(unreachable_patterns)]
9393
fn add_usize(&self, n: usize) -> Option<Self> {
94-
match <$t>::try_from(n) {
94+
match <$t>::private_try_from(n) {
9595
Ok(n_as_t) => self.checked_add(n_as_t),
9696
Err(_) => None,
9797
}
@@ -123,7 +123,7 @@ macro_rules! step_impl_signed {
123123
#[inline]
124124
#[allow(unreachable_patterns)]
125125
fn add_usize(&self, n: usize) -> Option<Self> {
126-
match <$unsigned>::try_from(n) {
126+
match <$unsigned>::private_try_from(n) {
127127
Ok(n_as_unsigned) => {
128128
// Wrapping in unsigned space handles cases like
129129
// `-120_i8.add_usize(200) == Some(80_i8)`,
@@ -461,3 +461,73 @@ impl<A: Step> DoubleEndedIterator for ops::RangeInclusive<A> {
461461

462462
#[stable(feature = "fused", since = "1.26.0")]
463463
impl<A: Step> FusedIterator for ops::RangeInclusive<A> {}
464+
465+
/// Compensate removal of some impls per
466+
/// https://github.com/rust-lang/rust/pull/49305#issuecomment-376293243
467+
trait PrivateTryFromUsize: Sized {
468+
fn private_try_from(n: usize) -> Result<Self, ()>;
469+
}
470+
471+
impl<T> PrivateTryFromUsize for T where T: TryFrom<usize> {
472+
#[inline]
473+
fn private_try_from(n: usize) -> Result<Self, ()> {
474+
T::try_from(n).map_err(|_| ())
475+
}
476+
}
477+
478+
// no possible bounds violation
479+
macro_rules! try_from_unbounded {
480+
($($target:ty),*) => {$(
481+
impl PrivateTryFromUsize for $target {
482+
#[inline]
483+
fn private_try_from(value: usize) -> Result<Self, ()> {
484+
Ok(value as $target)
485+
}
486+
}
487+
)*}
488+
}
489+
490+
// unsigned to signed (only positive bound)
491+
macro_rules! try_from_upper_bounded {
492+
($($target:ty),*) => {$(
493+
impl PrivateTryFromUsize for $target {
494+
#[inline]
495+
fn private_try_from(u: usize) -> Result<$target, ()> {
496+
if u > (<$target>::max_value() as usize) {
497+
Err(())
498+
} else {
499+
Ok(u as $target)
500+
}
501+
}
502+
}
503+
)*}
504+
}
505+
506+
507+
#[cfg(target_pointer_width = "16")]
508+
mod ptr_try_from_impls {
509+
use super::PrivateTryFromUsize;
510+
511+
try_from_unbounded!(u16, u32, u64, u128);
512+
try_from_unbounded!(i32, i64, i128);
513+
}
514+
515+
#[cfg(target_pointer_width = "32")]
516+
mod ptr_try_from_impls {
517+
use super::PrivateTryFromUsize;
518+
519+
try_from_upper_bounded!(u16);
520+
try_from_unbounded!(u32, u64, u128);
521+
try_from_upper_bounded!(i32);
522+
try_from_unbounded!(i64, i128);
523+
}
524+
525+
#[cfg(target_pointer_width = "64")]
526+
mod ptr_try_from_impls {
527+
use super::PrivateTryFromUsize;
528+
529+
try_from_upper_bounded!(u16, u32);
530+
try_from_unbounded!(u64, u128);
531+
try_from_upper_bounded!(i32, i64);
532+
try_from_unbounded!(i128);
533+
}

Diff for: src/libcore/num/mod.rs

+30-69
Original file line numberDiff line numberDiff line change
@@ -3647,7 +3647,7 @@ macro_rules! from_str_radix_int_impl {
36473647
from_str_radix_int_impl! { isize i8 i16 i32 i64 i128 usize u8 u16 u32 u64 u128 }
36483648

36493649
/// The error type returned when a checked integral type conversion fails.
3650-
#[unstable(feature = "try_from", issue = "33417")]
3650+
#[stable(feature = "try_from", since = "1.26.0")]
36513651
#[derive(Debug, Copy, Clone)]
36523652
pub struct TryFromIntError(());
36533653

@@ -3662,39 +3662,24 @@ impl TryFromIntError {
36623662
}
36633663
}
36643664

3665-
#[unstable(feature = "try_from", issue = "33417")]
3665+
#[stable(feature = "try_from", since = "1.26.0")]
36663666
impl fmt::Display for TryFromIntError {
36673667
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
36683668
self.__description().fmt(fmt)
36693669
}
36703670
}
36713671

3672-
#[unstable(feature = "try_from", issue = "33417")]
3672+
#[stable(feature = "try_from", since = "1.26.0")]
36733673
impl From<!> for TryFromIntError {
36743674
fn from(never: !) -> TryFromIntError {
36753675
never
36763676
}
36773677
}
36783678

3679-
// no possible bounds violation
3680-
macro_rules! try_from_unbounded {
3681-
($source:ty, $($target:ty),*) => {$(
3682-
#[unstable(feature = "try_from", issue = "33417")]
3683-
impl TryFrom<$source> for $target {
3684-
type Error = !;
3685-
3686-
#[inline]
3687-
fn try_from(value: $source) -> Result<Self, Self::Error> {
3688-
Ok(value as $target)
3689-
}
3690-
}
3691-
)*}
3692-
}
3693-
36943679
// only negative bounds
36953680
macro_rules! try_from_lower_bounded {
36963681
($source:ty, $($target:ty),*) => {$(
3697-
#[unstable(feature = "try_from", issue = "33417")]
3682+
#[stable(feature = "try_from", since = "1.26.0")]
36983683
impl TryFrom<$source> for $target {
36993684
type Error = TryFromIntError;
37003685

@@ -3713,7 +3698,7 @@ macro_rules! try_from_lower_bounded {
37133698
// unsigned to signed (only positive bound)
37143699
macro_rules! try_from_upper_bounded {
37153700
($source:ty, $($target:ty),*) => {$(
3716-
#[unstable(feature = "try_from", issue = "33417")]
3701+
#[stable(feature = "try_from", since = "1.26.0")]
37173702
impl TryFrom<$source> for $target {
37183703
type Error = TryFromIntError;
37193704

@@ -3732,7 +3717,7 @@ macro_rules! try_from_upper_bounded {
37323717
// all other cases
37333718
macro_rules! try_from_both_bounded {
37343719
($source:ty, $($target:ty),*) => {$(
3735-
#[unstable(feature = "try_from", issue = "33417")]
3720+
#[stable(feature = "try_from", since = "1.26.0")]
37363721
impl TryFrom<$source> for $target {
37373722
type Error = TryFromIntError;
37383723

@@ -3789,82 +3774,44 @@ try_from_both_bounded!(i128, u64, u32, u16, u8);
37893774
try_from_upper_bounded!(usize, isize);
37903775
try_from_lower_bounded!(isize, usize);
37913776

3777+
try_from_upper_bounded!(usize, u8);
3778+
try_from_upper_bounded!(usize, i8, i16);
3779+
try_from_both_bounded!(isize, u8);
3780+
try_from_both_bounded!(isize, i8);
3781+
37923782
#[cfg(target_pointer_width = "16")]
37933783
mod ptr_try_from_impls {
37943784
use super::TryFromIntError;
37953785
use convert::TryFrom;
37963786

3797-
try_from_upper_bounded!(usize, u8);
3798-
try_from_unbounded!(usize, u16, u32, u64, u128);
3799-
try_from_upper_bounded!(usize, i8, i16);
3800-
try_from_unbounded!(usize, i32, i64, i128);
3801-
3802-
try_from_both_bounded!(isize, u8);
3787+
// Fallible across platfoms, only implementation differs
38033788
try_from_lower_bounded!(isize, u16, u32, u64, u128);
3804-
try_from_both_bounded!(isize, i8);
3805-
try_from_unbounded!(isize, i16, i32, i64, i128);
3806-
3807-
rev!(try_from_unbounded, usize, u16);
3808-
rev!(try_from_upper_bounded, usize, u32, u64, u128);
38093789
rev!(try_from_lower_bounded, usize, i8, i16);
38103790
rev!(try_from_both_bounded, usize, i32, i64, i128);
3811-
3812-
rev!(try_from_unbounded, isize, u8);
3813-
rev!(try_from_upper_bounded, isize, u16, u32, u64, u128);
3814-
rev!(try_from_unbounded, isize, i16);
3815-
rev!(try_from_both_bounded, isize, i32, i64, i128);
38163791
}
38173792

38183793
#[cfg(target_pointer_width = "32")]
38193794
mod ptr_try_from_impls {
38203795
use super::TryFromIntError;
38213796
use convert::TryFrom;
38223797

3823-
try_from_upper_bounded!(usize, u8, u16);
3824-
try_from_unbounded!(usize, u32, u64, u128);
3825-
try_from_upper_bounded!(usize, i8, i16, i32);
3826-
try_from_unbounded!(usize, i64, i128);
3827-
3828-
try_from_both_bounded!(isize, u8, u16);
3798+
// Fallible across platfoms, only implementation differs
3799+
try_from_both_bounded!(isize, u16);
38293800
try_from_lower_bounded!(isize, u32, u64, u128);
3830-
try_from_both_bounded!(isize, i8, i16);
3831-
try_from_unbounded!(isize, i32, i64, i128);
3832-
3833-
rev!(try_from_unbounded, usize, u16, u32);
3834-
rev!(try_from_upper_bounded, usize, u64, u128);
38353801
rev!(try_from_lower_bounded, usize, i8, i16, i32);
38363802
rev!(try_from_both_bounded, usize, i64, i128);
3837-
3838-
rev!(try_from_unbounded, isize, u8, u16);
3839-
rev!(try_from_upper_bounded, isize, u32, u64, u128);
3840-
rev!(try_from_unbounded, isize, i16, i32);
3841-
rev!(try_from_both_bounded, isize, i64, i128);
38423803
}
38433804

38443805
#[cfg(target_pointer_width = "64")]
38453806
mod ptr_try_from_impls {
38463807
use super::TryFromIntError;
38473808
use convert::TryFrom;
38483809

3849-
try_from_upper_bounded!(usize, u8, u16, u32);
3850-
try_from_unbounded!(usize, u64, u128);
3851-
try_from_upper_bounded!(usize, i8, i16, i32, i64);
3852-
try_from_unbounded!(usize, i128);
3853-
3854-
try_from_both_bounded!(isize, u8, u16, u32);
3810+
// Fallible across platfoms, only implementation differs
3811+
try_from_both_bounded!(isize, u16, u32);
38553812
try_from_lower_bounded!(isize, u64, u128);
3856-
try_from_both_bounded!(isize, i8, i16, i32);
3857-
try_from_unbounded!(isize, i64, i128);
3858-
3859-
rev!(try_from_unbounded, usize, u16, u32, u64);
3860-
rev!(try_from_upper_bounded, usize, u128);
38613813
rev!(try_from_lower_bounded, usize, i8, i16, i32, i64);
38623814
rev!(try_from_both_bounded, usize, i128);
3863-
3864-
rev!(try_from_unbounded, isize, u8, u16, u32);
3865-
rev!(try_from_upper_bounded, isize, u64, u128);
3866-
rev!(try_from_unbounded, isize, i16, i32, i64);
3867-
rev!(try_from_both_bounded, isize, i128);
38683815
}
38693816

38703817
#[doc(hidden)]
@@ -4074,6 +4021,20 @@ impl_from! { u32, i64, #[stable(feature = "lossless_int_conv", since = "1.5.0")]
40744021
impl_from! { u32, i128, #[stable(feature = "i128", since = "1.26.0")] }
40754022
impl_from! { u64, i128, #[stable(feature = "i128", since = "1.26.0")] }
40764023

4024+
// The C99 standard defines bounds on INTPTR_MIN, INTPTR_MAX, and UINTPTR_MAX
4025+
// which imply that pointer-sized integers must be at least 16 bits:
4026+
// https://port70.net/~nsz/c/c99/n1256.html#7.18.2.4
4027+
impl_from! { u16, usize, #[stable(feature = "lossless_iusize_conv", since = "1.26.0")] }
4028+
impl_from! { u8, isize, #[stable(feature = "lossless_iusize_conv", since = "1.26.0")] }
4029+
impl_from! { i16, isize, #[stable(feature = "lossless_iusize_conv", since = "1.26.0")] }
4030+
4031+
// RISC-V defines the possibility of a 128-bit address space (RV128).
4032+
4033+
// CHERI proposes 256-bit “capabilities”. Unclear if this would be relevant to usize/isize.
4034+
// https://www.cl.cam.ac.uk/research/security/ctsrd/pdfs/20171017a-cheri-poster.pdf
4035+
// http://www.csl.sri.com/users/neumann/2012resolve-cheri.pdf
4036+
4037+
40774038
// Note: integers can only be represented with full precision in a float if
40784039
// they fit in the significand, which is 24 bits in f32 and 53 bits in f64.
40794040
// Lossy float conversions are not implemented at this time.

Diff for: src/libcore/prelude/v1.rs

+3
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ pub use cmp::{PartialEq, PartialOrd, Eq, Ord};
3939
#[stable(feature = "core_prelude", since = "1.4.0")]
4040
#[doc(no_inline)]
4141
pub use convert::{AsRef, AsMut, Into, From};
42+
#[stable(feature = "try_from", since = "1.26.0")]
43+
#[doc(no_inline)]
44+
pub use convert::{TryFrom, TryInto};
4245
#[stable(feature = "core_prelude", since = "1.4.0")]
4346
#[doc(no_inline)]
4447
pub use default::Default;

Diff for: src/libcore/tests/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
#![feature(step_trait)]
4444
#![feature(test)]
4545
#![feature(trusted_len)]
46-
#![feature(try_from)]
4746
#![feature(try_trait)]
4847
#![feature(exact_chunks)]
4948
#![feature(atomic_nand)]

0 commit comments

Comments
 (0)