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.
Also, fix false negatives in `c_void_returns`.
33e8e23 to
2949956
Compare
|
The lint should probably also complain about |
core::ffi::c_void as an &/&mut referentcore::ffi::c_void
Also, fix another false negative in `c_void_returns`.
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.
Also, extend `c_void_references` to lint on references to `c_void` in MIR.
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 |
|
My 2cents: all of these (including One counterpoint is that maybe we'd want to deny-by-default everything except |
|
And all of them are basically different variants of "this c_void isn't behind a raw pointer". it makes most sense to me to just have a single lint for that. |
|
I could see a world in which for "practical reasons" someone might want to ignore the |
|
☔ The latest upstream changes (presumably #160238) made this pull request unmergeable. Please resolve the merge conflicts by rebasing. |
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