rust-lang / rust-lang/rust-clippy
Lint to detect non `#[repr(C)]` type in `#[repr(C)]` struct
Nobody has claimed this yet.
- 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
- For external types, it's hard to impossible to create a suggestion.
- There are reasons to have
#[repr(C)]on a type, but not on each field. This will therefore create FPs - 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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