improper_ctypes should not suggest reprs that lead to errors #60757
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.
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:
The compiler suggests
repr(transparent)
alongsiderepr(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 suggestingrepr(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 asrepr(C)
).The text was updated successfully, but these errors were encountered: