-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
PhantomData<T> doesn't trigger improper_ctypes_definitions lint #94000
Comments
Should |
If your `Ptr` has methods which assume it is FFI-safe (like dereferencing
the pointer and doing things with it), then you would want to make sure
that `T` is FFI-safe, even though the type signature doesn't require it.
That's when you would want to add `PhantomData<T>`.
|
it means that the type stores a T in terms of lifetime and ownership (which borrow checker etc cares, but ABI doesn't care), but not in terms of data layout (which borrow checker doesn't care, but ABI does). Maybe we should clarify this in the doc. |
Is there a reason why?
I don't think you understand my problem. Here's a more specific example: say you wanted to make a FFI-safe #[repr(C)]
pub struct SafeVec<T> {
ptr: *mut T,
length: usize,
capacity: usize
} And implement methods for converting from/to the original Now the problem is that you can use any As I said before, there's a workaround to use a zero-sized array of that type |
This suggestion would add a ton of new false positives to the In general we try to make the builtin lints have a low degree of false positives, especially the ones which are enabled by default. Sadly, the Also keep in mind that |
I now understand that my original proposal is not good and I agree with your points. Is there any way my problem with |
Closing this as non-actionable due to the reasons that Thom cited. |
Given the following code:
Based on the documentation of
PhantomData
:I would think that it should trigger the
improper_ctypes_definitions
compiler lint, like this example would:I think that it is intuitive that
PhantomData<T>
should be marked as not FFI-safe ifT
is not FFI-safe.There is a workaround to this by using
[T; 0]
instead ofPhantomData<T>
, but it is very hacky:The text was updated successfully, but these errors were encountered: