rust-lang / rust-lang/rust-clippy

Lint to detect non `#[repr(C)]` type in `#[repr(C)]` struct

Open
#9,357 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-lint
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

What it does

Rust doesn't have a stable ABI, to still allow the exchange of data with external code an ABI can be defined per type. This is done with the #[repr(abi)] attribute. However, (AFAIK), the attribute only affects the type itself, meaning that the user has to ensure that all fields in the type also have #[repr(abi)].

The lint should warn, if a struct has an #[repr(abi)] attribute, but uses a type which doesn't have #[repr(abi)]. Generics should probably be ignored, as we can't check for those ABIs.

Lint Name

field_without_repr

Category

restriction

Advantage

Safe communication with other code

Drawbacks
  1. For external types, it's hard to impossible to create a suggestion.
  2. There are reasons to have #[repr(C)] on a type, but not on each field. This will therefore create FPs
  3. Maybe a lot of lint triggers

These drawbacks are fine if the lint is in the lint is in the restriction category

Example
// This is fine
#[repr(C)]
struct Magic {
    data: u32
}

// This can cause problems
#[repr(C)]
struct Wizzard {
    // `String` is not `#[repr(C)]`
    name: String,
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No files, tests, or entry points are named in the issue. Start by reviewing the proposed field_without_repr behavior, including generic fields and external types; the work is done when the restriction lint reliably identifies non-#[repr(abi)] fields in #[repr(abi)] structs without requiring suggestions.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.