Skip to content

Commit 9d493c8

Browse files
author
Robin Kruppe
committed
[improper_ctypes] Point at definition of non-FFI-safe type if possible
1 parent 22a1716 commit 9d493c8

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/librustc_lint/types.rs

+5
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,11 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
666666
if let Some(s) = help {
667667
diag.help(s);
668668
}
669+
if let ty::TyAdt(def, _) = unsafe_ty.sty {
670+
if let Some(sp) = self.cx.tcx.hir.span_if_local(def.did) {
671+
diag.span_note(sp, "type defined here");
672+
}
673+
}
669674
diag.emit();
670675
}
671676
}

src/test/ui/lint-ctypes.stderr

+15
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ note: lint level defined here
1010
11 | #![deny(improper_ctypes)]
1111
| ^^^^^^^^^^^^^^^
1212
= help: consider adding a #[repr(C)] or #[repr(transparent)] attribute to this struct
13+
note: type defined here
14+
--> $DIR/lint-ctypes.rs:32:1
15+
|
16+
32 | pub struct Foo;
17+
| ^^^^^^^^^^^^^^^
1318

1419
error: `extern` block uses type `Foo` which is not FFI-safe: this struct has unspecified layout
1520
--> $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
1823
| ^^^^^^^^^^
1924
|
2025
= help: consider adding a #[repr(C)] or #[repr(transparent)] attribute to this struct
26+
note: type defined here
27+
--> $DIR/lint-ctypes.rs:32:1
28+
|
29+
32 | pub struct Foo;
30+
| ^^^^^^^^^^^^^^^
2131

2232
error: `extern` block uses type `[u32]` which is not FFI-safe: slices have no C equivalent
2333
--> $DIR/lint-ctypes.rs:56:26
@@ -94,6 +104,11 @@ error: `extern` block uses type `ZeroSize` which is not FFI-safe: this struct ha
94104
| ^^^^^^^^
95105
|
96106
= help: consider adding a member to this struct
107+
note: type defined here
108+
--> $DIR/lint-ctypes.rs:28:1
109+
|
110+
28 | pub struct ZeroSize;
111+
| ^^^^^^^^^^^^^^^^^^^^
97112

98113
error: `extern` block uses type `ZeroSizeWithPhantomData` which is not FFI-safe: composed only of PhantomData
99114
--> $DIR/lint-ctypes.rs:66:33

0 commit comments

Comments
 (0)