Skip to content

Commit 948a17e

Browse files
committed
Stop parsing "-" as integer, fixes #22745
1 parent 91a5a1a commit 948a17e

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

src/libcore/num/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1672,6 +1672,7 @@ macro_rules! from_str_radix_int_impl {
16721672
let is_signed_ty = (0 as $T) > Int::min_value();
16731673

16741674
match src.slice_shift_char() {
1675+
Some(('-', "")) => Err(PIE { kind: Empty }),
16751676
Some(('-', src)) if is_signed_ty => {
16761677
// The number is negative
16771678
let mut result = 0;

src/libcoretest/num/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,9 @@ mod test {
122122
assert_eq!("-9223372036854775808".parse::<i64>().ok(), Some(i64_val));
123123
assert_eq!("-9223372036854775809".parse::<i64>().ok(), None);
124124
}
125+
126+
#[test]
127+
test_int_from_minus_sign() {
128+
assert_eq!("-".parse::<i32>().ok(), None);
129+
}
125130
}

0 commit comments

Comments
 (0)