Make *const (), *mut () okay for FFI #84267
Conversation
(rust-highfive has picked a reviewer for you, use r? to override) |
Would there be any difference between |
|
r? rust-lang/compiler-team |
I believe this is something @rust-lang/lang should take a look at before this is merged. Implementation-wise this LGTM. |
While there's no fundamental reason this couldn't work, we already have For that reason, I don't think we should do this. As an alternative, perhaps we could emit a structured suggestion if we see those types used in FFI, suggesting the use of |
@joshtriplett in pure Rust to Rust FFI (where C is not involved), c_void doesn't seem appropriate. Rust code idiomatically uses ptr to () as the unspecified pointer type, as seen in RawWakerVTable and to_raw_parts in the standard library. I think that c_void should only come up when talking to C. |
@dtolnay That's an interesting point. I was thinking of I'm wondering if it would be appropriate to provide a lint about it for |
We discussed this in today's @rust-lang/lang meeting. I would still like to see a lint on But for now, this seems like a good change, and a conservative one: @rfcbot merge |
Team member @joshtriplett has proposed to merge this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
@bors reviewed This seems to be setting a kind of precedent that the "C ABI" should not warn about things that are reasonable but which may not be idiomatic (and that the latter would be a distinct lint). Does that seem correct? |
"reasonable but not idiomatic" seems like exactly the case for which we should accept the code but emit a lint. |
@joshtriplett well, this is ultimately a lint no matter what, right? So the question is more like: what is the domain of this lint? |
Hmm, As for this specifically, I dunno. I could see both "just use |
|
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. The RFC will be merged soon. |
@bors r+ |
|
|
Finished benchmarking commit (c70b35e): comparison url. Summary: This benchmark run did not return any relevant changes. If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf. @rustbot label: -perf-regression |
dtolnay commentedApr 17, 2021
Pointer-to-() is used occasionally in the standard library to mean "pointer to none-of-your-business". Examples:
RawWakerVTable::new
https://doc.rust-lang.org/1.51.0/std/task/struct.RawWakerVTable.html#method.new<*const T>::to_raw_parts
https://doc.rust-lang.org/nightly/std/primitive.pointer.html#method.to_raw_partsI believe it's useful for the same purpose in FFI signatures, even while
()
itself is not FFI safe. The following should be allowed:Prior to this PR, those pointers were not considered okay for an extern signature.
The text was updated successfully, but these errors were encountered: