Re: [PATCH v2 0/2] rust: str: parse_int: match kstrtol() sign and newline handling
From: Andreas Hindborg
Date: Mon Nov 02 2026 - 10:41:28 EST
"Younes Akhouayri via B4 Relay" <devnull+git.younes.io@xxxxxxxxxx>
writes:
> The documentation of `ParseInt` says that any string parsed by
> `kstrtol()` or `kstrtoul()` is also parsed by `from_str()`. That does
> not hold today, and `from_str()` also accepts strings that `kstrtol()`
> rejects:
>
> input kstrtol() i32::from_str()
> "0x-5" -EINVAL Ok(-5)
> "0x+5" -EINVAL Ok(5)
> "-+5" -EINVAL Ok(-5)
> "+0x5" 5 Err(EINVAL)
> "5\n" 5 Err(EINVAL)
The documentation says that `from_str` will parse at least the set
parsed by `kstrtol`, so the first three cases are in line with the
documentation.
For the last two lines, we can strip leading "+" and trailing newline
before invoking the existing implementation.
Best regards,
Andreas Hindborg