rust-lang/rust-clippy · error

unqualified `#[repr(packed)]` defaults to `#[repr(Rust…

Error message

unqualified `#[repr(packed)]` defaults to `#[repr(Rust, packed)]`, which has no stable ABI

What it means

Clippy lint REPR_PACKED_WITHOUT_ABI: #[repr(packed)] without an explicit ABI resets the layout to the unspecified #[repr(Rust, packed)] representation, which has no stable ABI. The lint fires when the repr list contains ReprPacked but neither ReprC nor ReprRust, and the MSRV supports REPR_RUST — i.e. the author relied on an implicit default instead of naming the intended ABI.

Solutions

  1. Write #[repr(C, packed)] when a stable, C-compatible packed layout is intended
  2. Or spell out the default explicitly as #[repr(Rust, packed)] if no stable ABI is required
  3. Audit FFI boundaries and any code transmuting or serializing the type to confirm the chosen ABI matches consumers
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at clippy_lints/src/attrs/repr_attributes.rs:30 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of rust-lang/rust-clippy@13aece1138 (2026-09-07). Data as JSON: /api/errors/a516f2e712862884. Report an issue: GitHub.

Appendix: source

Thrown at clippy_lints/src/attrs/repr_attributes.rs:30

    if let Some(reprs) = find_attr!(attrs, Repr { reprs, .. } => reprs) {
        let packed_span = reprs
            .iter()
            .find(|(r, _)| matches!(r, ReprAttr::ReprPacked(..)))
            .map(|(_, s)| *s);

        if let Some(packed_span) = packed_span
            && !reprs
                .iter()
                .any(|(x, _)| *x == ReprAttr::ReprC || *x == ReprAttr::ReprRust)
            && msrv.meets(cx, msrvs::REPR_RUST)
        {
            span_lint_and_then(
                cx,
                REPR_PACKED_WITHOUT_ABI,
                item_span,
                "item uses `packed` representation without ABI-qualification",
                |diag| {
                    diag.warn(
                        "unqualified `#[repr(packed)]` defaults to `#[repr(Rust, packed)]`, which has no stable ABI",
                    )
                    .help("qualify the desired ABI explicitly via `#[repr(C, packed)]` or `#[repr(Rust, packed)]`")
                    .span_label(packed_span, "`packed` representation set here");
                },
            );
        }
    }
}

View on GitHub (pinned to 13aece1138)