1
Fork 0

Fix ICE in improper_ctypes_definitions lint with all-ZST transparent types

This commit is contained in:
Fabian Wolff 2021-07-27 23:40:32 +02:00
parent 7069a8c2b7
commit 4e76c3820f
3 changed files with 36 additions and 2 deletions

View file

@ -851,12 +851,18 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
use FfiResult::*;
if def.repr.transparent() {
// Can assume that only one field is not a ZST, so only check
// Can assume that at most one field is not a ZST, so only check
// that field's type for FFI-safety.
if let Some(field) = transparent_newtype_field(self.cx.tcx, variant) {
self.check_field_type_for_ffi(cache, field, substs)
} else {
bug!("malformed transparent type");
// All fields are ZSTs; this means that the type should behave
// like (), which is FFI-unsafe
FfiUnsafe {
ty,
reason: "this struct contains only zero-sized fields".into(),
help: None,
}
}
} else {
// We can't completely trust repr(C) markings; make sure the fields are