diff options
| author | marmeladema <xademax@gmail.com> | 2021-05-31 13:23:44 +0100 |
|---|---|---|
| committer | marmeladema <xademax@gmail.com> | 2021-06-03 23:21:43 +0100 |
| commit | 877cfb1aad2543b3fe31d97075ea37d283afc880 (patch) | |
| tree | 8309720eb7393af634577d804bb46c72efb76f64 /compiler/rustc_lint/src | |
| parent | 257782579915963c9dbe7433102275743837b9a8 (diff) | |
Warn against boxed DST in `improper_ctypes_definitions` lint
Diffstat (limited to 'compiler/rustc_lint/src')
| -rw-r--r-- | compiler/rustc_lint/src/types.rs | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/compiler/rustc_lint/src/types.rs b/compiler/rustc_lint/src/types.rs index 319adf42cf1..5d2256100ff 100644 --- a/compiler/rustc_lint/src/types.rs +++ b/compiler/rustc_lint/src/types.rs @@ -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); } |
