From d5e45f22733ddc65513fb050c2c75425f5df653d Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sun, 24 Mar 2024 19:58:05 -0700 Subject: [PATCH 1/8] Temporarily disable miri on doctests --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 13bab49..89689e5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -69,7 +69,7 @@ jobs: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@miri - run: cargo miri setup - - run: cargo miri test + - run: cargo miri test --all-targets # exclude doctests https://github.com/rust-lang/miri/issues/3404 env: MIRIFLAGS: -Zmiri-strict-provenance From fde7fa5e2a06e6ec28e54bdefdd2980bff78dd45 Mon Sep 17 00:00:00 2001 From: Lukasz Anforowicz Date: Wed, 6 Mar 2024 22:00:24 +0000 Subject: [PATCH 2/8] More granular `unsafe` blocks. There should be no functional changes from this commit - the same code is used before and after this commit, except that `unsafe { ... }` blocks wrap smaller pieces of code afterwards. Having more granular `unsafe` blocks hopefully makes `unsafe` audits a tiny bit easier. --- src/lib.rs | 118 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 66 insertions(+), 52 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index e2fad15..0b1e339 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -144,45 +144,53 @@ macro_rules! impl_Integer { let buf_ptr = buf.as_mut_ptr() as *mut u8; let lut_ptr = DEC_DIGITS_LUT.as_ptr(); - unsafe { - // need at least 16 bits for the 4-characters-at-a-time to work. - if mem::size_of::<$t>() >= 2 { - // eagerly decode 4 characters at a time - while n >= 10000 { - let rem = (n % 10000) as isize; - n /= 10000; + // need at least 16 bits for the 4-characters-at-a-time to work. + if mem::size_of::<$t>() >= 2 { + // eagerly decode 4 characters at a time + while n >= 10000 { + let rem = (n % 10000) as isize; + n /= 10000; - let d1 = (rem / 100) << 1; - let d2 = (rem % 100) << 1; - curr -= 4; + let d1 = (rem / 100) << 1; + let d2 = (rem % 100) << 1; + curr -= 4; + unsafe { ptr::copy_nonoverlapping(lut_ptr.offset(d1), buf_ptr.offset(curr), 2); ptr::copy_nonoverlapping(lut_ptr.offset(d2), buf_ptr.offset(curr + 2), 2); } } + } - // if we reach here numbers are <= 9999, so at most 4 chars long - let mut n = n as isize; // possibly reduce 64bit math + // if we reach here numbers are <= 9999, so at most 4 chars long + let mut n = n as isize; // possibly reduce 64bit math - // decode 2 more chars, if > 2 chars - if n >= 100 { - let d1 = (n % 100) << 1; - n /= 100; - curr -= 2; + // decode 2 more chars, if > 2 chars + if n >= 100 { + let d1 = (n % 100) << 1; + n /= 100; + curr -= 2; + unsafe { ptr::copy_nonoverlapping(lut_ptr.offset(d1), buf_ptr.offset(curr), 2); } + } - // decode last 1 or 2 chars - if n < 10 { - curr -= 1; + // decode last 1 or 2 chars + if n < 10 { + curr -= 1; + unsafe { *buf_ptr.offset(curr) = (n as u8) + b'0'; - } else { - let d1 = n << 1; - curr -= 2; + } + } else { + let d1 = n << 1; + curr -= 2; + unsafe { ptr::copy_nonoverlapping(lut_ptr.offset(d1), buf_ptr.offset(curr), 2); } + } - if !is_nonnegative { - curr -= 1; + if !is_nonnegative { + curr -= 1; + unsafe { *buf_ptr.offset(curr) = b'-'; } } @@ -245,45 +253,51 @@ macro_rules! impl_Integer128 { let mut curr = buf.len() as isize; let buf_ptr = buf.as_mut_ptr() as *mut u8; - unsafe { - // Divide by 10^19 which is the highest power less than 2^64. + // Divide by 10^19 which is the highest power less than 2^64. + let (n, rem) = udiv128::udivmod_1e19(n); + let buf1 = unsafe { buf_ptr.offset(curr - U64_MAX_LEN as isize) as *mut [MaybeUninit; U64_MAX_LEN] }; + curr -= rem.write(unsafe { &mut *buf1 }).len() as isize; + + if n != 0 { + // Memset the base10 leading zeros of rem. + let target = buf.len() as isize - 19; + unsafe { + ptr::write_bytes(buf_ptr.offset(target), b'0', (curr - target) as usize); + } + curr = target; + + // Divide by 10^19 again. let (n, rem) = udiv128::udivmod_1e19(n); - let buf1 = buf_ptr.offset(curr - U64_MAX_LEN as isize) as *mut [MaybeUninit; U64_MAX_LEN]; - curr -= rem.write(&mut *buf1).len() as isize; + let buf2 = unsafe { buf_ptr.offset(curr - U64_MAX_LEN as isize) as *mut [MaybeUninit; U64_MAX_LEN] }; + curr -= rem.write(unsafe { &mut *buf2 }).len() as isize; if n != 0 { - // Memset the base10 leading zeros of rem. - let target = buf.len() as isize - 19; - ptr::write_bytes(buf_ptr.offset(target), b'0', (curr - target) as usize); + // Memset the leading zeros. + let target = buf.len() as isize - 38; + unsafe { + ptr::write_bytes(buf_ptr.offset(target), b'0', (curr - target) as usize); + } curr = target; - // Divide by 10^19 again. - let (n, rem) = udiv128::udivmod_1e19(n); - let buf2 = buf_ptr.offset(curr - U64_MAX_LEN as isize) as *mut [MaybeUninit; U64_MAX_LEN]; - curr -= rem.write(&mut *buf2).len() as isize; - - if n != 0 { - // Memset the leading zeros. - let target = buf.len() as isize - 38; - ptr::write_bytes(buf_ptr.offset(target), b'0', (curr - target) as usize); - curr = target; - - // There is at most one digit left - // because u128::max / 10^19 / 10^19 is 3. - curr -= 1; + // There is at most one digit left + // because u128::max / 10^19 / 10^19 is 3. + curr -= 1; + unsafe { *buf_ptr.offset(curr) = (n as u8) + b'0'; } } + } - if !is_nonnegative { - curr -= 1; + if !is_nonnegative { + curr -= 1; + unsafe { *buf_ptr.offset(curr) = b'-'; } - - let len = buf.len() - curr as usize; - let bytes = slice::from_raw_parts(buf_ptr.offset(curr), len); - str::from_utf8_unchecked(bytes) } + + let len = buf.len() - curr as usize; + let bytes = unsafe { slice::from_raw_parts(buf_ptr.offset(curr), len) }; + unsafe { str::from_utf8_unchecked(bytes) } } } )*}; From 526d4e408c404d57044271bee32e33b7211021c3 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Mon, 25 Mar 2024 22:24:51 -0700 Subject: [PATCH 3/8] Explicitly install a Rust toolchain for cargo-outdated job Debugging a recent cargo-outdated bug, it would have been nice not to wonder whether a rustc version change in GitHub's runner image was a contributing factor. --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 89689e5..f18e6c3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -102,6 +102,7 @@ jobs: timeout-minutes: 45 steps: - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable - uses: dtolnay/install@cargo-outdated - run: cargo outdated --workspace --exit-code 1 - run: cargo outdated --manifest-path fuzz/Cargo.toml --exit-code 1 From eeca57ddcf93dd9d19b42630808eccbe70103cae Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Mon, 25 Mar 2024 22:59:43 -0700 Subject: [PATCH 4/8] Touch up comments --- src/lib.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 0b1e339..53fcbe7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -137,16 +137,16 @@ macro_rules! impl_Integer { let mut n = if is_nonnegative { self as $conv_fn } else { - // convert the negative num to positive by summing 1 to it's 2 complement + // Convert negative number to positive by summing 1 to its two's complement. (!(self as $conv_fn)).wrapping_add(1) }; let mut curr = buf.len() as isize; let buf_ptr = buf.as_mut_ptr() as *mut u8; let lut_ptr = DEC_DIGITS_LUT.as_ptr(); - // need at least 16 bits for the 4-characters-at-a-time to work. + // Need at least 16 bits for the 4-digits-at-a-time to work. if mem::size_of::<$t>() >= 2 { - // eagerly decode 4 characters at a time + // Eagerly decode 4 digits at a time. while n >= 10000 { let rem = (n % 10000) as isize; n /= 10000; @@ -161,10 +161,10 @@ macro_rules! impl_Integer { } } - // if we reach here numbers are <= 9999, so at most 4 chars long - let mut n = n as isize; // possibly reduce 64bit math + // If we reach here, numbers are <=9999 so at most 4 digits long. + let mut n = n as isize; // Possibly reduce 64-bit math. - // decode 2 more chars, if > 2 chars + // Decode 2 more digits, if >2 digits. if n >= 100 { let d1 = (n % 100) << 1; n /= 100; @@ -174,7 +174,7 @@ macro_rules! impl_Integer { } } - // decode last 1 or 2 chars + // Decode last 1 or 2 digits. if n < 10 { curr -= 1; unsafe { @@ -247,7 +247,7 @@ macro_rules! impl_Integer128 { let n = if is_nonnegative { self as u128 } else { - // convert the negative num to positive by summing 1 to it's 2 complement + // Convert negative number to positive by summing 1 to its two's complement. (!(self as u128)).wrapping_add(1) }; let mut curr = buf.len() as isize; @@ -280,7 +280,7 @@ macro_rules! impl_Integer128 { curr = target; // There is at most one digit left - // because u128::max / 10^19 / 10^19 is 3. + // because u128::MAX / 10^19 / 10^19 is 3. curr -= 1; unsafe { *buf_ptr.offset(curr) = (n as u8) + b'0'; From 8f392032fadf15b5e6b9b7b6add21875575d67af Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Mon, 25 Mar 2024 23:00:42 -0700 Subject: [PATCH 5/8] Release 1.0.11 --- Cargo.toml | 2 +- src/lib.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a977035..4703653 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "itoa" -version = "1.0.10" +version = "1.0.11" authors = ["David Tolnay "] categories = ["value-formatting", "no-std", "no-std::no-alloc"] description = "Fast integer primitive to string conversion" diff --git a/src/lib.rs b/src/lib.rs index 53fcbe7..8d6721d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -30,7 +30,7 @@ //! //! ![performance](https://raw.githubusercontent.com/dtolnay/itoa/master/performance.png) -#![doc(html_root_url = "https://docs.rs/itoa/1.0.10")] +#![doc(html_root_url = "https://docs.rs/itoa/1.0.11")] #![no_std] #![allow( clippy::cast_lossless, From 0ce0ec24401cc3fd55756f50058d2d3feb500d24 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Mon, 8 Apr 2024 11:52:12 -0700 Subject: [PATCH 6/8] Revert "Temporarily disable miri on doctests" This reverts commit d5e45f22733ddc65513fb050c2c75425f5df653d. --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f18e6c3..cb5f8ac 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -69,7 +69,7 @@ jobs: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@miri - run: cargo miri setup - - run: cargo miri test --all-targets # exclude doctests https://github.com/rust-lang/miri/issues/3404 + - run: cargo miri test env: MIRIFLAGS: -Zmiri-strict-provenance From 3895493dc335f50a54f65ef745c39d6d0aa10e8a Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Fri, 19 Apr 2024 20:40:18 -0700 Subject: [PATCH 7/8] Ignore cast_sign_loss pedantic clippy lint warning: casting `i8` to `u32` may lose the sign of the value --> src/lib.rs:138:21 | 138 | self as $conv_fn | ^^^^^^^^^^^^^^^^ ... 215 | / impl_Integer!( 216 | | I8_MAX_LEN => i8, 217 | | U8_MAX_LEN => u8, 218 | | I16_MAX_LEN => i16, ... | 221 | | U32_MAX_LEN => u32 222 | | as u32); | |___________- in this macro invocation | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_sign_loss = note: `-W clippy::cast-sign-loss` implied by `-W clippy::pedantic` = help: to override `-W clippy::pedantic` add `#[allow(clippy::cast_sign_loss)]` = note: this warning originates in the macro `impl_Integer` (in Nightly builds, run with -Z macro-backtrace for more info) warning: casting `i8` to `u32` may lose the sign of the value --> src/lib.rs:141:23 | 141 | (!(self as $conv_fn)).wrapping_add(1) | ^^^^^^^^^^^^^^^^^^ ... 215 | / impl_Integer!( 216 | | I8_MAX_LEN => i8, 217 | | U8_MAX_LEN => u8, 218 | | I16_MAX_LEN => i16, ... | 221 | | U32_MAX_LEN => u32 222 | | as u32); | |___________- in this macro invocation | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_sign_loss = note: this warning originates in the macro `impl_Integer` (in Nightly builds, run with -Z macro-backtrace for more info) warning: casting `isize` to `u8` may lose the sign of the value --> src/lib.rs:181:49 | 181 | *buf_ptr.offset(curr) = (n as u8) + b'0'; | ^^^^^^^^^ ... 215 | / impl_Integer!( 216 | | I8_MAX_LEN => i8, 217 | | U8_MAX_LEN => u8, 218 | | I16_MAX_LEN => i16, ... | 221 | | U32_MAX_LEN => u32 222 | | as u32); | |___________- in this macro invocation | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_sign_loss = note: this warning originates in the macro `impl_Integer` (in Nightly builds, run with -Z macro-backtrace for more info) warning: casting `isize` to `usize` may lose the sign of the value --> src/lib.rs:198:39 | 198 | let len = buf.len() - curr as usize; | ^^^^^^^^^^^^^ ... 215 | / impl_Integer!( 216 | | I8_MAX_LEN => i8, 217 | | U8_MAX_LEN => u8, 218 | | I16_MAX_LEN => i16, ... | 221 | | U32_MAX_LEN => u32 222 | | as u32); | |___________- in this macro invocation | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_sign_loss = note: this warning originates in the macro `impl_Integer` (in Nightly builds, run with -Z macro-backtrace for more info) warning: casting `i16` to `u32` may lose the sign of the value --> src/lib.rs:138:21 | 138 | self as $conv_fn | ^^^^^^^^^^^^^^^^ ... 215 | / impl_Integer!( 216 | | I8_MAX_LEN => i8, 217 | | U8_MAX_LEN => u8, 218 | | I16_MAX_LEN => i16, ... | 221 | | U32_MAX_LEN => u32 222 | | as u32); | |___________- in this macro invocation | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_sign_loss = note: this warning originates in the macro `impl_Integer` (in Nightly builds, run with -Z macro-backtrace for more info) warning: casting `i16` to `u32` may lose the sign of the value --> src/lib.rs:141:23 | 141 | (!(self as $conv_fn)).wrapping_add(1) | ^^^^^^^^^^^^^^^^^^ ... 215 | / impl_Integer!( 216 | | I8_MAX_LEN => i8, 217 | | U8_MAX_LEN => u8, 218 | | I16_MAX_LEN => i16, ... | 221 | | U32_MAX_LEN => u32 222 | | as u32); | |___________- in this macro invocation | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_sign_loss = note: this warning originates in the macro `impl_Integer` (in Nightly builds, run with -Z macro-backtrace for more info) warning: casting `i32` to `u32` may lose the sign of the value --> src/lib.rs:138:21 | 138 | self as $conv_fn | ^^^^^^^^^^^^^^^^ ... 215 | / impl_Integer!( 216 | | I8_MAX_LEN => i8, 217 | | U8_MAX_LEN => u8, 218 | | I16_MAX_LEN => i16, ... | 221 | | U32_MAX_LEN => u32 222 | | as u32); | |___________- in this macro invocation | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_sign_loss = note: this warning originates in the macro `impl_Integer` (in Nightly builds, run with -Z macro-backtrace for more info) warning: casting `i32` to `u32` may lose the sign of the value --> src/lib.rs:141:23 | 141 | (!(self as $conv_fn)).wrapping_add(1) | ^^^^^^^^^^^^^^^^^^ ... 215 | / impl_Integer!( 216 | | I8_MAX_LEN => i8, 217 | | U8_MAX_LEN => u8, 218 | | I16_MAX_LEN => i16, ... | 221 | | U32_MAX_LEN => u32 222 | | as u32); | |___________- in this macro invocation | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_sign_loss = note: this warning originates in the macro `impl_Integer` (in Nightly builds, run with -Z macro-backtrace for more info) warning: casting `i64` to `u64` may lose the sign of the value --> src/lib.rs:138:21 | 138 | self as $conv_fn | ^^^^^^^^^^^^^^^^ ... 224 | impl_Integer!(I64_MAX_LEN => i64, U64_MAX_LEN => u64 as u64); | ------------------------------------------------------------ in this macro invocation | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_sign_loss = note: this warning originates in the macro `impl_Integer` (in Nightly builds, run with -Z macro-backtrace for more info) warning: casting `i64` to `u64` may lose the sign of the value --> src/lib.rs:141:23 | 141 | (!(self as $conv_fn)).wrapping_add(1) | ^^^^^^^^^^^^^^^^^^ ... 224 | impl_Integer!(I64_MAX_LEN => i64, U64_MAX_LEN => u64 as u64); | ------------------------------------------------------------ in this macro invocation | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_sign_loss = note: this warning originates in the macro `impl_Integer` (in Nightly builds, run with -Z macro-backtrace for more info) warning: casting `isize` to `u8` may lose the sign of the value --> src/lib.rs:181:49 | 181 | *buf_ptr.offset(curr) = (n as u8) + b'0'; | ^^^^^^^^^ ... 224 | impl_Integer!(I64_MAX_LEN => i64, U64_MAX_LEN => u64 as u64); | ------------------------------------------------------------ in this macro invocation | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_sign_loss = note: this warning originates in the macro `impl_Integer` (in Nightly builds, run with -Z macro-backtrace for more info) warning: casting `isize` to `usize` may lose the sign of the value --> src/lib.rs:198:39 | 198 | let len = buf.len() - curr as usize; | ^^^^^^^^^^^^^ ... 224 | impl_Integer!(I64_MAX_LEN => i64, U64_MAX_LEN => u64 as u64); | ------------------------------------------------------------ in this macro invocation | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_sign_loss = note: this warning originates in the macro `impl_Integer` (in Nightly builds, run with -Z macro-backtrace for more info) warning: casting `isize` to `u64` may lose the sign of the value --> src/lib.rs:138:21 | 138 | self as $conv_fn | ^^^^^^^^^^^^^^^^ ... 233 | impl_Integer!(I64_MAX_LEN => isize, U64_MAX_LEN => usize as u64); | ---------------------------------------------------------------- in this macro invocation | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_sign_loss = note: this warning originates in the macro `impl_Integer` (in Nightly builds, run with -Z macro-backtrace for more info) warning: casting `isize` to `u64` may lose the sign of the value --> src/lib.rs:141:23 | 141 | (!(self as $conv_fn)).wrapping_add(1) | ^^^^^^^^^^^^^^^^^^ ... 233 | impl_Integer!(I64_MAX_LEN => isize, U64_MAX_LEN => usize as u64); | ---------------------------------------------------------------- in this macro invocation | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_sign_loss = note: this warning originates in the macro `impl_Integer` (in Nightly builds, run with -Z macro-backtrace for more info) warning: casting `isize` to `u8` may lose the sign of the value --> src/lib.rs:181:49 | 181 | *buf_ptr.offset(curr) = (n as u8) + b'0'; | ^^^^^^^^^ ... 233 | impl_Integer!(I64_MAX_LEN => isize, U64_MAX_LEN => usize as u64); | ---------------------------------------------------------------- in this macro invocation | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_sign_loss = note: this warning originates in the macro `impl_Integer` (in Nightly builds, run with -Z macro-backtrace for more info) warning: casting `isize` to `usize` may lose the sign of the value --> src/lib.rs:198:39 | 198 | let len = buf.len() - curr as usize; | ^^^^^^^^^^^^^ ... 233 | impl_Integer!(I64_MAX_LEN => isize, U64_MAX_LEN => usize as u64); | ---------------------------------------------------------------- in this macro invocation | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_sign_loss = note: this warning originates in the macro `impl_Integer` (in Nightly builds, run with -Z macro-backtrace for more info) warning: casting `i128` to `u128` may lose the sign of the value --> src/lib.rs:248:21 | 248 | self as u128 | ^^^^^^^^^^^^ ... 309 | impl_Integer128!(I128_MAX_LEN => i128, U128_MAX_LEN => u128); | ------------------------------------------------------------ in this macro invocation | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_sign_loss = note: this warning originates in the macro `impl_Integer128` (in Nightly builds, run with -Z macro-backtrace for more info) warning: casting `i128` to `u128` may lose the sign of the value --> src/lib.rs:251:23 | 251 | (!(self as u128)).wrapping_add(1) | ^^^^^^^^^^^^^^ ... 309 | impl_Integer128!(I128_MAX_LEN => i128, U128_MAX_LEN => u128); | ------------------------------------------------------------ in this macro invocation | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_sign_loss = note: this warning originates in the macro `impl_Integer128` (in Nightly builds, run with -Z macro-backtrace for more info) warning: casting `isize` to `usize` may lose the sign of the value --> src/lib.rs:265:72 | 265 | ptr::write_bytes(buf_ptr.offset(target), b'0', (curr - target) as usize); | ^^^^^^^^^^^^^^^^^^^^^^^^ ... 309 | impl_Integer128!(I128_MAX_LEN => i128, U128_MAX_LEN => u128); | ------------------------------------------------------------ in this macro invocation | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_sign_loss = note: this warning originates in the macro `impl_Integer128` (in Nightly builds, run with -Z macro-backtrace for more info) warning: casting `isize` to `usize` may lose the sign of the value --> src/lib.rs:278:76 | 278 | ptr::write_bytes(buf_ptr.offset(target), b'0', (curr - target) as usize); | ^^^^^^^^^^^^^^^^^^^^^^^^ ... 309 | impl_Integer128!(I128_MAX_LEN => i128, U128_MAX_LEN => u128); | ------------------------------------------------------------ in this macro invocation | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_sign_loss = note: this warning originates in the macro `impl_Integer128` (in Nightly builds, run with -Z macro-backtrace for more info) warning: casting `isize` to `usize` may lose the sign of the value --> src/lib.rs:298:39 | 298 | let len = buf.len() - curr as usize; | ^^^^^^^^^^^^^ ... 309 | impl_Integer128!(I128_MAX_LEN => i128, U128_MAX_LEN => u128); | ------------------------------------------------------------ in this macro invocation | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_sign_loss = note: this warning originates in the macro `impl_Integer128` (in Nightly builds, run with -Z macro-backtrace for more info) --- src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib.rs b/src/lib.rs index 8d6721d..3546bf4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -35,6 +35,7 @@ #![allow( clippy::cast_lossless, clippy::cast_possible_truncation, + clippy::cast_sign_loss, clippy::expl_impl_clone_on_copy, clippy::must_use_candidate, clippy::needless_doctest_main, From 945f297a243887f66407fcd65088b3713a464851 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Fri, 19 Apr 2024 20:42:40 -0700 Subject: [PATCH 8/8] Ignore cast_possible_wrap pedantic clippy lint warning: casting `usize` to `isize` may wrap around the value --> src/lib.rs:144:32 | 144 | let mut curr = buf.len() as isize; | ^^^^^^^^^^^^^^^^^^ ... 216 | / impl_Integer!( 217 | | I8_MAX_LEN => i8, 218 | | U8_MAX_LEN => u8, 219 | | I16_MAX_LEN => i16, ... | 222 | | U32_MAX_LEN => u32 223 | | as u32); | |___________- in this macro invocation | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_possible_wrap = note: `-W clippy::cast-possible-wrap` implied by `-W clippy::pedantic` = help: to override `-W clippy::pedantic` add `#[allow(clippy::cast_possible_wrap)]` = note: this warning originates in the macro `impl_Integer` (in Nightly builds, run with -Z macro-backtrace for more info) warning: casting `u32` to `isize` may wrap around the value on targets with 32-bit wide pointers --> src/lib.rs:152:35 | 152 | let rem = (n % 10000) as isize; | ^^^^^^^^^^^^^^^^^^^^ ... 216 | / impl_Integer!( 217 | | I8_MAX_LEN => i8, 218 | | U8_MAX_LEN => u8, 219 | | I16_MAX_LEN => i16, ... | 222 | | U32_MAX_LEN => u32 223 | | as u32); | |___________- in this macro invocation | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_possible_wrap = note: this warning originates in the macro `impl_Integer` (in Nightly builds, run with -Z macro-backtrace for more info) warning: casting `u32` to `isize` may wrap around the value on targets with 32-bit wide pointers --> src/lib.rs:166:29 | 166 | let mut n = n as isize; // Possibly reduce 64-bit math. | ^^^^^^^^^^ ... 216 | / impl_Integer!( 217 | | I8_MAX_LEN => i8, 218 | | U8_MAX_LEN => u8, 219 | | I16_MAX_LEN => i16, ... | 222 | | U32_MAX_LEN => u32 223 | | as u32); | |___________- in this macro invocation | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_possible_wrap = note: this warning originates in the macro `impl_Integer` (in Nightly builds, run with -Z macro-backtrace for more info) warning: casting `usize` to `isize` may wrap around the value --> src/lib.rs:144:32 | 144 | let mut curr = buf.len() as isize; | ^^^^^^^^^^^^^^^^^^ ... 216 | / impl_Integer!( 217 | | I8_MAX_LEN => i8, 218 | | U8_MAX_LEN => u8, 219 | | I16_MAX_LEN => i16, ... | 222 | | U32_MAX_LEN => u32 223 | | as u32); | |___________- in this macro invocation | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_possible_wrap = note: this warning originates in the macro `impl_Integer` (in Nightly builds, run with -Z macro-backtrace for more info) warning: casting `usize` to `isize` may wrap around the value --> src/lib.rs:144:32 | 144 | let mut curr = buf.len() as isize; | ^^^^^^^^^^^^^^^^^^ ... 225 | impl_Integer!(I64_MAX_LEN => i64, U64_MAX_LEN => u64 as u64); | ------------------------------------------------------------ in this macro invocation | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_possible_wrap = note: this warning originates in the macro `impl_Integer` (in Nightly builds, run with -Z macro-backtrace for more info) warning: casting `u64` to `isize` may wrap around the value on targets with 64-bit wide pointers --> src/lib.rs:152:35 | 152 | let rem = (n % 10000) as isize; | ^^^^^^^^^^^^^^^^^^^^ ... 225 | impl_Integer!(I64_MAX_LEN => i64, U64_MAX_LEN => u64 as u64); | ------------------------------------------------------------ in this macro invocation | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_possible_wrap = note: this warning originates in the macro `impl_Integer` (in Nightly builds, run with -Z macro-backtrace for more info) warning: casting `u64` to `isize` may wrap around the value on targets with 64-bit wide pointers --> src/lib.rs:166:29 | 166 | let mut n = n as isize; // Possibly reduce 64-bit math. | ^^^^^^^^^^ ... 225 | impl_Integer!(I64_MAX_LEN => i64, U64_MAX_LEN => u64 as u64); | ------------------------------------------------------------ in this macro invocation | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_possible_wrap = note: this warning originates in the macro `impl_Integer` (in Nightly builds, run with -Z macro-backtrace for more info) warning: casting `usize` to `isize` may wrap around the value --> src/lib.rs:144:32 | 144 | let mut curr = buf.len() as isize; | ^^^^^^^^^^^^^^^^^^ ... 234 | impl_Integer!(I64_MAX_LEN => isize, U64_MAX_LEN => usize as u64); | ---------------------------------------------------------------- in this macro invocation | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_possible_wrap = note: this warning originates in the macro `impl_Integer` (in Nightly builds, run with -Z macro-backtrace for more info) warning: casting `u64` to `isize` may wrap around the value on targets with 64-bit wide pointers --> src/lib.rs:152:35 | 152 | let rem = (n % 10000) as isize; | ^^^^^^^^^^^^^^^^^^^^ ... 234 | impl_Integer!(I64_MAX_LEN => isize, U64_MAX_LEN => usize as u64); | ---------------------------------------------------------------- in this macro invocation | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_possible_wrap = note: this warning originates in the macro `impl_Integer` (in Nightly builds, run with -Z macro-backtrace for more info) warning: casting `u64` to `isize` may wrap around the value on targets with 64-bit wide pointers --> src/lib.rs:166:29 | 166 | let mut n = n as isize; // Possibly reduce 64-bit math. | ^^^^^^^^^^ ... 234 | impl_Integer!(I64_MAX_LEN => isize, U64_MAX_LEN => usize as u64); | ---------------------------------------------------------------- in this macro invocation | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_possible_wrap = note: this warning originates in the macro `impl_Integer` (in Nightly builds, run with -Z macro-backtrace for more info) warning: casting `usize` to `isize` may wrap around the value --> src/lib.rs:254:32 | 254 | let mut curr = buf.len() as isize; | ^^^^^^^^^^^^^^^^^^ ... 310 | impl_Integer128!(I128_MAX_LEN => i128, U128_MAX_LEN => u128); | ------------------------------------------------------------ in this macro invocation | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_possible_wrap = note: this warning originates in the macro `impl_Integer128` (in Nightly builds, run with -Z macro-backtrace for more info) warning: casting `usize` to `isize` may wrap around the value --> src/lib.rs:259:59 | 259 | let buf1 = unsafe { buf_ptr.offset(curr - U64_MAX_LEN as isize) as *mut [MaybeUninit; U64... | ^^^^^^^^^^^^^^^^^^^^ ... 310 | impl_Integer128!(I128_MAX_LEN => i128, U128_MAX_LEN => u128); | ------------------------------------------------------------ in this macro invocation | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_possible_wrap = note: this warning originates in the macro `impl_Integer128` (in Nightly builds, run with -Z macro-backtrace for more info) warning: casting `usize` to `isize` may wrap around the value --> src/lib.rs:260:25 | 260 | curr -= rem.write(unsafe { &mut *buf1 }).len() as isize; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ... 310 | impl_Integer128!(I128_MAX_LEN => i128, U128_MAX_LEN => u128); | ------------------------------------------------------------ in this macro invocation | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_possible_wrap = note: this warning originates in the macro `impl_Integer128` (in Nightly builds, run with -Z macro-backtrace for more info) warning: casting `usize` to `isize` may wrap around the value --> src/lib.rs:264:34 | 264 | let target = buf.len() as isize - 19; | ^^^^^^^^^^^^^^^^^^ ... 310 | impl_Integer128!(I128_MAX_LEN => i128, U128_MAX_LEN => u128); | ------------------------------------------------------------ in this macro invocation | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_possible_wrap = note: this warning originates in the macro `impl_Integer128` (in Nightly builds, run with -Z macro-backtrace for more info) warning: casting `usize` to `isize` may wrap around the value --> src/lib.rs:272:63 | 272 | let buf2 = unsafe { buf_ptr.offset(curr - U64_MAX_LEN as isize) as *mut [MaybeUninit;... | ^^^^^^^^^^^^^^^^^^^^ ... 310 | impl_Integer128!(I128_MAX_LEN => i128, U128_MAX_LEN => u128); | ------------------------------------------------------------ in this macro invocation | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_possible_wrap = note: this warning originates in the macro `impl_Integer128` (in Nightly builds, run with -Z macro-backtrace for more info) warning: casting `usize` to `isize` may wrap around the value --> src/lib.rs:273:29 | 273 | curr -= rem.write(unsafe { &mut *buf2 }).len() as isize; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ... 310 | impl_Integer128!(I128_MAX_LEN => i128, U128_MAX_LEN => u128); | ------------------------------------------------------------ in this macro invocation | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_possible_wrap = note: this warning originates in the macro `impl_Integer128` (in Nightly builds, run with -Z macro-backtrace for more info) warning: casting `usize` to `isize` may wrap around the value --> src/lib.rs:277:38 | 277 | let target = buf.len() as isize - 38; | ^^^^^^^^^^^^^^^^^^ ... 310 | impl_Integer128!(I128_MAX_LEN => i128, U128_MAX_LEN => u128); | ------------------------------------------------------------ in this macro invocation | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_possible_wrap = note: this warning originates in the macro `impl_Integer128` (in Nightly builds, run with -Z macro-backtrace for more info) --- src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib.rs b/src/lib.rs index 3546bf4..1eeb86b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -35,6 +35,7 @@ #![allow( clippy::cast_lossless, clippy::cast_possible_truncation, + clippy::cast_possible_wrap, clippy::cast_sign_loss, clippy::expl_impl_clone_on_copy, clippy::must_use_candidate,