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

improper_ctypes should not suggest reprs that lead to errors #60757

Open
hanna-kruppe opened this issue May 12, 2019 · 0 comments
Open

improper_ctypes should not suggest reprs that lead to errors #60757

hanna-kruppe opened this issue May 12, 2019 · 0 comments
Labels
A-FFI Area: Foreign function interface (FFI) A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-enhancement Category: An issue proposing an enhancement or a PR with one. L-improper_ctypes Lint: improper_ctypes T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@hanna-kruppe
Copy link
Contributor

Currently when the lint finds a repr(Rust) struct, enum, or union that is not FFI-safe, it generally suggests some repr attributes that could be applied to a struct/enum/union that would make it FFI-safe, which is nice. However, it bases these suggestions only on the kind of data type, without checking whether the attribute could actually be applied to the specific type.

For example, when compiling this code:

struct Rgb(u8, u8, u8);

extern "C" {
    fn get_color(name: *const u8) -> Rgb;
}

The compiler suggests repr(transparent) alongside repr(C), but applying this suggestion will cause an error because the struct has multiple non-ZST fields.

Arguably the compiler should first check whether the suggestion "makes sense", and not suggest repr(transparent) in cases such as this one. Although it probably should continue to suggesting repr(C) even if that would then lead to another improper_ctypes about a field of the affected type (the user might want to repeatedly apply those suggestions to mark all necessary types as repr(C)).

@jonas-schievink jonas-schievink added A-FFI Area: Foreign function interface (FFI) A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 12, 2019
@workingjubilee workingjubilee added the L-improper_ctypes Lint: improper_ctypes label Sep 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-FFI Area: Foreign function interface (FFI) A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-enhancement Category: An issue proposing an enhancement or a PR with one. L-improper_ctypes Lint: improper_ctypes T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants