]> git.lizzy.rs Git - rust.git/commitdiff
Incorporated review changes.
authorSimon Heath <icefox@dreamquest.io>
Wed, 27 Feb 2019 04:47:55 +0000 (23:47 -0500)
committerSimon Sapin <simon.sapin@exyr.org>
Wed, 27 Feb 2019 15:03:11 +0000 (16:03 +0100)
src/libcore/convert.rs
src/libcore/num/mod.rs

index a9d1d01ccbb41cc9a8001923b0204d9f3c213aa2..0fc182348c6c2f9d3ba5075c1f46808e6c6f1ea9 100644 (file)
@@ -406,7 +406,9 @@ pub trait TryInto<T>: Sized {
 /// - `TryFrom<T> for U` implies [`TryInto<U>`]` for T`
 /// - [`try_from`] is reflexive, which means that `TryFrom<T> for T`
 /// is implemented and cannot fail -- the associated `Error` type for
-/// calling `T::try_from()` on a value of type `T` is `!`.
+/// calling `T::try_from()` on a value of type `T` is `Infallible`.
+/// When the `!` type is stablized `Infallible` and `!` will be
+/// equivalent.
 ///
 /// # Examples
 ///
index d8e230abaf9b97dc184deb416b99bfeb55ac6596..4a2f958b93fe77c47ae6a07e64060a49e6e82056 100644 (file)
@@ -4544,9 +4544,14 @@ macro_rules! try_from_unbounded {
         impl TryFrom<$source> for $target {
             type Error = TryFromIntError;
 
-            /// Try to create the target type from the source type.
-            /// This particular variant will never fail, but is included
-            /// for completeness's sake.
+            /// Try to create the target number type from a source
+            /// number type.  If the source type has a larger range
+            /// than the target, or their ranges are disjoint (such
+            /// as converting a signed to unsigned number or vice 
+            /// versa), this will return `None` if the source value
+            /// doesn't fit into the range of the destination value.
+            /// If the conversion can never fail, this is still
+            /// implemented for completeness's sake.
             #[inline]
             fn try_from(value: $source) -> Result<Self, Self::Error> {
                 Ok(value as $target)
@@ -4562,10 +4567,14 @@ macro_rules! try_from_lower_bounded {
         impl TryFrom<$source> for $target {
             type Error = TryFromIntError;
 
-            /// Try to create a target number type from a
-            /// source type that has `source::MIN > dest::MIN`.
-            /// Will return an error if `source` is less than
-            /// `dest::MIN`.
+            /// Try to create the target number type from a source
+            /// number type.  If the source type has a larger range
+            /// than the target, or their ranges are disjoint (such
+            /// as converting a signed to unsigned number or vice 
+            /// versa), this will return `None` if the source value
+            /// doesn't fit into the range of the destination value.
+            /// If the conversion can never fail, this is still
+            /// implemented for completeness's sake.
             #[inline]
             fn try_from(u: $source) -> Result<$target, TryFromIntError> {
                 if u >= 0 {
@@ -4585,10 +4594,14 @@ macro_rules! try_from_upper_bounded {
         impl TryFrom<$source> for $target {
             type Error = TryFromIntError;
 
-            /// Try to create a target number type from a
-            /// source type that has `source::MAX > dest::MAX`.
-            /// Will return an error if `source` is greater than
-            /// `dest::MAX`.
+            /// Try to create the target number type from a source
+            /// number type.  If the source type has a larger range
+            /// than the target, or their ranges are disjoint (such
+            /// as converting a signed to unsigned number or vice 
+            /// versa), this will return `None` if the source value
+            /// doesn't fit into the range of the destination value.
+            /// If the conversion can never fail, this is still
+            /// implemented for completeness's sake.
             #[inline]
             fn try_from(u: $source) -> Result<$target, TryFromIntError> {
                 if u > (<$target>::max_value() as $source) {
@@ -4608,11 +4621,14 @@ macro_rules! try_from_both_bounded {
         impl TryFrom<$source> for $target {
             type Error = TryFromIntError;
 
-            /// Try to "narrow" a number from the source type
-            /// to the target type.  Will return an error if
-            /// the source value is either larger than the
-            /// `MAX` value for the target type or smaller
-            /// than the `MIN` value for it.
+            /// Try to create the target number type from a source
+            /// number type.  If the source type has a larger range
+            /// than the target, or their ranges are disjoint (such
+            /// as converting a signed to unsigned number or vice 
+            /// versa), this will return `None` if the source value
+            /// doesn't fit into the range of the destination value.
+            /// If the conversion can never fail, this is still
+            /// implemented for completeness's sake.
             #[inline]
             fn try_from(u: $source) -> Result<$target, TryFromIntError> {
                 let min = <$target>::min_value() as $source;