Stop parsing "-" as integer, fixes #22745

This commit is contained in:
Michał Krasnoborski 2015-02-24 02:40:32 +01:00
parent 91a5a1ab4a
commit 948a17ed1d
2 changed files with 6 additions and 0 deletions

View File

@ -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;

View File

@ -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);
}
}