-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Dubious improper_ctypes
firing on recursive non-local containment?
#116831
Comments
This was apparently decided thus by T-lang #44109 (comment) but I do not think that T-lang's reasoning holds up in the face of actual software composition and usage patterns. |
I should also note that removing |
…ot-ffi-unsafe, r=jieyouxu warn less about non-exhaustive in ffi Bindgen allows generating `#[non_exhaustive] #[repr(u32)]` enums. This results in nonintuitive nonlocal `improper_ctypes` warnings, even when the types are otherwise perfectly valid in C. Adjust for actual tooling expectations by avoiding warning on simple enums with only unit variants. Closes rust-lang#116831
Rollup merge of rust-lang#116863 - workingjubilee:non-exhaustive-is-not-ffi-unsafe, r=jieyouxu warn less about non-exhaustive in ffi Bindgen allows generating `#[non_exhaustive] #[repr(u32)]` enums. This results in nonintuitive nonlocal `improper_ctypes` warnings, even when the types are otherwise perfectly valid in C. Adjust for actual tooling expectations by avoiding warning on simple enums with only unit variants. Closes rust-lang#116831
…ler-errors More tests for non-exhaustive C-like enums in FFI Add a few more tests for the `improper_ctypes` lint as found with the [varnish-rs](https://github.com/gquintard/varnish-rs) project. This follows up on rust-lang#116831, fixed in rust-lang#116863 by `@workingjubilee` - I have been seeing these fail with the bindgen-generated non-exhaustive enums inside other structs. Seems the issue does not exist in the primary branch, so this PR just makes sure more cases are covered for the future.
…ler-errors More tests for non-exhaustive C-like enums in FFI Add a few more tests for the `improper_ctypes` lint as found with the [varnish-rs](https://github.com/gquintard/varnish-rs) project. This follows up on rust-lang#116831, fixed in rust-lang#116863 by ``@workingjubilee`` - I have been seeing these fail with the bindgen-generated non-exhaustive enums inside other structs. Seems the issue does not exist in the primary branch, so this PR just makes sure more cases are covered for the future.
Rollup merge of rust-lang#132303 - nyurik:non-exhaustive-err, r=compiler-errors More tests for non-exhaustive C-like enums in FFI Add a few more tests for the `improper_ctypes` lint as found with the [varnish-rs](https://github.com/gquintard/varnish-rs) project. This follows up on rust-lang#116831, fixed in rust-lang#116863 by ``@workingjubilee`` - I have been seeing these fail with the bindgen-generated non-exhaustive enums inside other structs. Seems the issue does not exist in the primary branch, so this PR just makes sure more cases are covered for the future.
Bindgen allows you to create a "rustified non-exhaustive enum" from a C enum. This is used by pgrx-pg-sys for a specific C enum,
NodeTag
, becauserepr(Rust)
enum, it regularly changes the assigned values to its variants each version, requiring an extension to be built against a specific Postgres version.repr
to make sure it is the correct size, with#[non_exhaustive]
, so that people can write the same code and have it be robust against future Postgres versions (though I seriously doubt anyone is going to write a 400 variant match, but hey, we've seen weirder, sooo...).Unfortunately, it seems this can trigger the
improper_ctypes
lint if people add their own bindings against Postgres which mentionpgrx_pg_sys
's bound types, which they did not define the original bindings to, and which only recursively contains the improper ctype... i.e. they mentioned a pgrx-pg-sys-bound type, which is itself a pointer to a pgrx-pg-sys-bound type, that contains a pointer to another pgrx-pg-sys-bound type that itself contains the pgrx-pg-sys-bound enum.Naturally, they have no idea what the hell is going on, since the error doesn't even mention which field is the offender, or how recursively deep it is.
This disappears if I make it a "rustified enum" instead, which lacks
#[non_exhaustive]
. It seems some reasoning is being applied along the lines of, "Non-exhaustive means that it can become FFI-incompatible in the future due tofeature(arbitrary_enum_discriminant)
andfeature(really_tagged_unions)
, without breaking compat", when that has nothing to do with reality, and in fact I'm more trying to use it to encourage people to handle the C code correctly! And even if that was the case, the lint appears to be violating locality.I tried this code:
I got this:
I expected to not see a warning on types that weren't defined in the local crate, are de facto safe as argument types, and in any case are behind at least two pointers.
Meta
This repros on both stable and this nightly:
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: