Skip to content

Commit

Permalink
update Display to carry index
Browse files Browse the repository at this point in the history
  • Loading branch information
eopb committed Mar 5, 2021
1 parent df0f1ae commit 6ce70b1
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion library/core/src/iter/traits/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1588,7 +1588,7 @@ pub trait Iterator {
/// This will print:
///
/// ```text
/// Parsing error: invalid digit found in string
/// Parsing error: invalid digit found at index 0
/// Sum: 3
/// ```
#[inline]
Expand Down
7 changes: 6 additions & 1 deletion library/core/src/num/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ impl ParseIntError {
#[stable(feature = "rust1", since = "1.0.0")]
impl fmt::Display for ParseIntError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.__description().fmt(f)
match self.kind {
IntErrorKind::InvalidDigit(i) => {
write!(f, "invalid digit found at index {}", i)
}
_ => self.__description().fmt(f),
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ error[E0545]: `issue` must be a non-zero numeric string or "none"
LL | #[unstable(feature = "unstable_test_feature", issue = "something")]
| ^^^^^^^^-----------
| |
| invalid digit found in string
| invalid digit found at index 0

error: aborting due to 2 previous errors

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ error[E0545]: `issue` must be a non-zero numeric string or "none"
LL | #[unstable(feature = "a", issue = "no")]
| ^^^^^^^^----
| |
| invalid digit found in string
| invalid digit found at index 0

error: aborting due to 3 previous errors

Expand Down

0 comments on commit 6ce70b1

Please sign in to comment.