1
Fork 0

Warn against boxed DST in improper_ctypes_definitions lint

This commit is contained in:
marmeladema 2021-05-31 13:23:44 +01:00
parent 2577825799
commit 877cfb1aad
3 changed files with 66 additions and 24 deletions

View file

@ -909,11 +909,18 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
}
match *ty.kind() {
ty::Adt(def, _) if def.is_box() && matches!(self.mode, CItemKind::Definition) => {
FfiSafe
}
ty::Adt(def, substs) => {
if def.is_box() && matches!(self.mode, CItemKind::Definition) {
if ty.boxed_ty().is_sized(tcx.at(DUMMY_SP), self.cx.param_env) {
return FfiSafe;
} else {
return FfiUnsafe {
ty,
reason: format!("box cannot be represented as a single pointer"),
help: None,
};
}
}
if def.is_phantom_data() {
return FfiPhantom(ty);
}