-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
warn less about non-exhaustive in ffi #116863
warn less about non-exhaustive in ffi #116863
Conversation
(rustbot has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
@@ -27,3 +27,14 @@ pub enum NonExhaustiveVariants { | |||
#[non_exhaustive] Tuple(u32), | |||
#[non_exhaustive] Struct { field: u32 } | |||
} | |||
|
|||
// Note the absence of repr(C): it's not necessary, and recent C code can now use repr hints too. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docs don't make explicit that the ABI matches C's - https://doc.rust-lang.org/reference/type-layout.html#primitive-representation-of-field-less-enums - my sense is that's probably just an oversight?
But as-is it's not clear to me that this is accurate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typedef enum Name: uint8_t {
/* fields */
} Name;
is legal C code as-of C23 and must, by brute force of logic, match
#[repr(u8)]
enum Name {
/* fields */
}
or fail to compile, according to my understanding. (There simply isn't any other valid representation for the two types in either language's rules, if the Rust variants are data-free: they must match.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am happy to revise the wording but
- it would be inconsistent with
improper_ctypes
as-is to warn onu32
in FFI - the inadequacy of the docs is a preexisting issue it seems
- if I had my druthers I would yeet the entire idea of linting on another crate's types in a crate that isn't the declaring crate from the lint, because it seems absurd, especially when in an
extern "C"
block that is only declaring a binding against C functions, not declaring a new Rust function (thus the bound function implicitly exists anyway), and this is very much the most-lamented lint in terms of false positives.
2ce1399
to
34094d0
Compare
I suppose some tests might depend on not having their imports formatted, but this is silly... |
34094d0
to
25e2128
Compare
When I started reading #116831 my first reaction was "if From the issue it looks like what you want to express is "this enum is Maybe |
Warning on |
tests/ui/rfcs/rfc-2008-non-exhaustive/improper_ctypes/auxiliary/types.rs
Show resolved
Hide resolved
Correct, if the... approximately entire linting system was reworked, as I understand it, I guess the allow-site could be in the upstream crate? |
Well, not |
Right, an arbitrary |
☔ The latest upstream changes (presumably #124558) made this pull request unmergeable. Please resolve the merge conflicts. |
uhhhh |
@rustbot labels -I-lang-nominated We discussed this issue in the meeting on 2024-06-12. Our consensus was as follows:
|
Thank you, I will rebase this shortly and write about-as-much down into rustc_lint. |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apart from the minor nit, and based on the T-lang decision prior to this, this looks reasonable to me. Feel free to r=me after slightly expanding on what "really tagged union" means in the comment.
@bors r+ |
Extracting this logic into a module makes it easier to write down, and more importantly, later find, the actual decisions we've made.
64f5736
to
62aa8f0
Compare
er! |
@bors r=jieyouxu |
…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
…iaskrgr Rollup of 12 pull requests Successful merges: - rust-lang#116863 (warn less about non-exhaustive in ffi) - rust-lang#127675 (Remove invalid help diagnostics for const pointer) - rust-lang#131772 (Remove `const_refs_to_static` TODO in proc_macro) - rust-lang#131789 (Make sure that outer opaques capture inner opaques's lifetimes even with precise capturing syntax) - rust-lang#131795 (Stop inverting expectation in normalization errors) - rust-lang#131920 (Add codegen test for branchy bool match) - rust-lang#131921 (replace STATX_ALL with (STATX_BASIC_STATS | STATX_BTIME) as former is deprecated) - rust-lang#131925 (Warn on redundant `--cfg` directive when revisions are used) - rust-lang#131931 (Remove unnecessary constness from `lower_generic_args_of_path`) - rust-lang#131932 (use tracked_path in rustc_fluent_macro) - rust-lang#131936 (feat(rustdoc-json-types): introduce rustc-hash feature) - rust-lang#131939 (Get rid of `OnlySelfBounds`) Failed merges: - rust-lang#131181 (Compiletest: Custom differ) r? `@ghost` `@rustbot` modify labels: rollup
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 generating
#[non_exhaustive] #[repr(u32)]
enums. This results in nonintuitive nonlocalimproper_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 #116831