Skip to content

Commit 83d294f

Browse files
committed
Bring char along with InvalidDigit
1 parent c027844 commit 83d294f

File tree

5 files changed

+12
-12
lines changed

5 files changed

+12
-12
lines changed

compiler/rustc_middle/src/middle/limits.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ fn update_limit(
5252
IntErrorKind::Empty | IntErrorKind::OnlySign => {
5353
"`limit` must be a non-negative integer"
5454
}
55-
IntErrorKind::InvalidDigit => "not a valid integer",
55+
IntErrorKind::InvalidDigit(_) => "not a valid integer",
5656
IntErrorKind::NegOverflow => bug!("`limit` should never underflow"),
5757
IntErrorKind::Zero => bug!("zero is a valid `limit`"),
5858
kind => bug!("unimplemented IntErrorKind variant: {:?}", kind),

library/core/src/num/error.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,12 @@ pub enum IntErrorKind {
9292
/// Among other causes, this variant will be constructed when parsing an empty string.
9393
#[stable(feature = "int_error_matching", since = "1.47.0")]
9494
Empty,
95-
/// Contains an invalid digit.
95+
/// Contains an digit invalid in its context.
9696
///
9797
/// Among other causes, this variant will be constructed when parsing a string that
9898
/// contains a letter.
9999
#[stable(feature = "int_error_matching", since = "1.47.0")]
100-
InvalidDigit,
100+
InvalidDigit(#[stable(feature = "int_error_matching", since = "1.47.0")] char),
101101
/// Integer is too large to store in target integer type.
102102
#[stable(feature = "int_error_matching", since = "1.47.0")]
103103
PosOverflow,
@@ -131,7 +131,7 @@ impl ParseIntError {
131131
pub fn __description(&self) -> &str {
132132
match self.kind {
133133
IntErrorKind::Empty => "cannot parse integer from empty string",
134-
IntErrorKind::InvalidDigit => "invalid digit found in string",
134+
IntErrorKind::InvalidDigit(_) => "invalid digit found in string",
135135
IntErrorKind::PosOverflow => "number too large to fit in target type",
136136
IntErrorKind::NegOverflow => "number too small to fit in target type",
137137
IntErrorKind::Zero => "number would be zero for non-zero type",

library/core/src/num/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,7 @@ fn from_str_radix<T: FromStrRadixHelper>(src: &str, radix: u32) -> Result<T, Par
845845
for &c in digits {
846846
let x = match (c as char).to_digit(radix) {
847847
Some(x) => x,
848-
None => return Err(PIE { kind: InvalidDigit }),
848+
None => return Err(PIE { kind: InvalidDigit(c as char) }),
849849
};
850850
result = match result.checked_mul(radix) {
851851
Some(result) => result,
@@ -861,7 +861,7 @@ fn from_str_radix<T: FromStrRadixHelper>(src: &str, radix: u32) -> Result<T, Par
861861
for &c in digits {
862862
let x = match (c as char).to_digit(radix) {
863863
Some(x) => x,
864-
None => return Err(PIE { kind: InvalidDigit }),
864+
None => return Err(PIE { kind: InvalidDigit(c as char) }),
865865
};
866866
result = match result.checked_mul(radix) {
867867
Some(result) => result,

library/core/tests/nonzero.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ fn test_from_str() {
131131
assert_eq!("0".parse::<NonZeroU8>().err().map(|e| e.kind().clone()), Some(IntErrorKind::Zero));
132132
assert_eq!(
133133
"-1".parse::<NonZeroU8>().err().map(|e| e.kind().clone()),
134-
Some(IntErrorKind::InvalidDigit)
134+
Some(IntErrorKind::InvalidDigit('-'))
135135
);
136136
assert_eq!(
137137
"-129".parse::<NonZeroI8>().err().map(|e| e.kind().clone()),

library/core/tests/num/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,11 @@ fn test_leading_plus() {
117117

118118
#[test]
119119
fn test_invalid() {
120-
test_parse::<i8>("--129", Err(IntErrorKind::InvalidDigit));
121-
test_parse::<i8>("++129", Err(IntErrorKind::InvalidDigit));
122-
test_parse::<u8>("Съешь", Err(IntErrorKind::InvalidDigit));
123-
// is this the correct error here. Maybe need a reapeat sign error here
124-
test_parse::<i8>("--", Err(IntErrorKind::InvalidDigit));
120+
test_parse::<i8>("--129", Err(IntErrorKind::InvalidDigit('-')));
121+
test_parse::<i8>("++129", Err(IntErrorKind::InvalidDigit('+')));
122+
test_parse::<u8>("Съешь", Err(IntErrorKind::InvalidDigit('Ð')));
123+
test_parse::<u8>("123Hello", Err(IntErrorKind::InvalidDigit('H')));
124+
test_parse::<i8>("--", Err(IntErrorKind::InvalidDigit('-')));
125125
}
126126

127127
#[test]

0 commit comments

Comments
 (0)