From c68440cad49f6d0cda09f8c7d4989ff63f55a26e Mon Sep 17 00:00:00 2001 From: Songbird0 <Songbird0@users.noreply.github.com> Date: Sun, 4 Mar 2018 21:59:53 +0100 Subject: [PATCH 1/4] Add a potential cause raising `ParseIntError`. Initially, I wanted to add it directly to the documentation of `str. parse()' method, I finally found that it was more relevant (I hope so?) to directly document the structure in question. I've added a scenario, in which we could all get caught at least once, to make it easier to diagnose the problem when parsing integers. --- src/libcore/num/mod.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index 59a67fff48c..1b51ebefb60 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -3845,7 +3845,13 @@ fn from_str_radix<T: FromStrRadixHelper>(src: &str, radix: u32) -> Result<T, Par /// /// This error is used as the error type for the `from_str_radix()` functions /// on the primitive integer types, such as [`i8::from_str_radix`]. +/// +/// # Potential causes /// +/// Among other causes, `ParseIntError` can be thrown because of leading or trailing whitespaces in the string e.g. when it is getted from the standard input. +/// Using the [`str.trim()`] method ensures that no whitespace remains before parsing. +/// +/// [`str.trim()`]: ../../std/primitive.str.html#method.trim /// [`i8::from_str_radix`]: ../../std/primitive.i8.html#method.from_str_radix #[derive(Debug, Clone, PartialEq, Eq)] #[stable(feature = "rust1", since = "1.0.0")] From 247fc38aebf752528078349f913764ba6a8edf59 Mon Sep 17 00:00:00 2001 From: Songbird0 <Songbird0@users.noreply.github.com> Date: Sun, 4 Mar 2018 22:18:42 +0100 Subject: [PATCH 2/4] Tidy error: add a new line The error was: ``` [00:05:25] tidy error: /checkout/src/libcore/num/mod.rs:3848: trailing whitespace [00:05:25] tidy error: /checkout/src/libcore/num/mod.rs:3851: line longer than 100 chars [00:05:25] tidy error: /checkout/src/libcore/num/mod.rs:3851: trailing whitespace [00:05:26] some tidy checks failed ``` The line was truncated to 92 characters. --- 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 1b51ebefb60..00a46dca876 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -3848,7 +3848,8 @@ fn from_str_radix<T: FromStrRadixHelper>(src: &str, radix: u32) -> Result<T, Par /// /// # Potential causes /// -/// Among other causes, `ParseIntError` can be thrown because of leading or trailing whitespaces in the string e.g. when it is getted from the standard input. +/// Among other causes, `ParseIntError` can be thrown because of leading or trailing whitespaces +/// in the string e.g. when it is getted from the standard input. /// Using the [`str.trim()`] method ensures that no whitespace remains before parsing. /// /// [`str.trim()`]: ../../std/primitive.str.html#method.trim From ef1aae1cc2310ae6c05bed273da55a9ba85b1ef5 Mon Sep 17 00:00:00 2001 From: Songbird0 <Songbird0@users.noreply.github.com> Date: Mon, 5 Mar 2018 03:57:33 +0100 Subject: [PATCH 3/4] Modify wording and remove useless whitespaces. --- src/libcore/num/mod.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index 00a46dca876..8b43aeefade 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -3845,11 +3845,11 @@ fn from_str_radix<T: FromStrRadixHelper>(src: &str, radix: u32) -> Result<T, Par /// /// This error is used as the error type for the `from_str_radix()` functions /// on the primitive integer types, such as [`i8::from_str_radix`]. -/// +/// /// # Potential causes /// -/// Among other causes, `ParseIntError` can be thrown because of leading or trailing whitespaces -/// in the string e.g. when it is getted from the standard input. +/// Among other causes, `ParseIntError` can be thrown because of leading or trailing whitespaces +/// in the string e.g. when it is obtained from the standard input. /// Using the [`str.trim()`] method ensures that no whitespace remains before parsing. /// /// [`str.trim()`]: ../../std/primitive.str.html#method.trim From 6d71aa47fbcaeb0493ac1bbc4408b513f6108fd0 Mon Sep 17 00:00:00 2001 From: Songbird0 <Songbird0@users.noreply.github.com> Date: Mon, 5 Mar 2018 14:33:37 +0100 Subject: [PATCH 4/4] Fix spelling error for `whitespaces`. --- 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 8b43aeefade..929d6ef4c20 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -3848,7 +3848,7 @@ fn from_str_radix<T: FromStrRadixHelper>(src: &str, radix: u32) -> Result<T, Par /// /// # Potential causes /// -/// Among other causes, `ParseIntError` can be thrown because of leading or trailing whitespaces +/// Among other causes, `ParseIntError` can be thrown because of leading or trailing whitespace /// in the string e.g. when it is obtained from the standard input. /// Using the [`str.trim()`] method ensures that no whitespace remains before parsing. ///