lint on more incorrect usages of core::ffi::c_void - #159986
lint on more incorrect usages of core::ffi::c_void#159986Jules-Bertholet wants to merge 5 commits into
core::ffi::c_void#159986Conversation
|
cc @rust-lang/miri |
|
r? @fee1-dead rustbot has assigned @fee1-dead. Use Why was this reviewer chosen?The reviewer was selected based on:
|
This comment has been minimized.
This comment has been minimized.
33e8e23 to
2949956
Compare
|
The lint should probably also complain about |
core::ffi::c_void as an &/&mut referentcore::ffi::c_void
Added another lint for this |
|
Added a third lint, against |
|
Idea (not sure if this is feasible): If we do anything that asks for the size of c_void, emit a warning unless it's for a pointer offset operation |
We can emit a warning regardless, with a note to just use byte_add for offset operations. (Is that what people are using size_of for..?) |
|
Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt |
60a14e5 to
2d23dd9
Compare
|
Added a fourth lint to check for incorrect usage of |
This comment has been minimized.
This comment has been minimized.
2d23dd9 to
bf41d85
Compare
| unsafe { r.read() }; | ||
| //~^ ERROR c_void |
There was a problem hiding this comment.
|
Apologies if missed, but do any of these catch patterns like |
No. For something like a |
|
Assuming this needs lang to take a look and that it is about ready for it: @rustbot label +I-lang-nominated |
|
One thing I would like lang's input on: should we merge the lints? We could have a single lint for all incorrect |
|
Thanks @Jules-Bertholet. @rfcbot reviewed |
|
Yes, we should ship them. Agreed they should start at @rfcbot reviewed No strong feelings about one lint vs multiple lints or whether there should be a group. I don't think people should be allowing them as a group, so not having a single allow for them is probably fine? |
|
🔔 This is now entering its final comment period, as per the review above. 🔔 |
bf41d85 to
183f8f2
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
The final comment period, with a disposition to merge, as per the review above, is now complete. As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed. |
183f8f2 to
60c47e3
Compare
Also, fix false negatives in `c_void_returns`.
Also, fix another false negative in `c_void_returns`.
60c47e3 to
c89b8bb
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
This comment has been minimized.
This comment has been minimized.
Also, extend `c_void_references` to lint on references to `c_void` in MIR.
c89b8bb to
37413b6
Compare
View all comments
core::ffi::c_voidhas size 1 and a highly non-trivial validity invariant. It should only ever be used behind a raw pointer. However, people mess this up all the time.c_void_references: Lint against&or&mutreferences toc_void. This is a widespread mistake, e.g. here in Miri, here across GitHub.c_void_statics: Lint againststatics andconsts of typec_void. Examples of this mistake across GitHubc_void_parameters: Lint against usage ofc_voidas a function parameter type. Examples of this mistake across GitHubc_void_values: Lint against usage ofc_voidby value in MIR.Also fixes false negatives in the pre-exisiting
c_void_returns. Like that lint, these new lints are warn-by-default, but should eventually be upgraded to deny.See also #159935
@rustbot label T-lang needs-fcp A-FFI