Uh oh!
There was an error while loading. Please reload this page.
warn less about non-exhaustive in ffi - #116863
Conversation
rustbot
commented
Oct 17, 2023
(rustbot has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
| #[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.
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.
typedefenumName: uint8_t {
/* fields */
} Name;is legal C code as-of C23 and must, by brute force of logic, match
#[repr(u8)]enumName{/* 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.
I am happy to revise the wording but
- it would be inconsistent with
improper_ctypesas-is to warn onu32in 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
34094d0Compareworkingjubilee
commented
Oct 17, 2023
I suppose some tests might depend on not having their imports formatted, but this is silly... |
34094d0 to
25e2128Comparepetrochenkov
commented
Oct 25, 2023
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 |
petrochenkov
commented
Oct 25, 2023
Warning on |
Uh oh!
There was an error while loading. Please reload this page.
workingjubilee
commented
Oct 26, 2023
Correct, if the... approximately entire linting system was reworked, as I understand it, I guess the allow-site could be in the upstream crate? |
petrochenkov
commented
Oct 26, 2023
Well, not |
workingjubilee
commented
Oct 26, 2023
Right, an arbitrary |
bors
commented
Apr 30, 2024
☔ The latest upstream changes (presumably #124558) made this pull request unmergeable. Please resolve the merge conflicts. |
workingjubilee
commented
May 14, 2024
uhhhh |
traviscross
commented
Jul 3, 2024
@rustbot labels -I-lang-nominated We discussed this issue in the meeting on 2024-06-12. Our consensus was as follows:
|
workingjubilee
commented
Jul 3, 2024
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.
Uh oh!
There was an error while loading. Please reload this page.
jieyouxu
left a comment
There was a problem hiding this comment.
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.
jieyouxu
commented
Oct 19, 2024
@bors r+ |
bors
commented
Oct 19, 2024
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
62aa8f0Compareworkingjubilee
commented
Oct 19, 2024
er! |
workingjubilee
commented
Oct 19, 2024
@bors r=jieyouxu |
bors
commented
Oct 19, 2024
…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. Closesrust-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. Closesrust-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_ctypeswarnings, 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