Skip to content
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

Implement RFC #18 #14479

Closed
wants to merge 5 commits into from
Closed

Implement RFC #18 #14479

wants to merge 5 commits into from

Conversation

emberian
Copy link
Member

Closes #14309.

Extends the ctypes lint to warn when a struct not annotated with
#[repr(C)] is used in an FFI function.

As of RFC 18, struct layout is undefined. Opting into a C-compatible struct
layout is now down with #[repr(C)]. For consistency, specifying a packed
layout is now also down with #[repr(packed)]. Both can be specified.

[breaking-change]
@@ -544,7 +544,7 @@ mod imp {
static IMAGE_FILE_MACHINE_IA64: libc::DWORD = 0x0200;
static IMAGE_FILE_MACHINE_AMD64: libc::DWORD = 0x8664;

#[packed]
#[repr(packed)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be C, packed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, stupid cfg'd code!

@emberian
Copy link
Member Author

@alexcrichton at this point I'd rather just overhaul the ctypes lint to be more precise, and done after trans. Right now it handwaves away things like generic structs. I feel like:

#[repr(C)]
struct Foo<T> {
    x: T
}

should be a warning where T is not #[repr(C)]. Etc.

@alexcrichton
Copy link
Member

At minimum you may want to deal with pointer types to structs, as those are probably the most common way of dealing with FFI structs. A fancier lint could come later.

@alexcrichton
Copy link
Member

Closing due to inactivity, but feel free to reopen with a rebase!

bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tracking bug for RFC 18 - undefined struct layout
3 participants