From 9d493c897b4382dc145b9448b3fafdfbbaecf528 Mon Sep 17 00:00:00 2001 From: Robin Kruppe Date: Wed, 14 Feb 2018 23:01:39 +0100 Subject: [PATCH] [improper_ctypes] Point at definition of non-FFI-safe type if possible --- src/librustc_lint/types.rs | 5 +++++ src/test/ui/lint-ctypes.stderr | 15 +++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/librustc_lint/types.rs b/src/librustc_lint/types.rs index 378fe99bf31..396d830d85b 100644 --- a/src/librustc_lint/types.rs +++ b/src/librustc_lint/types.rs @@ -666,6 +666,11 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> { if let Some(s) = help { diag.help(s); } + if let ty::TyAdt(def, _) = unsafe_ty.sty { + if let Some(sp) = self.cx.tcx.hir.span_if_local(def.did) { + diag.span_note(sp, "type defined here"); + } + } diag.emit(); } } diff --git a/src/test/ui/lint-ctypes.stderr b/src/test/ui/lint-ctypes.stderr index a8628c8b3d2..2abf08d55f7 100644 --- a/src/test/ui/lint-ctypes.stderr +++ b/src/test/ui/lint-ctypes.stderr @@ -10,6 +10,11 @@ note: lint level defined here 11 | #![deny(improper_ctypes)] | ^^^^^^^^^^^^^^^ = help: consider adding a #[repr(C)] or #[repr(transparent)] attribute to this struct +note: type defined here + --> $DIR/lint-ctypes.rs:32:1 + | +32 | pub struct Foo; + | ^^^^^^^^^^^^^^^ error: `extern` block uses type `Foo` which is not FFI-safe: this struct has unspecified layout --> $DIR/lint-ctypes.rs:55:28 @@ -18,6 +23,11 @@ error: `extern` block uses type `Foo` which is not FFI-safe: this struct has uns | ^^^^^^^^^^ | = help: consider adding a #[repr(C)] or #[repr(transparent)] attribute to this struct +note: type defined here + --> $DIR/lint-ctypes.rs:32:1 + | +32 | pub struct Foo; + | ^^^^^^^^^^^^^^^ error: `extern` block uses type `[u32]` which is not FFI-safe: slices have no C equivalent --> $DIR/lint-ctypes.rs:56:26 @@ -94,6 +104,11 @@ error: `extern` block uses type `ZeroSize` which is not FFI-safe: this struct ha | ^^^^^^^^ | = help: consider adding a member to this struct +note: type defined here + --> $DIR/lint-ctypes.rs:28:1 + | +28 | pub struct ZeroSize; + | ^^^^^^^^^^^^^^^^^^^^ error: `extern` block uses type `ZeroSizeWithPhantomData` which is not FFI-safe: composed only of PhantomData --> $DIR/lint-ctypes.rs:66:33