diff options
| author | Manish Goregaokar <manishsmail@gmail.com> | 2018-03-08 11:25:58 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-03-08 11:25:58 -0800 |
| commit | 7c581b08fa9a9b843ecee2a8af82b346da6fd42b (patch) | |
| tree | 8027925c13b66cb93e6583ddf6443aefaa71b41b | |
| parent | 6d0d34336d791d4e5c776d56fc1813b0929ee073 (diff) | |
| parent | 6d71aa47fbcaeb0493ac1bbc4408b513f6108fd0 (diff) | |
| download | rust-7c581b08fa9a9b843ecee2a8af82b346da6fd42b.tar.gz rust-7c581b08fa9a9b843ecee2a8af82b346da6fd42b.zip | |
Rollup merge of #48738 - Songbird0:parseinterror_potential_cause, r=joshtriplett
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.
| -rw-r--r-- | src/libcore/num/mod.rs | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index a46ac2b5f0f..09ab7060d37 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -3900,6 +3900,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 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. +/// +/// [`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")] |
