Skip to content

Commit 7c581b0

Browse files
authored
Rollup merge of rust-lang#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.
2 parents 6d0d343 + 6d71aa4 commit 7c581b0

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/libcore/num/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3900,6 +3900,13 @@ fn from_str_radix<T: FromStrRadixHelper>(src: &str, radix: u32) -> Result<T, Par
39003900
/// This error is used as the error type for the `from_str_radix()` functions
39013901
/// on the primitive integer types, such as [`i8::from_str_radix`].
39023902
///
3903+
/// # Potential causes
3904+
///
3905+
/// Among other causes, `ParseIntError` can be thrown because of leading or trailing whitespace
3906+
/// in the string e.g. when it is obtained from the standard input.
3907+
/// Using the [`str.trim()`] method ensures that no whitespace remains before parsing.
3908+
///
3909+
/// [`str.trim()`]: ../../std/primitive.str.html#method.trim
39033910
/// [`i8::from_str_radix`]: ../../std/primitive.i8.html#method.from_str_radix
39043911
#[derive(Debug, Clone, PartialEq, Eq)]
39053912
#[stable(feature = "rust1", since = "1.0.0")]

0 commit comments

Comments
 (0)