From 80e3f8941d86bad0bd8d5551e6d066741ade1fc2 Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Tue, 29 Aug 2017 22:13:21 -0700 Subject: [PATCH 01/13] Add blanket TryFrom impl when From is implemented. Adds `impl TryFrom for U where U: From`. Removes `impl<'a, T> TryFrom<&'a str> for T where T: FromStr` due to overlapping impls caused by the new blanket impl. This removal is to be discussed further on the tracking issue for TryFrom. Refs #33417. --- src/libcore/convert.rs | 41 +++++++++++++++++++++++++++------------ src/libcore/iter/range.rs | 2 ++ src/libcore/num/mod.rs | 36 +++++++++------------------------- src/libcore/str/mod.rs | 7 ++----- 4 files changed, 42 insertions(+), 44 deletions(-) diff --git a/src/libcore/convert.rs b/src/libcore/convert.rs index 6f3c3863fae1d..37b5bfa265d5d 100644 --- a/src/libcore/convert.rs +++ b/src/libcore/convert.rs @@ -48,7 +48,24 @@ #![stable(feature = "rust1", since = "1.0.0")] -use str::FromStr; +use fmt; + +/// An uninhabited type used as the error type for implementations of fallible +/// conversion traits in cases where they cannot actually fail. +/// +/// Because `Infallible` has no constructors (variants), a value of this type +/// can never exist. It is used only to satisfy trait signatures that expect +/// an error type, and signals to both the compiler and the user that the error +/// case is impossible. +#[unstable(feature = "try_from", issue = "33417")] +pub enum Infallible {} + +#[unstable(feature = "try_from", issue = "33417")] +impl fmt::Debug for Infallible { + fn fmt(&self, _: &mut fmt::Formatter) -> fmt::Result { + match *self {} + } +} /// A cheap reference-to-reference conversion. Used to convert a value to a /// reference value within generic code. @@ -417,6 +434,17 @@ impl TryInto for T where U: TryFrom } } +// Infallible conversions are semantically equivalent to fallible conversions +// with an uninhabited error type. +#[unstable(feature = "try_from", issue = "33417")] +impl TryFrom for T where T: From { + type Error = Infallible; + + fn try_from(value: U) -> Result { + Ok(T::from(value)) + } +} + //////////////////////////////////////////////////////////////////////////////// // CONCRETE IMPLS //////////////////////////////////////////////////////////////////////////////// @@ -442,14 +470,3 @@ impl AsRef for str { self } } - -// FromStr implies TryFrom<&str> -#[unstable(feature = "try_from", issue = "33417")] -impl<'a, T> TryFrom<&'a str> for T where T: FromStr -{ - type Error = ::Err; - - fn try_from(s: &'a str) -> Result { - FromStr::from_str(s) - } -} diff --git a/src/libcore/iter/range.rs b/src/libcore/iter/range.rs index 73d518b570a11..e9aee4a4676de 100644 --- a/src/libcore/iter/range.rs +++ b/src/libcore/iter/range.rs @@ -89,6 +89,7 @@ macro_rules! step_impl_unsigned { } #[inline] + #[allow(unreachable_patterns)] fn add_usize(&self, n: usize) -> Option { match <$t>::try_from(n) { Ok(n_as_t) => self.checked_add(n_as_t), @@ -120,6 +121,7 @@ macro_rules! step_impl_signed { } #[inline] + #[allow(unreachable_patterns)] fn add_usize(&self, n: usize) -> Option { match <$unsigned>::try_from(n) { Ok(n_as_unsigned) => { diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index c5175287ccfa6..4777f9d72ccd7 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -2507,12 +2507,10 @@ impl fmt::Display for TryFromIntError { macro_rules! try_from_unbounded { ($source:ty, $($target:ty),*) => {$( #[unstable(feature = "try_from", issue = "33417")] - impl TryFrom<$source> for $target { - type Error = TryFromIntError; - + impl From<$source> for $target { #[inline] - fn try_from(u: $source) -> Result<$target, TryFromIntError> { - Ok(u as $target) + fn from(value: $source) -> $target { + value as $target } } )*} @@ -2584,31 +2582,17 @@ macro_rules! rev { } /// intra-sign conversions -try_from_unbounded!(u8, u8, u16, u32, u64, u128); -try_from_unbounded!(u16, u16, u32, u64, u128); -try_from_unbounded!(u32, u32, u64, u128); -try_from_unbounded!(u64, u64, u128); -try_from_unbounded!(u128, u128); try_from_upper_bounded!(u16, u8); try_from_upper_bounded!(u32, u16, u8); try_from_upper_bounded!(u64, u32, u16, u8); try_from_upper_bounded!(u128, u64, u32, u16, u8); -try_from_unbounded!(i8, i8, i16, i32, i64, i128); -try_from_unbounded!(i16, i16, i32, i64, i128); -try_from_unbounded!(i32, i32, i64, i128); -try_from_unbounded!(i64, i64, i128); -try_from_unbounded!(i128, i128); try_from_both_bounded!(i16, i8); try_from_both_bounded!(i32, i16, i8); try_from_both_bounded!(i64, i32, i16, i8); try_from_both_bounded!(i128, i64, i32, i16, i8); // unsigned-to-signed -try_from_unbounded!(u8, i16, i32, i64, i128); -try_from_unbounded!(u16, i32, i64, i128); -try_from_unbounded!(u32, i64, i128); -try_from_unbounded!(u64, i128); try_from_upper_bounded!(u8, i8); try_from_upper_bounded!(u16, i8, i16); try_from_upper_bounded!(u32, i8, i16, i32); @@ -2627,10 +2611,8 @@ try_from_both_bounded!(i64, u32, u16, u8); try_from_both_bounded!(i128, u64, u32, u16, u8); // usize/isize -try_from_unbounded!(usize, usize); try_from_upper_bounded!(usize, isize); try_from_lower_bounded!(isize, usize); -try_from_unbounded!(isize, isize); #[cfg(target_pointer_width = "16")] mod ptr_try_from_impls { @@ -2647,14 +2629,14 @@ mod ptr_try_from_impls { try_from_both_bounded!(isize, i8); try_from_unbounded!(isize, i16, i32, i64, i128); - rev!(try_from_unbounded, usize, u8, u16); + rev!(try_from_unbounded, usize, u16); rev!(try_from_upper_bounded, usize, u32, u64, u128); rev!(try_from_lower_bounded, usize, i8, i16); rev!(try_from_both_bounded, usize, i32, i64, i128); rev!(try_from_unbounded, isize, u8); rev!(try_from_upper_bounded, isize, u16, u32, u64, u128); - rev!(try_from_unbounded, isize, i8, i16); + rev!(try_from_unbounded, isize, i16); rev!(try_from_both_bounded, isize, i32, i64, i128); } @@ -2673,14 +2655,14 @@ mod ptr_try_from_impls { try_from_both_bounded!(isize, i8, i16); try_from_unbounded!(isize, i32, i64, i128); - rev!(try_from_unbounded, usize, u8, u16, u32); + rev!(try_from_unbounded, usize, u16, u32); rev!(try_from_upper_bounded, usize, u64, u128); rev!(try_from_lower_bounded, usize, i8, i16, i32); rev!(try_from_both_bounded, usize, i64, i128); rev!(try_from_unbounded, isize, u8, u16); rev!(try_from_upper_bounded, isize, u32, u64, u128); - rev!(try_from_unbounded, isize, i8, i16, i32); + rev!(try_from_unbounded, isize, i16, i32); rev!(try_from_both_bounded, isize, i64, i128); } @@ -2699,14 +2681,14 @@ mod ptr_try_from_impls { try_from_both_bounded!(isize, i8, i16, i32); try_from_unbounded!(isize, i64, i128); - rev!(try_from_unbounded, usize, u8, u16, u32, u64); + rev!(try_from_unbounded, usize, u16, u32, u64); rev!(try_from_upper_bounded, usize, u128); rev!(try_from_lower_bounded, usize, i8, i16, i32, i64); rev!(try_from_both_bounded, usize, i128); rev!(try_from_unbounded, isize, u8, u16, u32); rev!(try_from_upper_bounded, isize, u64, u128); - rev!(try_from_unbounded, isize, i8, i16, i32, i64); + rev!(try_from_unbounded, isize, i16, i32, i64); rev!(try_from_both_bounded, isize, i128); } diff --git a/src/libcore/str/mod.rs b/src/libcore/str/mod.rs index a5f6e49a53b4f..86a3b9f330bbb 100644 --- a/src/libcore/str/mod.rs +++ b/src/libcore/str/mod.rs @@ -18,7 +18,6 @@ use self::pattern::Pattern; use self::pattern::{Searcher, ReverseSearcher, DoubleEndedSearcher}; use char; -use convert::TryFrom; use fmt; use iter::{Map, Cloned, FusedIterator}; use slice::{self, SliceIndex}; @@ -2142,7 +2141,7 @@ pub trait StrExt { #[stable(feature = "core", since = "1.6.0")] fn is_empty(&self) -> bool; #[stable(feature = "core", since = "1.6.0")] - fn parse<'a, T: TryFrom<&'a str>>(&'a self) -> Result; + fn parse(&self) -> Result; } // truncate `&str` to length at most equal to `max` @@ -2462,9 +2461,7 @@ impl StrExt for str { fn is_empty(&self) -> bool { self.len() == 0 } #[inline] - fn parse<'a, T>(&'a self) -> Result where T: TryFrom<&'a str> { - T::try_from(self) - } + fn parse(&self) -> Result { FromStr::from_str(self) } } #[stable(feature = "rust1", since = "1.0.0")] From b0edfce9505f8fdbfb0b6ea035b2949bc36ece5b Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Wed, 30 Aug 2017 04:42:22 -0700 Subject: [PATCH 02/13] Implement TryFrom explicitly for infallible numeric conversions. See https://github.com/rust-lang/rust/pull/44174#discussion_r135982787 --- src/libcore/num/mod.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index 4777f9d72ccd7..4372646a56919 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -2507,10 +2507,12 @@ impl fmt::Display for TryFromIntError { macro_rules! try_from_unbounded { ($source:ty, $($target:ty),*) => {$( #[unstable(feature = "try_from", issue = "33417")] - impl From<$source> for $target { + impl TryFrom<$source> for $target { + type Error = Infallible; + #[inline] - fn from(value: $source) -> $target { - value as $target + fn try_from(value: $source) -> Result { + Ok(value as $target) } } )*} @@ -2617,7 +2619,7 @@ try_from_lower_bounded!(isize, usize); #[cfg(target_pointer_width = "16")] mod ptr_try_from_impls { use super::TryFromIntError; - use convert::TryFrom; + use convert::{Infallible, TryFrom}; try_from_upper_bounded!(usize, u8); try_from_unbounded!(usize, u16, u32, u64, u128); @@ -2643,7 +2645,7 @@ mod ptr_try_from_impls { #[cfg(target_pointer_width = "32")] mod ptr_try_from_impls { use super::TryFromIntError; - use convert::TryFrom; + use convert::{Infallible, TryFrom}; try_from_upper_bounded!(usize, u8, u16); try_from_unbounded!(usize, u32, u64, u128); @@ -2669,7 +2671,7 @@ mod ptr_try_from_impls { #[cfg(target_pointer_width = "64")] mod ptr_try_from_impls { use super::TryFromIntError; - use convert::TryFrom; + use convert::{Infallible, TryFrom}; try_from_upper_bounded!(usize, u8, u16, u32); try_from_unbounded!(usize, u64, u128); From 414ee9a2541d1a866864641c250367f0c28978be Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Wed, 30 Aug 2017 04:43:04 -0700 Subject: [PATCH 03/13] Remove test case that assumes FromStr provides TryFrom<&'a str>. See https://travis-ci.org/rust-lang/rust/jobs/269861252 --- src/libcore/tests/char.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libcore/tests/char.rs b/src/libcore/tests/char.rs index 7c3b90c81536e..4e10ceac878b6 100644 --- a/src/libcore/tests/char.rs +++ b/src/libcore/tests/char.rs @@ -32,7 +32,6 @@ fn test_convert() { #[test] fn test_from_str() { assert_eq!(char::from_str("a").unwrap(), 'a'); - assert_eq!(char::try_from("a").unwrap(), 'a'); assert_eq!(char::from_str("\0").unwrap(), '\0'); assert_eq!(char::from_str("\u{D7FF}").unwrap(), '\u{d7FF}'); assert!(char::from_str("").is_err()); From 36c0ff8690621f44b7bed31da96fbc64a101c2af Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Fri, 1 Sep 2017 00:26:37 -0700 Subject: [PATCH 04/13] Reword docs for Infallible to make them easier to understand. --- src/libcore/convert.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/libcore/convert.rs b/src/libcore/convert.rs index 37b5bfa265d5d..d3a86f7f3e3ad 100644 --- a/src/libcore/convert.rs +++ b/src/libcore/convert.rs @@ -50,13 +50,12 @@ use fmt; -/// An uninhabited type used as the error type for implementations of fallible -/// conversion traits in cases where they cannot actually fail. +/// A type used as the error type for implementations of fallible conversion +/// traits in cases where conversions cannot actually fail. /// -/// Because `Infallible` has no constructors (variants), a value of this type -/// can never exist. It is used only to satisfy trait signatures that expect -/// an error type, and signals to both the compiler and the user that the error -/// case is impossible. +/// Because `Infallible` has no variants, a value of this type can never exist. +/// It is used only to satisfy trait signatures that expect an error type, and +/// signals to both the compiler and the user that the error case is impossible. #[unstable(feature = "try_from", issue = "33417")] pub enum Infallible {} From 93a56cdacd29e8b29bae45c3abca229f6011a492 Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Fri, 1 Sep 2017 01:57:05 -0700 Subject: [PATCH 05/13] impl From for TryFromIntError. --- src/libcore/num/mod.rs | 9 ++++++++- src/libcore/tests/num/mod.rs | 10 +++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index 4372646a56919..9f87e2bd8316d 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -12,7 +12,7 @@ #![stable(feature = "rust1", since = "1.0.0")] -use convert::TryFrom; +use convert::{Infallible, TryFrom}; use fmt; use intrinsics; use str::FromStr; @@ -2503,6 +2503,13 @@ impl fmt::Display for TryFromIntError { } } +#[unstable(feature = "try_from", issue = "33417")] +impl From for TryFromIntError { + fn from(_: Infallible) -> TryFromIntError { + TryFromIntError(()) + } +} + // no possible bounds violation macro_rules! try_from_unbounded { ($source:ty, $($target:ty),*) => {$( diff --git a/src/libcore/tests/num/mod.rs b/src/libcore/tests/num/mod.rs index 400d53ce51a08..7eb5ff9885777 100644 --- a/src/libcore/tests/num/mod.rs +++ b/src/libcore/tests/num/mod.rs @@ -8,10 +8,11 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use core::convert::TryFrom; +use core::convert::{TryFrom, TryInto}; use core::cmp::PartialEq; use core::fmt::Debug; use core::marker::Copy; +use core::num::TryFromIntError; use core::ops::{Add, Sub, Mul, Div, Rem}; use core::option::Option; use core::option::Option::{Some, None}; @@ -134,6 +135,13 @@ fn test_empty() { assert_eq!("".parse::().ok(), None); } +#[test] +fn test_infallible_try_from_int_error() { + let func = |x: i8| -> Result { Ok(x.try_into()?) }; + + assert!(func(0).is_ok()); +} + macro_rules! test_impl_from { ($fn_name: ident, $Small: ty, $Large: ty) => { #[test] From 5f6de3d40238aa253b7dc4dd037599ef9e29999f Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Mon, 18 Sep 2017 22:19:00 -0700 Subject: [PATCH 06/13] Derive additional traits for Infallible. --- src/libcore/convert.rs | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/libcore/convert.rs b/src/libcore/convert.rs index d3a86f7f3e3ad..9730de0efe9e2 100644 --- a/src/libcore/convert.rs +++ b/src/libcore/convert.rs @@ -48,8 +48,6 @@ #![stable(feature = "rust1", since = "1.0.0")] -use fmt; - /// A type used as the error type for implementations of fallible conversion /// traits in cases where conversions cannot actually fail. /// @@ -57,15 +55,9 @@ use fmt; /// It is used only to satisfy trait signatures that expect an error type, and /// signals to both the compiler and the user that the error case is impossible. #[unstable(feature = "try_from", issue = "33417")] +#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] pub enum Infallible {} -#[unstable(feature = "try_from", issue = "33417")] -impl fmt::Debug for Infallible { - fn fmt(&self, _: &mut fmt::Formatter) -> fmt::Result { - match *self {} - } -} - /// A cheap reference-to-reference conversion. Used to convert a value to a /// reference value within generic code. /// From 9562981b0b6dc2d7ae6070732778623a59cfdd0a Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Thu, 21 Sep 2017 20:21:54 -0700 Subject: [PATCH 07/13] impl std::error::Error for convert::Infallible. --- src/libstd/error.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/libstd/error.rs b/src/libstd/error.rs index 401552a6ec417..5cb2b00334db3 100644 --- a/src/libstd/error.rs +++ b/src/libstd/error.rs @@ -55,6 +55,7 @@ use alloc::allocator; use any::TypeId; use cell; use char; +use convert; use fmt::{self, Debug, Display}; use mem::transmute; use num; @@ -347,6 +348,12 @@ impl Error for char::ParseCharError { } } +#[unstable(feature = "try_from", issue = "33417")] +impl Error for convert::Infallible { + fn description(&self) -> &str { + "an error of this type can never exist" + } +} // copied from any.rs impl Error + 'static { From 79f2439aa698c7eefa089ad05027826d7911780f Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Thu, 21 Sep 2017 21:03:40 -0700 Subject: [PATCH 08/13] Impl fmt::Display for convert::Infallible. --- src/libcore/convert.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/libcore/convert.rs b/src/libcore/convert.rs index 9730de0efe9e2..6eb499ad8ab23 100644 --- a/src/libcore/convert.rs +++ b/src/libcore/convert.rs @@ -48,6 +48,8 @@ #![stable(feature = "rust1", since = "1.0.0")] +use fmt; + /// A type used as the error type for implementations of fallible conversion /// traits in cases where conversions cannot actually fail. /// @@ -58,6 +60,12 @@ #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] pub enum Infallible {} +#[unstable(feature = "try_from", issue = "33417")] +impl fmt::Display for Infallible { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + "an error of this type can never exist".fmt(f) + } +} /// A cheap reference-to-reference conversion. Used to convert a value to a /// reference value within generic code. /// From 4d2a8c527880a56db3b410450fa2b6cbf0cbe3a8 Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Sat, 23 Sep 2017 17:08:16 -0700 Subject: [PATCH 09/13] Simplify implementation of Display and Error for convert::Infallible. --- src/libcore/convert.rs | 5 +++-- src/libstd/error.rs | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/libcore/convert.rs b/src/libcore/convert.rs index 6eb499ad8ab23..e815d72d36646 100644 --- a/src/libcore/convert.rs +++ b/src/libcore/convert.rs @@ -62,8 +62,9 @@ pub enum Infallible {} #[unstable(feature = "try_from", issue = "33417")] impl fmt::Display for Infallible { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - "an error of this type can never exist".fmt(f) + fn fmt(&self, _: &mut fmt::Formatter) -> fmt::Result { + match *self { + } } } /// A cheap reference-to-reference conversion. Used to convert a value to a diff --git a/src/libstd/error.rs b/src/libstd/error.rs index 5cb2b00334db3..6a4de4ecbffd4 100644 --- a/src/libstd/error.rs +++ b/src/libstd/error.rs @@ -351,7 +351,8 @@ impl Error for char::ParseCharError { #[unstable(feature = "try_from", issue = "33417")] impl Error for convert::Infallible { fn description(&self) -> &str { - "an error of this type can never exist" + match *self { + } } } From ba74a8665d2b7771b6fd0499dc050c1bf075fca9 Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Sat, 23 Sep 2017 17:19:18 -0700 Subject: [PATCH 10/13] Add back mistakenly removed numeric conversions. --- src/libcore/num/mod.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index 9f87e2bd8316d..cfa22360e9e17 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -2638,14 +2638,14 @@ mod ptr_try_from_impls { try_from_both_bounded!(isize, i8); try_from_unbounded!(isize, i16, i32, i64, i128); - rev!(try_from_unbounded, usize, u16); + rev!(try_from_unbounded, usize, u8, u16); rev!(try_from_upper_bounded, usize, u32, u64, u128); rev!(try_from_lower_bounded, usize, i8, i16); rev!(try_from_both_bounded, usize, i32, i64, i128); rev!(try_from_unbounded, isize, u8); rev!(try_from_upper_bounded, isize, u16, u32, u64, u128); - rev!(try_from_unbounded, isize, i16); + rev!(try_from_unbounded, isize, i8, i16); rev!(try_from_both_bounded, isize, i32, i64, i128); } @@ -2664,14 +2664,14 @@ mod ptr_try_from_impls { try_from_both_bounded!(isize, i8, i16); try_from_unbounded!(isize, i32, i64, i128); - rev!(try_from_unbounded, usize, u16, u32); + rev!(try_from_unbounded, usize, u8, u16, u32); rev!(try_from_upper_bounded, usize, u64, u128); rev!(try_from_lower_bounded, usize, i8, i16, i32); rev!(try_from_both_bounded, usize, i64, i128); rev!(try_from_unbounded, isize, u8, u16); rev!(try_from_upper_bounded, isize, u32, u64, u128); - rev!(try_from_unbounded, isize, i16, i32); + rev!(try_from_unbounded, isize, i8, i16, i32); rev!(try_from_both_bounded, isize, i64, i128); } From 1a29e822274c69efbf2b8177e7702a4136897050 Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Thu, 28 Sep 2017 23:46:19 -0700 Subject: [PATCH 11/13] Remove conflicting TryFrom impls on 32-bit targets. --- src/libcore/num/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index cfa22360e9e17..6489d0d192a2e 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -2664,12 +2664,12 @@ mod ptr_try_from_impls { try_from_both_bounded!(isize, i8, i16); try_from_unbounded!(isize, i32, i64, i128); - rev!(try_from_unbounded, usize, u8, u16, u32); + rev!(try_from_unbounded, usize, u16, u32); rev!(try_from_upper_bounded, usize, u64, u128); rev!(try_from_lower_bounded, usize, i8, i16, i32); rev!(try_from_both_bounded, usize, i64, i128); - rev!(try_from_unbounded, isize, u8, u16); + rev!(try_from_unbounded, isize, u16); rev!(try_from_upper_bounded, isize, u32, u64, u128); rev!(try_from_unbounded, isize, i8, i16, i32); rev!(try_from_both_bounded, isize, i64, i128); From 966cf339cbf83500775e195c23d420582c9d0f48 Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Fri, 29 Sep 2017 14:04:28 -0700 Subject: [PATCH 12/13] Simplify implementation of From for TryFromIntError. --- src/libcore/num/mod.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index 6489d0d192a2e..0b226f84eabfb 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -2505,8 +2505,9 @@ impl fmt::Display for TryFromIntError { #[unstable(feature = "try_from", issue = "33417")] impl From for TryFromIntError { - fn from(_: Infallible) -> TryFromIntError { - TryFromIntError(()) + fn from(infallible: Infallible) -> TryFromIntError { + match infallible { + } } } From 27d95d3645761252caf42c77fc53b76b4278520a Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Fri, 29 Sep 2017 14:10:26 -0700 Subject: [PATCH 13/13] Fix more TryFrom impls for integers. --- src/libcore/num/mod.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index 0b226f84eabfb..23538ecab4fa3 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -2639,14 +2639,14 @@ mod ptr_try_from_impls { try_from_both_bounded!(isize, i8); try_from_unbounded!(isize, i16, i32, i64, i128); - rev!(try_from_unbounded, usize, u8, u16); + rev!(try_from_unbounded, usize, u16); rev!(try_from_upper_bounded, usize, u32, u64, u128); rev!(try_from_lower_bounded, usize, i8, i16); rev!(try_from_both_bounded, usize, i32, i64, i128); rev!(try_from_unbounded, isize, u8); rev!(try_from_upper_bounded, isize, u16, u32, u64, u128); - rev!(try_from_unbounded, isize, i8, i16); + rev!(try_from_unbounded, isize, i16); rev!(try_from_both_bounded, isize, i32, i64, i128); } @@ -2670,9 +2670,9 @@ mod ptr_try_from_impls { rev!(try_from_lower_bounded, usize, i8, i16, i32); rev!(try_from_both_bounded, usize, i64, i128); - rev!(try_from_unbounded, isize, u16); + rev!(try_from_unbounded, isize, u8, u16); rev!(try_from_upper_bounded, isize, u32, u64, u128); - rev!(try_from_unbounded, isize, i8, i16, i32); + rev!(try_from_unbounded, isize, i16, i32); rev!(try_from_both_bounded, isize, i64, i128); }