From 2d1cd9ae80f1c6f5c1925f52bd69344bf63610c7 Mon Sep 17 00:00:00 2001 From: Ethan Brierley Date: Mon, 5 Nov 2018 17:23:34 +0000 Subject: [PATCH 01/12] Make `ParseIntError` and `IntErrorKind` fully public --- 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 c6cbeea5a0ea6..fada8efbd218d 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -4768,11 +4768,11 @@ fn from_str_radix(src: &str, radix: u32) -> Result Date: Mon, 5 Nov 2018 21:22:45 +0000 Subject: [PATCH 02/12] Add useful attributes --- src/libcore/num/mod.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index fada8efbd218d..02c7689e2b6c8 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -4771,7 +4771,10 @@ pub struct ParseIntError { pub kind: IntErrorKind, } +#[unstable(feature = "int_error_matching", + reason = "it can be useful to match errors when making error messages for integer parsing")] #[derive(Debug, Clone, PartialEq, Eq)] +#[non_exhaustive] pub enum IntErrorKind { Empty, InvalidDigit, From 420e6413c6124ba0c5032730af3ef50c7d2e2c95 Mon Sep 17 00:00:00 2001 From: Ethan Brierley Date: Mon, 5 Nov 2018 21:37:10 +0000 Subject: [PATCH 03/12] break line to keep `travis_fold:start:tidy` happy --- src/libcore/num/mod.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index 02c7689e2b6c8..c218713823a52 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -4772,7 +4772,8 @@ pub struct ParseIntError { } #[unstable(feature = "int_error_matching", - reason = "it can be useful to match errors when making error messages for integer parsing")] + reason = "it can be useful to match errors when making error messages \ + for integer parsing")] #[derive(Debug, Clone, PartialEq, Eq)] #[non_exhaustive] pub enum IntErrorKind { From b60efc1574fdba2504fdc903990a00893fd6d295 Mon Sep 17 00:00:00 2001 From: Ethan Brierley Date: Mon, 5 Nov 2018 21:57:19 +0000 Subject: [PATCH 04/12] Continue to try to make travis happy by adding a issue number --- src/libcore/num/mod.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index c218713823a52..7657b45f02468 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -4773,7 +4773,8 @@ pub struct ParseIntError { #[unstable(feature = "int_error_matching", reason = "it can be useful to match errors when making error messages \ - for integer parsing")] + for integer parsing", + issue = "22639")] #[derive(Debug, Clone, PartialEq, Eq)] #[non_exhaustive] pub enum IntErrorKind { From c3f0c9419e39a52758f99c156c41969341ff59da Mon Sep 17 00:00:00 2001 From: Ethan Brierley Date: Tue, 6 Nov 2018 08:34:30 +0000 Subject: [PATCH 05/12] Add very useful documentation --- src/libcore/num/mod.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index 7657b45f02468..b8f291f6d0503 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -4771,6 +4771,7 @@ pub struct ParseIntError { pub kind: IntErrorKind, } +/// Enum to store the various types of errors that can cause parsing an integer to fail. #[unstable(feature = "int_error_matching", reason = "it can be useful to match errors when making error messages \ for integer parsing", @@ -4778,9 +4779,16 @@ pub struct ParseIntError { #[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. Empty, + /// Contains an invalid digit. + /// Among other causes, this variant will be constructed when parsing a string that + /// contains a letter. InvalidDigit, + /// Integer is too small to store in target integer type. Overflow, + /// Integer is too large to store in target integer type. Underflow, } From 3dc56b7d9c81cdfb400cf6b937f12ee3b7e3b6b9 Mon Sep 17 00:00:00 2001 From: Ethan Brierley Date: Tue, 6 Nov 2018 08:37:25 +0000 Subject: [PATCH 06/12] Fix mistake in my markdown --- src/libcore/num/mod.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index b8f291f6d0503..f31ce033649ca 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -4780,9 +4780,11 @@ pub struct ParseIntError { #[non_exhaustive] pub enum IntErrorKind { /// Value being parsed is empty. + /// /// Among other causes, this variant will be constructed when parsing an empty string. Empty, /// Contains an invalid digit. + /// /// Among other causes, this variant will be constructed when parsing a string that /// contains a letter. InvalidDigit, From f1a593d1162dc399222c219a261bc95126e7fa62 Mon Sep 17 00:00:00 2001 From: Ethan Brierley Date: Tue, 6 Nov 2018 09:29:24 +0000 Subject: [PATCH 07/12] Document kind field --- src/libcore/num/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index f31ce033649ca..a7b6d719c6a01 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -4768,6 +4768,7 @@ fn from_str_radix(src: &str, radix: u32) -> Result Date: Wed, 7 Nov 2018 08:35:28 +0000 Subject: [PATCH 08/12] Use method rather than public field --- src/libcore/num/mod.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index a7b6d719c6a01..e297050f1f04e 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -4768,8 +4768,7 @@ fn from_str_radix(src: &str, radix: u32) -> Result IntErrorKind { + self.kind + } #[unstable(feature = "int_error_internals", reason = "available through Error trait and this method should \ not be exposed publicly", From d0bac148f7ae149ea93b1610fd2398fc1f00da65 Mon Sep 17 00:00:00 2001 From: Ethan Brierley Date: Wed, 7 Nov 2018 08:38:34 +0000 Subject: [PATCH 09/12] Fix incorrect documentation --- 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 e297050f1f04e..ad448af9af82a 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -4788,9 +4788,9 @@ pub enum IntErrorKind { /// Among other causes, this variant will be constructed when parsing a string that /// contains a letter. InvalidDigit, - /// Integer is too small to store in target integer type. - Overflow, /// Integer is too large to store in target integer type. + Overflow, + /// Integer is too small to store in target integer type. Underflow, } From 51e1f5560de3f9c8ae673c8014a5ed9547c1ce86 Mon Sep 17 00:00:00 2001 From: Ethan Brierley Date: Wed, 7 Nov 2018 08:48:37 +0000 Subject: [PATCH 10/12] add unstable attribute --- src/libcore/num/mod.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index ad448af9af82a..71617347e4c8a 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -4796,6 +4796,10 @@ pub enum IntErrorKind { impl ParseIntError { /// Outputs the detailed cause of parsing an integer failing. + #[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 } From 07b97a486f3580f9b50404a4199271f70b4a63fb Mon Sep 17 00:00:00 2001 From: Ethan Brierley Date: Sun, 25 Nov 2018 19:31:35 +0000 Subject: [PATCH 11/12] Use a reference rather than take ownership --- src/libcore/num/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index 71617347e4c8a..56ccea19b8a3f 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -4800,7 +4800,7 @@ impl ParseIntError { reason = "it can be useful to match errors when making error messages \ for integer parsing", issue = "22639")] - pub fn kind(self) -> IntErrorKind { + pub fn kind(&self) -> &IntErrorKind { self.kind } #[unstable(feature = "int_error_internals", From 121e5e806e41c4825fc4a25ad45d2585d1058165 Mon Sep 17 00:00:00 2001 From: Ethan Brierley Date: Sun, 25 Nov 2018 19:44:09 +0000 Subject: [PATCH 12/12] fix missing borrow --- src/libcore/num/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index 56ccea19b8a3f..eb8a51b18a5d2 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -4801,7 +4801,7 @@ impl ParseIntError { for integer parsing", issue = "22639")] pub fn kind(&self) -> &IntErrorKind { - self.kind + &self.kind } #[unstable(feature = "int_error_internals", reason = "available through Error trait and this method should \