Stop parsing "-" as integer, fixes #22745
This commit is contained in:
parent
91a5a1ab4a
commit
948a17ed1d
@ -1672,6 +1672,7 @@ macro_rules! from_str_radix_int_impl {
|
||||
let is_signed_ty = (0 as $T) > Int::min_value();
|
||||
|
||||
match src.slice_shift_char() {
|
||||
Some(('-', "")) => Err(PIE { kind: Empty }),
|
||||
Some(('-', src)) if is_signed_ty => {
|
||||
// The number is negative
|
||||
let mut result = 0;
|
||||
|
@ -122,4 +122,9 @@ mod test {
|
||||
assert_eq!("-9223372036854775808".parse::<i64>().ok(), Some(i64_val));
|
||||
assert_eq!("-9223372036854775809".parse::<i64>().ok(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
test_int_from_minus_sign() {
|
||||
assert_eq!("-".parse::<i32>().ok(), None);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user