Skip to content

Conversation

@petesmc
Copy link
Contributor

@petesmc petesmc commented Dec 25, 2025

Fix lints from clippy::cast_lossless

@codecov
Copy link

codecov bot commented Dec 25, 2025

Codecov Report

❌ Patch coverage is 38.98432% with 817 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
programs/zstdcli.rs 0.00% 91 Missing ⚠️
lib/compress/zstd_lazy.rs 0.00% 77 Missing ⚠️
lib/compress/zstd_compress.rs 60.00% 66 Missing ⚠️
lib/legacy/zstd_v05.rs 43.26% 59 Missing ⚠️
lib/legacy/zstd_v06.rs 51.63% 59 Missing ⚠️
programs/fileio.rs 0.00% 58 Missing ⚠️
lib/compress/zstd_opt.rs 0.00% 53 Missing ⚠️
programs/util.rs 0.00% 50 Missing ⚠️
lib/compress/zstd_ldm.rs 0.00% 46 Missing ⚠️
programs/benchzstd.rs 0.00% 44 Missing ⚠️
... and 26 more
Flag Coverage Δ
test-aarch64-apple-darwin 33.19% <38.84%> (-0.23%) ⬇️
test-aarch64-unknown-linux-gnu ?
test-i686-unknown-linux-gnu ?
test-x86_64-unknown-linux-gnu 32.99% <37.86%> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
lib/common/bitstream.rs 97.25% <100.00%> (-0.79%) ⬇️
lib/common/fse.rs 54.54% <100.00%> (ø)
lib/common/fse_decompress.rs 94.63% <100.00%> (-1.66%) ⬇️
lib/dictBuilder/cover.rs 80.73% <100.00%> (-0.10%) ⬇️
lib/dictBuilder/fastcover.rs 78.86% <100.00%> (ø)
lib/common/mem.rs 75.78% <50.00%> (-2.11%) ⬇️
lib/common/zstd_common.rs 0.00% <0.00%> (ø)
lib/compress/hist.rs 74.39% <66.66%> (ø)
lib/compress/zstd_preSplit.rs 65.58% <80.00%> (ø)
lib/decompress/huf_decompress.rs 77.11% <91.66%> (-2.28%) ⬇️
... and 31 more

... and 3 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@petesmc petesmc force-pushed the clippy_cast_lossless branch 2 times, most recently from 46eea01 to fd0e007 Compare December 28, 2025 10:02
@petesmc petesmc force-pushed the clippy_cast_lossless branch from fd0e007 to 02ee2a6 Compare December 28, 2025 10:04
Copy link
Member

@folkertdev folkertdev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to only apply this change only to the parts of the code that we've already cleaned up manually. Let's start with lib/dictBuilder. Can you

  • remove changes to the other subdirectories from the initial commit
  • fix the other comments I've left in a separate commit (that is easier to review)

let mut candidateDictBuffer: Box<[u8]> = Box::from(vec![0u8; dictBufferCapacity]);
let regressionTolerance =
params.shrinkDictMaxRegression as core::ffi::c_double / 100.0f64 + 1.00f64;
core::ffi::c_double::from(params.shrinkDictMaxRegression) / 100.0f64 + 1.00f64;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should import use core::ffi::c_double so we can use it unqualified here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same in the other files for the other core::ffi types.

assert!(T[(s - 1) as usize] as i32 <= T[s as usize] as i32);
assert_eq!(i32::from(T[s as usize]), c1);
assert!(
(s + 1) < n && i32::from(T[s as usize]) <= i32::from(T[(s + 1) as usize])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the cast is just not needed here (c2rust introduces it to exactly match the C semantics, but we can just compare u8s here.

#[cfg_attr(feature = "export-symbols", export_name = crate::prefix!(ZDICT_isError))]
pub extern "C" fn ZDICT_isError(errorCode: size_t) -> core::ffi::c_uint {
ERR_isError(errorCode) as _
ERR_isError(errorCode).into()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer c_uint::from here.

// look backward
let mut length_2 = MINMATCHLENGTH;
while (length_2 >= MINMATCHLENGTH) as core::ffi::c_int & (start > 0) as core::ffi::c_int != 0 {
while core::ffi::c_int::from(length_2 >= MINMATCHLENGTH) & core::ffi::c_int::from(start > 0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be simplified into length_2 >= MINMATCHLENGTH && start > 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants