]> git.lizzy.rs Git - rust.git/commitdiff
Apply suggested changes
authorEthan Brierley <ethanboxx@gmail.com>
Mon, 26 Oct 2020 18:14:12 +0000 (18:14 +0000)
committerEthan Brierley <ethanboxx@gmail.com>
Mon, 26 Oct 2020 18:14:12 +0000 (18:14 +0000)
compiler/rustc_middle/src/lib.rs
compiler/rustc_middle/src/middle/limits.rs
library/core/src/lib.rs
library/core/src/num/error.rs
library/core/src/num/mod.rs
library/core/tests/lib.rs
library/core/tests/nonzero.rs
library/core/tests/num/mod.rs
library/std/src/lib.rs
library/std/src/num.rs

index 37bc1a305b2f84ffc417b0f7c3d6542ea9151c6a..fa885ce2e7cdfb4ded4be2cd0090a3cc352746e7 100644 (file)
@@ -46,6 +46,7 @@
 #![feature(crate_visibility_modifier)]
 #![feature(associated_type_bounds)]
 #![feature(rustc_attrs)]
+#![feature(int_error_matching)]
 #![recursion_limit = "512"]
 
 #[macro_use]
index e0d171fa77125cf0bf52e1137f17566751b185e3..9ff2b7f08fe04d824ec93c59803c0e7848fab481 100644 (file)
@@ -50,8 +50,10 @@ fn update_limit(
                     let error_str = match e.kind() {
                         IntErrorKind::PosOverflow => "`limit` is too large",
                         IntErrorKind::Empty => "`limit` must be a non-negative integer",
-                        IntErrorKind::InvalidDigit(_) => "not a valid integer",
-                        IntErrorKind::NegOverflow => bug!("`limit` should never underflow"),
+                        IntErrorKind::InvalidDigit => "not a valid integer",
+                        IntErrorKind::NegOverflow => {
+                            bug!("`limit` should never negatively underflow")
+                        }
                         IntErrorKind::Zero => bug!("zero is a valid `limit`"),
                         kind => bug!("unimplemented IntErrorKind variant: {:?}", kind),
                     };
index 63ca6e517d214edf4cef59bc5b8c39e077ec88a7..d67ad30e123f95fd5564e7f54cd428810bed6584 100644 (file)
 #![feature(slice_ptr_get)]
 #![feature(no_niche)] // rust-lang/rust#68303
 #![feature(unsafe_block_in_unsafe_fn)]
+#![feature(int_error_matching)]
 #![deny(unsafe_op_in_unsafe_fn)]
 
 #[prelude_import]
index e1684719ab4ec27a061375f3dddef29781ba5505..9d8c8c862911c21bac4ce60cb482912ed41ea289 100644 (file)
@@ -77,20 +77,26 @@ pub struct ParseIntError {
 /// # Example
 ///
 /// ```
+/// #![feature(int_error_matching)]
+///
 /// # fn main() {
 /// if let Err(e) = i32::from_str_radix("a12", 10) {
 ///     println!("Failed conversion to i32: {:?}", e.kind());
 /// }
 /// # }
 /// ```
-#[stable(feature = "int_error_matching", since = "1.47.0")]
+#[unstable(
+    feature = "int_error_matching",
+    reason = "it can be useful to match errors when making error messages \
+              for integer parsing",
+    issue = "22639"
+)]
 #[derive(Debug, Clone, PartialEq, Eq)]
 #[non_exhaustive]
 pub enum IntErrorKind {
     /// Value being parsed is empty.
     ///
     /// Among other causes, this variant will be constructed when parsing an empty string.
-    #[stable(feature = "int_error_matching", since = "1.47.0")]
     Empty,
     /// Contains an invalid digit in its context.
     ///
@@ -99,25 +105,26 @@ pub enum IntErrorKind {
     ///
     /// This variant is also constructed when a `+` or `-` is misplaced within a string
     /// either on its own or in the middle of a number.
-    #[stable(feature = "int_error_matching", since = "1.47.0")]
-    InvalidDigit(#[stable(feature = "int_error_matching", since = "1.47.0")] char),
+    InvalidDigit,
     /// Integer is too large to store in target integer type.
-    #[stable(feature = "int_error_matching", since = "1.47.0")]
     PosOverflow,
     /// Integer is too small to store in target integer type.
-    #[stable(feature = "int_error_matching", since = "1.47.0")]
     NegOverflow,
     /// Value was Zero
     ///
     /// This variant will be emitted when the parsing string has a value of zero, which
     /// would be illegal for non-zero types.
-    #[stable(feature = "int_error_matching", since = "1.47.0")]
     Zero,
 }
 
 impl ParseIntError {
     /// Outputs the detailed cause of parsing an integer failing.
-    #[stable(feature = "int_error_matching", since = "1.47.0")]
+    #[unstable(
+        feature = "int_error_matching",
+        reason = "it can be useful to match errors when making error messages \
+              for integer parsing",
+        issue = "22639"
+    )]
     pub fn kind(&self) -> &IntErrorKind {
         &self.kind
     }
@@ -131,7 +138,7 @@ pub fn kind(&self) -> &IntErrorKind {
     pub fn __description(&self) -> &str {
         match self.kind {
             IntErrorKind::Empty => "cannot parse integer from empty string",
-            IntErrorKind::InvalidDigit(_) => "invalid digit found in string",
+            IntErrorKind::InvalidDigit => "invalid digit found in string",
             IntErrorKind::PosOverflow => "number too large to fit in target type",
             IntErrorKind::NegOverflow => "number too small to fit in target type",
             IntErrorKind::Zero => "number would be zero for non-zero type",
index fd00a072d896c903b537a9ee4d1e139e00247ce5..71448a622c09e0bb03a88830239118a390bd3388 100644 (file)
@@ -63,7 +63,12 @@ macro_rules! doc_comment {
 #[stable(feature = "try_from", since = "1.34.0")]
 pub use error::TryFromIntError;
 
-#[stable(feature = "int_error_matching", since = "1.47.0")]
+#[unstable(
+    feature = "int_error_matching",
+    reason = "it can be useful to match errors when making error messages \
+              for integer parsing",
+    issue = "22639"
+)]
 pub use error::IntErrorKind;
 
 macro_rules! usize_isize_to_xe_bytes_doc {
@@ -831,7 +836,7 @@ fn from_str_radix<T: FromStrRadixHelper>(src: &str, radix: u32) -> Result<T, Par
 
     let (is_positive, digits) = match src[0] {
         b'+' | b'-' if src[1..].is_empty() => {
-            return Err(PIE { kind: InvalidDigit(src[0] as char) });
+            return Err(PIE { kind: InvalidDigit });
         }
         b'+' => (true, &src[1..]),
         b'-' if is_signed_ty => (false, &src[1..]),
@@ -844,7 +849,7 @@ fn from_str_radix<T: FromStrRadixHelper>(src: &str, radix: u32) -> Result<T, Par
         for &c in digits {
             let x = match (c as char).to_digit(radix) {
                 Some(x) => x,
-                None => return Err(PIE { kind: InvalidDigit(c as char) }),
+                None => return Err(PIE { kind: InvalidDigit }),
             };
             result = match result.checked_mul(radix) {
                 Some(result) => result,
@@ -860,7 +865,7 @@ fn from_str_radix<T: FromStrRadixHelper>(src: &str, radix: u32) -> Result<T, Par
         for &c in digits {
             let x = match (c as char).to_digit(radix) {
                 Some(x) => x,
-                None => return Err(PIE { kind: InvalidDigit(c as char) }),
+                None => return Err(PIE { kind: InvalidDigit }),
             };
             result = match result.checked_mul(radix) {
                 Some(result) => result,
index c128691fa75253ea04b69745eb927ba9f9dd0314..d8b36beb3e0856585939f7e91f7b24497751fc3f 100644 (file)
@@ -37,6 +37,7 @@
 #![feature(try_trait)]
 #![feature(slice_internals)]
 #![feature(slice_partition_dedup)]
+#![feature(int_error_matching)]
 #![feature(array_value_iter)]
 #![feature(iter_partition_in_place)]
 #![feature(iter_is_partitioned)]
index 949d4ea32f06463f7d6ca1b339b5bb1b0967dccb..fb1293c99bba934748dd13362c0a994eea41d833 100644 (file)
@@ -131,7 +131,7 @@ fn test_from_str() {
     assert_eq!("0".parse::<NonZeroU8>().err().map(|e| e.kind().clone()), Some(IntErrorKind::Zero));
     assert_eq!(
         "-1".parse::<NonZeroU8>().err().map(|e| e.kind().clone()),
-        Some(IntErrorKind::InvalidDigit('-'))
+        Some(IntErrorKind::InvalidDigit)
     );
     assert_eq!(
         "-129".parse::<NonZeroI8>().err().map(|e| e.kind().clone()),
index 12e52252278c543aa0e7ac6e8a85c44315e41aad..7c25c32fb40a717cc67741aff69a546098f3125e 100644 (file)
@@ -118,14 +118,14 @@ fn test_leading_plus() {
 
 #[test]
 fn test_invalid() {
-    test_parse::<i8>("--129", Err(IntErrorKind::InvalidDigit('-')));
-    test_parse::<i8>("++129", Err(IntErrorKind::InvalidDigit('+')));
-    test_parse::<u8>("Съешь", Err(IntErrorKind::InvalidDigit('Ð')));
-    test_parse::<u8>("123Hello", Err(IntErrorKind::InvalidDigit('H')));
-    test_parse::<i8>("--", Err(IntErrorKind::InvalidDigit('-')));
-    test_parse::<i8>("-", Err(IntErrorKind::InvalidDigit('-')));
-    test_parse::<i8>("+", Err(IntErrorKind::InvalidDigit('+')));
-    test_parse::<u8>("-1", Err(IntErrorKind::InvalidDigit('-')));
+    test_parse::<i8>("--129", Err(IntErrorKind::InvalidDigit));
+    test_parse::<i8>("++129", Err(IntErrorKind::InvalidDigit));
+    test_parse::<u8>("Съешь", Err(IntErrorKind::InvalidDigit));
+    test_parse::<u8>("123Hello", Err(IntErrorKind::InvalidDigit));
+    test_parse::<i8>("--", Err(IntErrorKind::InvalidDigit));
+    test_parse::<i8>("-", Err(IntErrorKind::InvalidDigit));
+    test_parse::<i8>("+", Err(IntErrorKind::InvalidDigit));
+    test_parse::<u8>("-1", Err(IntErrorKind::InvalidDigit));
 }
 
 #[test]
index fa23229066cf1af563adb9d7f7edbb71df2b2fc4..ac0075ad129c5778e0fe27ace2057edfac1366f1 100644 (file)
 #![feature(global_asm)]
 #![feature(hashmap_internals)]
 #![feature(int_error_internals)]
+#![feature(int_error_matching)]
 #![feature(integer_atomics)]
 #![feature(into_future)]
 #![feature(lang_items)]
index ac3b055cdb0506d4d26fd3a3495d8cdbf1301a87..0f1c59626859411ee501d47abe7715d19c63ff02 100644 (file)
 #[stable(feature = "nonzero", since = "1.28.0")]
 pub use core::num::{NonZeroU128, NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU8, NonZeroUsize};
 
-#[stable(feature = "int_error_matching", since = "1.47.0")]
+#[unstable(
+    feature = "int_error_matching",
+    reason = "it can be useful to match errors when making error messages \
+              for integer parsing",
+    issue = "22639"
+)]
 pub use core::num::IntErrorKind;
 
 #[cfg(test)]