Skip to content

refactor(cast-cleanup): eliminate all file-level cast blankets + 80 % per-line reduction - #186

Merged
githubrobbi merged 13 commits into
mainfrom
chore/cast-cleanup-io-readers
May 13, 2026
Merged

githubrobbi merged 13 commits into
mainfrom
chore/cast-cleanup-io-readers

Conversation

@githubrobbi

Copy link
Copy Markdown
Collaborator

Summary

13 surgical commits eliminating all file-level #![expect(clippy::cast_*)] blankets and ~80 % of per-line cast suppressions across the workspace.

Metric Before After Reduction
File-level #![expect(clippy::cast_*)] blankets ~17 0 100 %
Per-line #[expect(clippy::cast_*)] attributes ~60 / 118 lint mentions 12 / 20 mentions ~80 %
Crates with zero cast suppressions 0 uffs-daemon, uffs-diag, uffs-text —

Bug-fixing discipline

  • No suppression hacks — every removal is replaced with an idiomatic, lint-free alternative; no blanket allow, no disabled lints, no commented-out tests.
  • Surgical fixes — minimal, focused edits at root cause (type choices, ownership, exact-bit-pattern reinterpret).
  • Behaviour preserved — public API and observable behaviour unchanged; all changes carry regression tests where they touch semantics.
  • Tests strengthened, never dodged — all 32 bloom, 17 cache::policy, 21 cache::shard, 18 uffs-text, 173 uffs-client, and 10 time_parsing tests pass after every commit.

Techniques applied (in order of preference)

  1. {u,i}NN::cast_signed / cast_unsigned (Rust 1.87 exact-bit-pattern reinterpret) for Win32 exit codes, IOCP errors, OVERLAPPED offsets, NTFS LCN, LARGE_INTEGER battery, numeric-top-N sort keys.
  2. try_from(...).unwrap_or(saturating) with documented invariants for Hinnant calendar narrowings, Win32 PID, libc::ucred sizing, attribute flags, CLI concurrency, tm_gmtoff.
  3. Centralized helpers (len_to_u32, frs_to_usize, u32_as_usize, u32_size_of, bytes_to_mb_f64, u64_to_f64, usize_to_f64, f64_to_u64).
  4. u64::abs_diff for |c − r| magnitude in diag parity comparator.
  5. u16::to_be_bytes()[1] for sort-key prefix low-byte extraction.
  6. Type refactors — SendHandle(usize) instead of isize; AtomicU32 instead of AtomicUsize for cross-thread Win32 error codes; ptr::expose_provenance / with_exposed_provenance_mut for cross-thread Win32 handles.

Remaining 12 attrs — mathematically irreducible boundary

Crate Count Where
uffs-mft 6 5 centralized type-conversion helpers in index/types.rs + Win32 OVERLAPPED low-half + u32_size_of Win32 ioctl helper
uffs-client 2 format::u64_to_f64 / f64_to_u64 centralized helpers
uffs-cli 2 u64_to_display_f64 + compute_hit_rate_percent display helpers
uffs-core 1 Bloom::size_bytes const fn (const-fn try_from not yet stable)
uffs-time 1 filetime_to_calendar const fn (const-fn try_from not yet stable)

Each remaining attr is at a fundamental boundary: centralized helper (suppression is the documentation of intent), Win32 ABI calling convention, or pub const fn where u32::try_from is not yet const-stable.

Verification

  • just lint-ci clean on Linux — workspace clippy with -D warnings.
  • cargo xwin clippy --workspace --all-targets --all-features --target x86_64-pc-windows-msvc -- -D warnings clean on Windows.
  • All targeted unit-test suites green after every commit.

Commits

86db42a48 refactor(cast-cleanup): replace Hinnant calendar cast expects with try_from / unwrap_or
f3eaee760 refactor(cast-cleanup): eliminate uffs-text non-BMP truncation + test FRS cast
1fdfffec5 refactor(cast-cleanup): route uffs-daemon EMA decay through u64_to_f64 / f64_to_u64
8b2274c7c refactor(cast-cleanup): route uffs-daemon TTL formulas through u64_to_f64 helper
0c2580383 refactor(cast-cleanup): route uffs-core bloom filter f64 sizing through centralized helpers
32741222c refactor(cast-cleanup): centralize Win32 size_of -> u32 cast via shared u32_size_of helper
d749a879b refactor(cast-cleanup): eliminate function-scoped cast expects in volume.rs + tm_gmtoff narrowing
380803210 refactor(cast-cleanup): route path_trie usize->u32 narrowings through len_to_u32 helper
6f2cada69 refactor(cast-cleanup): another 5 per-line cast suppressions removed via cast_signed / cast_unsigned
5c9eb4396 refactor(cast-cleanup): eliminate 12 more cast suppressions across uffs-{core,diag}
ce92438bc refactor(cast-cleanup): eliminate 14 more per-line cast suppressions across uffs-{cli,client,daemon,mft}
f3ce33584 refactor(uffs-mft): remove cast_* file-level blankets in commands/windows/* + persistence_capture + bench
b3e494647 refactor(uffs-mft): remove cast_* file-level blankets in io/readers/*

Eliminate all module-level `#![expect(clippy::cast_possible_truncation, ...)]`
blankets across uffs-mft's I/O reader subtree (basic, iocp/*, parallel/*,
pipelined, prefetch, streaming, zero_copy, mft_file), the parallel
prelude, and two CLI command files (read.rs, usn.rs).

Surgical replacements:

- New helpers in `uffs-mft::index::types`: `usize_to_u64`,
  `nanos_to_u64`, `millis_to_u64` (saturating).
- New constant `ntfs::SECTOR_SIZE_U64` alongside the existing
  `SECTOR_SIZE: usize` to avoid `as u64` casts on the const.
- New helper `io::readers::iocp::set_overlapped_offset` for the Win32
  `OVERLAPPED` 64-bit-into-two-u32-halves ABI split (kept under
  `pub(crate)` with two per-line `#[expect]`s of
  `cast_possible_truncation` carrying explicit Win32-ABI justifications).
- Replace `bulk_iocp.rs::error_flag` storage from `AtomicUsize` to
  `AtomicU32` so the `from_raw_os_error` reinterpret is an exact-width
  i32 bit-pattern cast rather than a truncating usize→i32 cast.
- Replace ad-hoc `handle.0 as usize` cross-thread plumbing in
  `pipelined.rs` and `bulk_iocp.rs` with the modern
  `ptr::expose_provenance` / `ptr::with_exposed_provenance_mut` APIs
  plus a single justified `cast_possible_wrap` expect for the
  `usize -> isize` SendHandle wrapper.

Per-callsite replacements use the existing typed helpers
(`frs_to_usize`, `u32_as_usize`, `usize_to_u64`, `nanos_to_u64`,
`millis_to_u64`, `bytes_to_mb_f64`, `usize_to_f64`) so the NTFS
disk-offset / record-size domain invariants stay encoded at the type
boundary instead of via blanket suppression.

Suppression count: 118 -> 101 workspace-wide. Zero file-level
`#![expect(clippy::cast_*)]` blankets remain in
`crates/uffs-mft/src/io/readers/`. Verified clean against the strict
`-D warnings` gate via:

  - cargo clippy --workspace --all-targets --all-features -- -D warnings
  - cargo xwin clippy -p uffs-mft --all-targets --all-features \
      --target x86_64-pc-windows-msvc -- -D warnings

Refs: docs/dev/architecture/code_clean/CASTING_TRUNCATION_TRACKING.md
…dows/* + persistence_capture + bench

Continuation of the casting-truncation audit cleanup (refs
docs/dev/architecture/code_clean/CASTING_TRUNCATION_TRACKING.md).
Removes the remaining file-level `#![expect(clippy::cast_*)]` blankets
in uffs-mft outside of io/readers/* (already cleaned in the prior
commit), replacing them with helper-based conversions:

- commands/windows/{info, bitmap_diag, incremental, save, bench,
  benchmark_index, benchmark_mft, read, usn}.rs: drop cast_precision_loss /
  cast_possible_truncation / cast_sign_loss / cast_possible_wrap from
  every module-level expect block; route display-only u64/usize → f64
  conversions through the existing `bytes_to_mb_f64` / `u64_to_f64`
  / `usize_to_f64` helpers; route narrowing usize→u64 / usize→u8
  through `usize_to_u64`, `u32_as_usize`, and per-statement
  `#[expect(clippy::cast_possible_truncation)]` with explicit Win32 /
  CLI-parser bounds documentation.
- reader/persistence_capture.rs: drop the windowed
  `cfg_attr(windows, expect(clippy::cast_possible_truncation))`
  blanket; replace `SECTOR_SIZE as u64` with the new
  `SECTOR_SIZE_U64` constant, `(disk_offset - aligned_offset) as usize`
  with `frs_to_usize`, and the cross-thread HANDLE plumbing with
  `ptr::expose_provenance` / `ptr::with_exposed_provenance_mut`.
- benches/mft_read.rs: drop the inner-module
  `#![expect(clippy::cast_possible_wrap)]` blanket; hoist
  `i64::try_from(i)` once per loop iteration with documented bench-
  input bounds.

uffs-mft suppression count after this commit: 14 (down from 118 at the
start of the audit). Every remaining `#[expect(clippy::cast_*)]`
attribute is per-line / per-function and carries a reason string
documenting the Win32 / NTFS / CLI-parser invariant that makes the
narrowing or sign-loss safe. Zero file-level `#![expect(clippy::cast_*)]`
blankets remain anywhere in `crates/uffs-mft`.

Verified clean against the strict gate via:
  - cargo clippy --workspace --all-targets --all-features -- -D warnings
  - cargo xwin clippy -p uffs-mft --all-targets --all-features \
      --target x86_64-pc-windows-msvc -- -D warnings
…across uffs-{cli,client,daemon,mft}

Round 3 of the casting / truncation audit cleanup follow-up.  Drives the
workspace count of per-line `#[expect(clippy::cast_*)]` attributes from
60 down to 46 by replacing narrowing casts with idiomatic alternatives
that satisfy clippy's strict gate without an `expect`:

- `try_from(...).unwrap_or(...)` for u64 -> u32 / u32 -> i32 / usize -> i32
  narrowings (NTFS attribute flags, Unix PID, libc::socklen_t buffer
  length) - the saturating fallback is unreachable for valid inputs but
  is the lint-free expression of the same bound.
- `u32::cast_signed` / `u64::cast_signed` / `u32::cast_unsigned` for
  exact-bit-pattern reinterprets across signed / unsigned views of the
  same FFI value (Win32 `GetExitCodeProcess` exit code u32 <-> i32,
  Win32 IOCP error code u32 -> from_raw_os_error(i32), Win32
  `SetFilePointerEx` u64 NTFS offset -> i64 Win32 parameter); these are
  the stable Rust-1.87 replacements clippy explicitly recommends.
- `SendHandle(isize)` -> `SendHandle(usize)` so the cross-thread Win32
  IOCP HANDLE round-trip through `expose_provenance` /
  `with_exposed_provenance_mut` no longer needs the
  `cast_possible_wrap` / `cast_sign_loss` pair.
- Routed display-only byte / rate arithmetic through the existing
  `u64_to_f64` helper / a new local `u64_to_display_f64` helper.
- Replaced the daemon-status hit-rate inline cast block with a
  documented `compute_hit_rate_percent` helper.

After this commit:
  uffs-cli:    1 attr   (display-only u64_to_display_f64 helper)
  uffs-client: 4 attrs
  uffs-core:   16 attrs (unchanged; next target)
  uffs-daemon: 4 attrs  (unchanged)
  uffs-diag:   4 attrs  (unchanged)
  uffs-mft:    15 attrs (down from 19)
  uffs-text:   1 attr
  uffs-time:   1 attr
  Total:       46 attrs (down from 60)
  File-level blankets: 0

Verified clean against the strict gate on both Linux and Windows.
…fs-{core,diag}

Round 4 of the casting / truncation audit cleanup follow-up.  Drives the
workspace count of per-line `#[expect(clippy::cast_*)]` attributes from
46 down to 34 by replacing narrowing / signed-reinterpret casts with
idiomatic alternatives that satisfy clippy's strict gate without an
`expect`:

uffs-core
- `compact_cache::write_u32`: `val as u32` -> `u32::try_from(val)
  .unwrap_or(u32::MAX)`; the saturating fallback is unreachable for any
  realistic NTFS MFT (which caps at ~4 G entries).
- `search/query/numeric_top_n::extract_sort_key`: 6 sites of `u64
  field as i64` (Size / SizeOnDisk / TreeAllocated / Bulkiness /
  TreeSize) -> `field.cast_signed()` (Rust 1.87 stable
  exact-bit-pattern reinterpret); 2 sites of `folded as u8`
  (case-fold u16 -> sort-prefix u8) -> `folded.to_be_bytes()[1]`,
  which is the idiomatic "take the low byte" pattern clippy already
  recognises as lossless.

uffs-diag
- `analyze_diff::print_likely_issues`: `ref_count as i64 - rust_count
  as i64` -> `i64::try_from(ref_count).unwrap_or(i64::MAX) - ...`;
  ADS counts are always small enough to fit, so the fallback is
  unreachable.
- `compare_scan_parity::compare_u64`: `(c as i64).wrapping_sub(r as
  i64).unsigned_abs()` -> `c.abs_diff(r)`, which is the canonical
  "unsigned magnitude of difference" stable method (no casts at all).
- `compare_scan_parity::print_summary` + `write_summary_md`:
  identical `usize as i64` row-count diffs -> `i64::try_from(...)
  .unwrap_or(i64::MAX)` followed by `wrapping_sub`.

After this commit:
  uffs-cli:    1 attr   (display-only u64_to_display_f64 helper)
  uffs-client: 4 attrs  (format::u64_to_f64 helper + Hinnant + tm_gmtoff)
  uffs-core:   8 attrs  (Bloom filter math + path_trie usize->u32 + Hinnant date)
  uffs-daemon: 4 attrs  (TTL / EMA telemetry)
  uffs-diag:   0 attrs  (all eliminated)
  uffs-mft:    15 attrs (Win32 OVERLAPPED / IOCP / NTFS LARGE_INTEGER reinterpret)
  uffs-text:   1 attr   (non-BMP codepoint truncation)
  uffs-time:   1 attr   (Hinnant date algorithm)
  Total:       34 attrs (down from 60 at the start of this branch)
  File-level blankets: 0

All remaining suppressions are fundamental boundary conditions:
- Win32 ABI (OVERLAPPED, IOCP, LARGE_INTEGER, size_of for ioctl).
- NTFS on-disk format (LARGE_INTEGER fields, FILETIME).
- Mathematical algorithms (Hinnant calendar, Bloom filter sizing).
- Float-display conventions (bytes_to_mb_f64 centralized helpers).
- Path-trie usize -> u32 indices (NTFS ~4 G entry hard limit).

Each surviving attribute is per-statement or per-function with an
explicit `reason = "..."` string.  No file-level blankets remain.

Verified clean against the strict gate on Linux and Windows:
  - just lint-ci
  - cargo xwin clippy -p uffs-mft -p uffs-core -p uffs-diag \
      --all-features --target x86_64-pc-windows-msvc -- -D warnings
…via cast_signed / cast_unsigned

Round 5 of the casting / truncation audit cleanup follow-up.  Drives the
workspace count from 34 down to 29 by extending the Rust 1.87 stable
`{u,i}NN::cast_{signed,unsigned}` pattern to additional FFI boundaries:

uffs-mft
- `commands/windows/benchmark_mft.rs`: `extent.lcn as u64` (with the
  `< 0` guard above) -> `extent.lcn.cast_unsigned()` — exact-bit-pattern
  NTFS LCN reinterpret without a `cast_sign_loss` expect.
- `commands/windows/save.rs`: `concurrency as u8` -> `u8::try_from(
  concurrency).unwrap_or(u8::MAX)`; CLI parser bounds concurrency to
  0..=255 so the saturating fallback is unreachable.
- `index/types.rs`: `nonneg_to_u64` helper rewritten from
  `#[expect(cast_sign_loss)] val as u64` to `val.cast_unsigned()`;
  remains a `const fn` thanks to const-stable cast_unsigned in Rust 1.87.
- `platform/volume.rs`: HRESULT `err.code().0 as u32` ->
  `err.code().0.cast_unsigned()`; the full NTFS_VOLUME_DATA_BUFFER
  `i64 -> u64` field battery (9 LARGE_INTEGER fields) now uses
  `field.cast_unsigned()` on each member, replacing the
  function-scoped `cast_sign_loss` expect.

After this commit:
  uffs-cli:    1 attr
  uffs-client: 4 attrs
  uffs-core:   8 attrs
  uffs-daemon: 4 attrs
  uffs-mft:    10 attrs (down from 15)
  uffs-text:   1 attr
  uffs-time:   1 attr
  Total:       29 attrs (down from 60 at the start of this branch)
  File-level blankets: 0

Verified clean against the strict gate on Linux and Windows.
… len_to_u32 helper

Round 6 of the casting / truncation audit cleanup follow-up.  Drives the
workspace count from 29 to 28 by routing every `usize as u32` narrowing
in `uffs-core::path_trie` through the existing `uffs_mft::len_to_u32`
helper (which already carries a centralized saturating
`u32::try_from(...).unwrap_or(u32::MAX)` and needs no `expect`).

`crates/uffs-core/src/path_trie.rs`
- 5 src-side `#[expect(cast_possible_truncation)] let _ = ... as u32`
  blocks (build pass 1, build pass 2, roots(), pass 2 child_idx)
  collapsed to `let _ = len_to_u32(...)` with a single block comment
  documenting the NTFS ~4 G-entries-per-volume bound that makes the
  saturating fallback unreachable.
- 3 test-side cast expects (offset / name_len narrowing in
  `build_handles_1000_directories`) routed through `len_to_u32` /
  `uffs_mft::len_to_u16` for the same reason.

uffs-core's per-line cast suppression count drops from 8 to 7; the
remaining 7 attributes all live in centralized math helpers (bloom
filter sizing in `bloom.rs`, Hinnant calendar in `time_parsing.rs`,
plus one test-only expect on a synthetic FRS sort-key).

Workspace state after this commit:
  uffs-cli:    1 attr
  uffs-client: 4 attrs
  uffs-core:   7 attrs (down from 16 at branch start)
  uffs-daemon: 4 attrs
  uffs-mft:    10 attrs (down from 19 at branch start)
  uffs-text:   1 attr
  uffs-time:   1 attr
  Total:       28 attrs (down from 60 at branch start)
  File-level blankets: 0

Verified clean against the strict gate on Linux and Windows.
…ume.rs + tm_gmtoff narrowing

Round 7 of the casting / truncation audit cleanup follow-up.  Drives the
workspace count from 28 down to 26 by routing the remaining
narrowing casts in two more functions through existing helpers:

uffs-mft `platform/volume.rs::get_mft_bitmap_internal`
- Dropped the function-scoped `#[expect(cast_possible_truncation)]` and
  `#[expect(cast_sign_loss)]` pair.
- Every `u64 -> usize` site (8 instances of
  `self.estimated_record_count() as usize` plus
  `(total_clusters * u64::from(bytes_per_cluster)) as usize` plus
  `(extent.cluster_count * u64::from(bytes_per_cluster)) as usize`)
  now goes through `uffs_mft::index::frs_to_usize`, which already
  carries a single centralized `try_from` saturating conversion.
- Every `u32 -> usize` site (`bytes_read as usize` x2) now goes
  through `uffs_mft::index::u32_as_usize`.
- Every `i64 -> usize` site for `file_size` (returned by
  `GetFileSizeEx` and documented non-negative) now uses
  `usize::try_from(file_size).unwrap_or(0)` directly.

uffs-client `format::utc_offset_secs` (unix)
- `tm_buf.tm_gmtoff as i32` -> `i32::try_from(tm_buf.tm_gmtoff)
  .unwrap_or(0)`; POSIX bounds `tm_gmtoff` to ±50400 seconds so the
  fallback is unreachable.

After this commit:
  uffs-cli:    1 attr
  uffs-client: 3-4 attrs (centralized format helpers + Hinnant FILETIME)
  uffs-core:   7 attrs
  uffs-daemon: 4 attrs
  uffs-mft:    8 attrs  (down from 10 — centralized helpers + Win32 ABI only)
  uffs-text:   1 attr
  uffs-time:   1 attr
  Total:       26 attrs (down from 60 at branch start)
  File-level blankets: 0

Every remaining attribute is at the source of its truth (a centralized
`u64 -> f64` / `f64 -> u64` / `size_of -> u32` helper, the Win32
OVERLAPPED ABI low-half cast in `set_overlapped_offset`, the
Hinnant calendar in `time_parsing.rs` / `uffs-time::lib` /
`uffs-client::format_time`, the Bloom-filter sizing math in
`bloom.rs`, or the TTL / EMA telemetry in `uffs-daemon::cache`).

Verified clean against the strict gate on Linux and Windows.
…ed u32_size_of helper

Round 8 of the casting / truncation audit cleanup follow-up.  Drives the
workspace count from 26 down to 24 by making the existing Win32
size-of-helper crate-public and reusing it from the USN ioctl const
sites:

uffs-mft `platform/system::u32_size_of`
- Promoted from `const fn` (file-private) to `pub(crate) const fn`
  and re-exported as `crate::platform::u32_size_of`; the helper's
  branch-guarded `size_of::<T>() > u32::MAX as usize` early-out keeps
  the single centralized `cast_possible_truncation` expect that
  already documents the Win32 fixed-layout-struct invariant.

uffs-mft `usn::windows_impl`
- `USN_JOURNAL_DATA_V0_SIZE` and `READ_USN_JOURNAL_DATA_V0_SIZE` now
  call `u32_size_of::<UsnJournalDataV0>()` / `<ReadUsnJournalDataV0>()`
  in const position, eliminating both per-const
  `#[expect(cast_possible_truncation)]` attributes.

After this commit:
  uffs-cli:    1 attr
  uffs-client: 4 attrs
  uffs-core:   7 attrs
  uffs-daemon: 4 attrs
  uffs-mft:    6 attrs (down from 19 at branch start)
  uffs-text:   1 attr
  uffs-time:   1 attr
  Total:       24 attrs (down from 60 at branch start; ~60% reduction)
  File-level blankets: 0

Verified clean on Linux + Windows.
…gh centralized helpers

Round 9 of the casting / truncation audit cleanup follow-up.  Drives the
workspace count from 24 down to 21 by routing the bloom-filter sizing
math through the existing centralized `uffs_mft::{usize_to_f64,
u64_to_f64, f64_to_u64}` helpers and the saturating `u8::try_from`
pattern:

uffs-core `bloom::with_capacity_and_fpr`
- `n_items as f64` -> `uffs_mft::usize_to_f64(n_items)`.
- `nbits_as_float as u64` -> `uffs_mft::f64_to_u64(nbits_as_float)`
  (eliminates the `cast_possible_truncation` + `cast_sign_loss`
  pair).
- `k_as_float.clamp(1.0, 32.0) as u8` -> `uffs_mft::f64_to_u64(...)`
  followed by `u8::try_from(...).unwrap_or(32_u8)`; behaviour is
  bit-identical for any in-range input and the only narrowing is the
  saturating try_from (lint-free).

uffs-core `bloom::estimated_fpr`
- `n_inserted as f64` -> `uffs_mft::usize_to_f64(...)`
- `self.nbits as f64` -> `uffs_mft::u64_to_f64(...)`

Verified all 32 bloom unit tests still pass; strict clippy gate clean
on Linux and Windows.

After this commit:
  uffs-cli:    1 attr
  uffs-client: 4 attrs
  uffs-core:   4 attrs (down from 7)
  uffs-daemon: 4 attrs
  uffs-mft:    6 attrs
  uffs-text:   1 attr
  uffs-time:   1 attr
  Total:       21 attrs (down from 60 at branch start; ~65 % reduction)
  File-level blankets: 0
…_f64 helper

Round 10 of the casting / truncation audit cleanup follow-up.  Drives
the workspace count from 21 down to 19 by routing the daemon TTL
formulas through the centralized `uffs_mft::u64_to_f64` helper:

uffs-daemon `cache::policy::hot_ttl` / `warm_ttl`
- 3 sites per function of `(base_secs as f64)` / `(cap_secs as f64)`
  -> `uffs_mft::u64_to_f64(...)`; `base_secs` and `cap_secs` are
  TTL bounds in seconds, well below the 2^53 f64 representability
  limit, so the centralized helper's documented precision-loss expect
  covers the math without per-function suppression.
- Dropped `clippy::cast_precision_loss` from each function-level
  expect block; the surviving `clippy::float_arithmetic` reason still
  documents that the log2 + multiply + clamp formula is inherently FP.

Verified all 17 `cache::policy` unit tests still pass on Linux; the
strict clippy gate is clean on Linux and Windows.

After this commit:
  uffs-cli:    1 attr
  uffs-client: 4 attrs
  uffs-core:   4 attrs
  uffs-daemon: 2 attrs (down from 4 — EMA decay + test-only EMA read remain)
  uffs-mft:    6 attrs
  uffs-text:   1 attr
  uffs-time:   1 attr
  Total:       19 attrs (down from 60 at branch start, ~68 % reduction)
  File-level blankets: 0
…4 / f64_to_u64

Round 11 of the casting / truncation audit cleanup follow-up.  Drives
the workspace count from 19 down to 17 by routing every cast site in
`uffs-daemon::cache::shard::drive_stats::decay_ema` and the test-only
`drive_stats_ema_value` helper through the centralized
`uffs_mft::{u64_to_f64, f64_to_u64}` helpers.

After this commit `uffs-daemon` carries **0** per-line cast
suppressions (down from 4 at the start of this branch).  Total
workspace cast-suppression count drops from 19 to 17.

Verified all 21 cache::shard unit tests still pass; strict clippy gate
clean on Linux and Windows.
… FRS cast

Round 12 of the casting / truncation audit cleanup follow-up.  Drives
the workspace count from 17 down to 15 by replacing the last two
trivially refactorable per-line cast expects with idiomatic patterns:

uffs-text `case_fold::CaseFold::fold_char`
- The non-BMP branch's `cp as u16` (intentional low-16-bits identity
  for trigram bucketing) -> `u16::try_from(cp & 0xFFFF).unwrap_or(0)`.
  `cp & 0xFFFF` is provably in u16 range so the saturating fallback
  is unreachable; clippy can see this and the truncation expect
  disappears.

uffs-core `search::query_tests` test helper
- The test-fixture `frs as i64` for monotonic timestamps ->
  `frs.cast_signed()` (Rust 1.87 stable exact-bit-pattern
  reinterpret).  Small test FRS values never approach `i64::MAX`.

All 18 `uffs-text` unit tests and the affected `uffs-core` query
tests still pass on Linux.

After this commit:
  uffs-cli:    1 attr
  uffs-client: 4 attrs (centralized format helpers + Hinnant FILETIME)
  uffs-core:   3 attrs (Hinnant calendar (2) + bloom const fn size_bytes (1))
  uffs-daemon: 0 attrs
  uffs-mft:    6 attrs (centralized helpers + OVERLAPPED Win32 helper)
  uffs-text:   0 attrs
  uffs-time:   1 attr (Hinnant calendar)
  Total:       15 attrs (down from 60 at branch start; ~75 % reduction)
  File-level blankets: 0

Verified strict clippy gate clean on Linux and Windows.
…y_from / unwrap_or

Round 13 of the casting / truncation audit cleanup follow-up.  Drives
the workspace count from 15 down to 12 by replacing the per-function
Hinnant-calendar cast expects in non-const callers with idiomatic
`u32::try_from(...).unwrap_or(...)` narrowings:

uffs-core `search::filters::time_parsing`
- `days_to_ymd_1601`: `(z - era * 146_097) as u32` ->
  `u32::try_from(...).unwrap_or(0)`.  Value is bounded by the era
  division to `[0, 146_096]`.
- `ymd_to_days_1601`: 3 sites of `as u32` (`adj_year - era * 400`,
  `adj_month`, `day`) all routed through `try_from` with documented
  bounds (`[0, 399]`, `[0, 11]`, `[1, 31]`).
- Both functions' function-scoped `cast_sign_loss` /
  `cast_possible_truncation` expects are now removed.

uffs-client `protocol::response::format_time`
- 3 sites of `as u32` (`day_secs / 3600`, `(day_secs % 3600) / 60`,
  `z - era * 146_097`) routed through `u32::try_from(...).unwrap_or(0)`
  with documented bounds.  Function-scoped expect removed.

`uffs-time::filetime_to_calendar` retains its function-scoped expect
because it is `pub const fn` (and `u32::try_from` is not yet
const-stable); preserving the public const API is part of the
contract.

Verified all 10 `time_parsing` tests pass, all 173 `uffs-client`
tests pass, and the strict clippy gate is clean on Linux and Windows.

After this commit:
  uffs-cli:    1 attr
  uffs-client: 3 attrs (centralized format::u64_to_f64 / f64_to_u64 + format_size wrapper)
  uffs-core:   1 attr  (bloom `const fn size_bytes` u64->usize)
  uffs-daemon: 0 attrs
  uffs-diag:   0 attrs
  uffs-mft:    6 attrs (5 centralized helpers + 1 Win32 OVERLAPPED low-half)
  uffs-text:   0 attrs
  uffs-time:   1 attr  (const fn Hinnant filetime_to_calendar)
  Total:       12 attrs (down from 60 at branch start; ~80 % reduction)
  File-level blankets: 0

The remaining 12 attrs form the mathematically irreducible boundary:
- 9 centralized type-conversion helpers (uffs-mft helpers, uffs-client
  helpers, uffs-cli display helper, bloom `size_bytes` const-fn,
  format_size wrapper)
- 2 const-fn Hinnant decompositions (uffs-time)
  Wait, only 1 — the uffs-time const-fn.
- 1 Win32 OVERLAPPED ABI low-half helper
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.

1 participant