Skip to content

Commit 6ce70b1

Browse files
committed
update Display to carry index
1 parent df0f1ae commit 6ce70b1

File tree

4 files changed

+9
-4
lines changed

4 files changed

+9
-4
lines changed

library/core/src/iter/traits/iterator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1588,7 +1588,7 @@ pub trait Iterator {
15881588
/// This will print:
15891589
///
15901590
/// ```text
1591-
/// Parsing error: invalid digit found in string
1591+
/// Parsing error: invalid digit found at index 0
15921592
/// Sum: 3
15931593
/// ```
15941594
#[inline]

library/core/src/num/error.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,11 @@ impl ParseIntError {
146146
#[stable(feature = "rust1", since = "1.0.0")]
147147
impl fmt::Display for ParseIntError {
148148
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
149-
self.__description().fmt(f)
149+
match self.kind {
150+
IntErrorKind::InvalidDigit(i) => {
151+
write!(f, "invalid digit found at index {}", i)
152+
}
153+
_ => self.__description().fmt(f),
154+
}
150155
}
151156
}

src/test/ui/feature-gates/unstable-attribute-allow-issue-0.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ error[E0545]: `issue` must be a non-zero numeric string or "none"
1212
LL | #[unstable(feature = "unstable_test_feature", issue = "something")]
1313
| ^^^^^^^^-----------
1414
| |
15-
| invalid digit found in string
15+
| invalid digit found at index 0
1616

1717
error: aborting due to 2 previous errors
1818

src/test/ui/stability-attribute/stability-attribute-sanity-2.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ error[E0545]: `issue` must be a non-zero numeric string or "none"
1616
LL | #[unstable(feature = "a", issue = "no")]
1717
| ^^^^^^^^----
1818
| |
19-
| invalid digit found in string
19+
| invalid digit found at index 0
2020

2121
error: aborting due to 3 previous errors
2222

0 commit comments

Comments
 (0)