mozilla / mozilla/cbindgen

Why does cbindgen transfer annotations from typedef to the underlying aliased type?

Open
#1,027 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
3k
Forks
386
Avg merge
1h 43m
Merged PRs (30d)
1

Description

A very early commit https://github.com/mozilla/cbindgen/commit/98c707b66e53e8046cdbb0f097e7dba2173b742b attempts to transfer annotations from each Typedef to its underlying aliased type. The attempt fails if the aliased type already has annotations, or if multiple typedefs alias the same type.

What purpose does annotation transfer serve? I can't think of any reason it's necessary, and it risks causing unintended side effects.

For example, a must-use typedef forces the underlying struct to be must-use as well, which is probably not the original intent -- if the code writer intended for a struct to be must-use, they would annotate the struct as must-use -- not some random typedef (of potentially several) that happens to alias it.

There are no code comments explaining why this behavior is desirable, let alone necessary. There is no pull request associated with the commit that might explain the change, no issue tracking the feature, and no unit tests fail if I disable the code.

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

Start by inspecting commit 98c707b66e53e8046cdbb0f097e7dba2173b742b and the current annotation-transfer path. Reproduce cases where a typedef aliases an annotated type or where multiple typedefs share one type, then run the existing unit tests. Done means the intended typedef and aliased-type annotation semantics are established and covered by tests or documented rationale.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.