[improper_ctypes] Point at definition of non-FFI-safe type if possible

This commit is contained in:
Robin Kruppe 2018-02-14 23:01:39 +01:00
parent 22a171609b
commit 9d493c897b
2 changed files with 20 additions and 0 deletions

View File

@ -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();
}
}

View File

@ -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