mozilla / cbindgen

A project for generating C bindings from Rust code
Mozilla Public License 2.0
2.43k stars 315 forks source link

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

Open scovich opened 3 weeks ago

scovich commented 3 weeks ago

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.

scovich commented 3 weeks ago

CC @eqrion @emilio in case they have context?