-
-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New lints: Adding new fields to union
types
#950
Comments
Wouldn't this not be the case for |
I've been thinking about this too. I think it might be possible to trigger this in pub union Example {
pub x: i64,
pub y: u64,
+ pub z: [bool; 8],
} I believe that this addition is not sensitive to I don't know what the semantics or guarantees (if any) might be for a union of unevenly-sized types, like: pub union Uneven {
pub first: i64,
pub second: bool,
} If anyone has any idea where the |
With |
Interesting! Is encountering a I'm happy to make our lints also require that the union be |
The main thing that you can't do with |
Nice, that addresses my questions. I updated the lint descriptions above to only fire on Thank you both for walking me through this, I appreciate it! |
Removing a
pub
field from aunion
type is clearly a major breaking change. But how about adding a new field? I chatted with @joshlf about this, and the current plan is like this:Any public API 1 field of a public API union may be read or written by downstream callers. There are two risks here:
unsafe
to read a field of that type. They would justify that this is sound because no matter what field was previously written, it's bit-compatible. Adding a new field that is not bit-compatible breaks that logic, regardless of whether the field ispub
or not.cargo-semver-checks
, so we'd trigger the lint for any field additions. If/when bit-pattern data is available, we can make the lint more fine-grained.Two lints, then:
repr(C)
union with no non-public-API fields adds new field, regardless of its visibility (major, deny by default)repr(C)
union with at least one non-public-API field adds new field, regardless of its visibility (major, warn by default)Notes to folks looking to contribute these lints:
pub
field" not "public API field", a subtle distinction).Footnotes
"Public API" in
cargo-semver-checks
is defined as:pub and (not #[doc(hidden)] or #[deprecated])
. In other words, deprecated pub items are public API regardless of#[doc(hidden)]
, and#[doc(hidden)]
pub items are not public API unless deprecated. More info here: https://predr.ag/blog/checking-semver-for-doc-hidden-items/ ↩The text was updated successfully, but these errors were encountered: