"Miguel Ojeda" <miguel.ojeda.sando...@gmail.com> writes: > On Thu, Feb 27, 2025 at 3:39 PM Andreas Hindborg <a.hindb...@kernel.org> > wrote: >> >> + // SAFETY: We checked that `val` will fit in `Self` >> above. >> + let val: Self = unsafe { >> val.try_into().unwrap_unchecked() }; > > This is wrong -- `val` can be the maximum, and thus it does not fit > since it is 2's complement, even if later the complement would. > > In fact, it is caught by the doctest when run with debug assertions enabled: > > /// assert_eq!(Ok(-128), i8::from_str(b_str!("-128"))); > > We try to put 128 into `i8`, which of course does not work...
Thanks for catching this! I have to start running tests with debug assertions, it makes no sense not to do so. I'll send a new version now, hope it will make the cut. Best regards, Andreas Hindborg