Skip to content

fix(docs): remove CLayoutOf wrapper for ZST - #277

Merged
Andrew Farkas (HactarCE) merged 1 commit into
masterfrom
ajf/zst-docs-fix
Nov 12, 2026
Merged

Andrew Farkas (HactarCE) merged 1 commit into
masterfrom
ajf/zst-docs-fix

Conversation

@HactarCE

@HactarCE Andrew Farkas (HactarCE) commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Overview

Removes CLayoutOf wrapper for zero-sized PhantomData in struct definitions generated by saferffi macros.

This will fix the recent build failures for dittolive-ditto-sys on docs.rs.

Contributes to SDKS-5225

How does this work?

#[repr(transparent)] is supposed to work on any struct with exactly one non-ZST (zero-sized type) field. While rustc knows that PhantomData<T> is always ZST for any T, it doesn't know that CLayoutOf<PhantomData<T>> is always ZST.

Removing the CLayoutOf wrapper here has no other effects: the layout of any PhantomData<T> is CVoid, which is similarly zero-sized with 1-byte alignment and has the same variance. It just ensures that #[repr(transparent)] works.

How was this tested?

This patch was tested in a clone of the getditto/ditto repository rather thangetditto/safer_ffi directly.

In getditto/ditto on the main branch, run the following command:

git restore sdks/rust/Cargo.lock
rustup run nightly \
  env RUSTC="$(rustup which rustc --toolchain nightly)" \
      RUSTDOC="$(rustup which rustdoc --toolchain nightly)" \
      DOCS_RS=1 \
  cargo rustdoc --lib \
    --manifest-path sdks/rust/dittolive-ditto-sys/external/Cargo.toml

This should fail with two errors:

error[E0690]: transparent struct needs at most one non-trivial field, but has 2
   --> dittolive-ditto-sys/external/dittoffi.rs:427:1

error[E0690]: transparent struct needs at most one non-trivial field, but has 2
   --> dittolive-ditto-sys/external/dittoffi.rs:813:1

(output abbreviated)

Running with this patch enabled should succeed:

git restore sdks/rust/Cargo.lock
rustup run nightly \
  env RUSTC="$(rustup which rustc --toolchain nightly)" \
      RUSTDOC="$(rustup which rustdoc --toolchain nightly)" \
      DOCS_RS=1 \
  cargo rustdoc --lib \
    --manifest-path sdks/rust/dittolive-ditto-sys/external/Cargo.toml \
    --config 'patch.crates-io.safer_ffi-proc_macros.git="https://github.com/getditto/safer_ffi"' \
    --config 'patch.crates-io.safer_ffi-proc_macros.branch="ajf/zst-docs-fix"'

Performance impact

N/A. replaces one ZST with another; no behavior change.

Checklist

  • I reviewed my own diff and cleaned up debug code
  • I manually tested this on a real target (not just unit tests)
  • I updated docs for any public API changes
  • I added the necessary changelog entry for public changes, else labelled the PR as https://github.com/getditto/ditto/labels/D-skip-changelog
  • CI is green
  • I updated docs for any public API changes. If a mintlify change is needed please link to it, or make sure you have a corresponding Linear ticket to follow up.

AI assistance

  • No AI assistance, or only trivial autocomplete
  • AI-assisted (describe below)
    • with thorough supervision and adjustments
    • with little supervision

AI identified the issue and provided the fix. I understand the issue + fix and wrote the PR + changelog entry. The command to reproduce/test the issue was initially AI-written, then I simplified it.

@HactarCE
Andrew Farkas (HactarCE) merged commit 22bb3b9 into master Nov 12, 2026
207 checks passed
@HactarCE
Andrew Farkas (HactarCE) deleted the ajf/zst-docs-fix branch November 12, 2026 20:13

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I've checked and in the specific case of transparent this does indeed not require further CTypes for the PhantomData: LGTM! ✅

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.

3 participants