Skip to content

Conversation

@arianbeh
Copy link

Changes

  • Enabled the clippy::as_conversions lint at the workspace level by updating
    Cargo.toml.
  • Resolved all resulting as_conversions violations across the workspace by:
    • Replacing unsafe pointer casts with std::ptr::from_ref / std::ptr::from_mut
      where appropriate (e.g. in cpu-template-helper).
    • Replacing silent integer casts with explicit conversions such as
      i64::from(), u64::try_from(), and usize::try_from().
    • Using localized #[allow(clippy::as_conversions)] in low-level or const
      contexts where as is intentional and required (e.g., enum-to-byte
      encoding in ACPI AML, seccompiler const fns, and libc constant conversions).
    • Cleaning up comparisons and length/size conversions to avoid silent
      truncation.
  • Updated the necessary code paths in:
    • cpu-template-helper
    • utils::time
    • acpi-tables (AML, DSDT, MADT, XSDT)
    • seccompiler (bindings, types, lib)
    • rebase-snap
    • jailer (resource_limits)
    • snapshot-editor
    • firecracker (main and examples)
    • vmm (library, benches, and tests)

Reason

This PR implements the final step of #3161, consolidating several
cast-related Clippy lints into as_conversions and fixing all violations.

Enabling as_conversions ensures:

  • Integer and pointer casts are either:
    • Performed via explicit, safe conversion APIs, or
    • Clearly scoped behind #[allow] where they are intentional and unavoidable.
  • Silent truncation, wraparound, and lossy conversions are avoided.
  • The workspace stays clean under RUSTFLAGS="-Dwarnings".
  • Future code introducing unsafe as casts will be flagged consistently.

All changes preserve existing behavior while making the code safer and more
explicit about type boundaries.

Verification

Locally ran:

  • RUSTFLAGS="-Dwarnings" cargo clippy --all --all-targets
  • cargo fmt

All packages build clean with no Clippy warnings.

I was not able to run tools/devtool checkbuild or tools/devtool checkstyle
because /dev/kvm is not available in my environment.

Closes #3161.

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.

Use clippy::as_conversions

1 participant