1
Fork 0

Rollup merge of #85853 - marmeladema:improper-ctypes-definitions-boxed-dst, r=petrochenkov

Warn against boxed DST in `improper_ctypes_definitions` lint

Fixes #85714
This commit is contained in:
Yuki Okushi 2021-06-05 06:13:38 +09:00 committed by GitHub
commit ec9e7d5df1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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);
}