{"action":"created","issue":{"url":"https://api.github.com/repos/rust-lang/rust/issues/27303","labels_url":"https://api.github.com/repos/rust-lang/rust/issues/27303/labels{/name}","comments_url":"https://api.github.com/repos/rust-lang/rust/issues/27303/comments","events_url":"https://api.github.com/repos/rust-lang/rust/issues/27303/events","html_url":"https://github.com/rust-lang/rust/issues/27303","id":97331093,"number":27303,"title":"Document the correct FFI equivalent to a C opaque struct","user":{"login":"crumblingstatue","id":1521976,"avatar_url":"https://avatars.githubusercontent.com/u/1521976?v=3","gravatar_id":"","url":"https://api.github.com/users/crumblingstatue","html_url":"https://github.com/crumblingstatue","followers_url":"https://api.github.com/users/crumblingstatue/followers","following_url":"https://api.github.com/users/crumblingstatue/following{/other_user}","gists_url":"https://api.github.com/users/crumblingstatue/gists{/gist_id}","starred_url":"https://api.github.com/users/crumblingstatue/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/crumblingstatue/subscriptions","organizations_url":"https://api.github.com/users/crumblingstatue/orgs","repos_url":"https://api.github.com/users/crumblingstatue/repos","events_url":"https://api.github.com/users/crumblingstatue/events{/privacy}","received_events_url":"https://api.github.com/users/crumblingstatue/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/rust-lang/rust/labels/A-docs","name":"A-docs","color":"d7e102"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":7,"created_at":"2015-07-26T16:26:02Z","updated_at":"2015-08-05T17:31:49Z","closed_at":null,"body":"With recent changes to the `improper_ctypes` lint, it now rejects `#[repr(C)] struct Foo;` for representing a C opaque struct.\r\n\r\n```Rust\r\n#[repr(C)]\r\npub struct Foo;\r\n\r\nextern \"C\" {\r\n\tpub fn foo(arg: *const Foo);\r\n}\r\n\r\nfn main() {\r\n}\r\n```\r\n\r\n```\r\nfoo.rs:5:25: 5:28 warning: found zero-size struct in foreign module, consider adding a member to this struct, #[warn(improper_ctypes)] on by default\r\nfoo.rs:5 \tpub fn foo(arg: *const Foo);\r\n         \t                       ^~~\r\n\r\n```\r\n\r\nOn the #rust IRC channel, I have asked what is the proper way to represent a C opaque struct, but no definitive answer was reached.\r\n\r\nSome of the answers were:\r\n- `struct Foo;` is incorrect.\r\n- `struct Foo;` is fine, but it can break certain LLVM optimizations.\r\n- Use `c_void` instead. This isn't satisfactory when it is desirable to represent a C opaque struct as a distinct type in your API.\r\n- Use a newtype wrapper around `c_void`. Someone said this might not be correct either.\r\n- Rustc should allow `#repr(C) enum Foo {}`. It doesn't currently allow this.\r\n\r\nThis should be properly researched and then documented in the official documentation, so users know what to use for representing C opaque struct types in Rust when interfacing with C code.\r\n\r\nSome relevant issues:\r\n- https://github.com/rust-lang/rust/issues/17679\r\n- https://github.com/rust-lang/rust/issues/20660\r\n"},"comment":{"url":"https://api.github.com/repos/rust-lang/rust/issues/comments/128084810","html_url":"https://github.com/rust-lang/rust/issues/27303#issuecomment-128084810","issue_url":"https://api.github.com/repos/rust-lang/rust/issues/27303","id":128084810,"user":{"login":"tomjakubowski","id":667901,"avatar_url":"https://avatars.githubusercontent.com/u/667901?v=3","gravatar_id":"","url":"https://api.github.com/users/tomjakubowski","html_url":"https://github.com/tomjakubowski","followers_url":"https://api.github.com/users/tomjakubowski/followers","following_url":"https://api.github.com/users/tomjakubowski/following{/other_user}","gists_url":"https://api.github.com/users/tomjakubowski/gists{/gist_id}","starred_url":"https://api.github.com/users/tomjakubowski/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tomjakubowski/subscriptions","organizations_url":"https://api.github.com/users/tomjakubowski/orgs","repos_url":"https://api.github.com/users/tomjakubowski/repos","events_url":"https://api.github.com/users/tomjakubowski/events{/privacy}","received_events_url":"https://api.github.com/users/tomjakubowski/received_events","type":"User","site_admin":false},"created_at":"2015-08-05T17:31:49Z","updated_at":"2015-08-05T17:31:49Z","body":"@bluss raw pointers to Sized types are always allowed in FFI signatures, AFAIK."}}