diff options
| author | Robin Kruppe <robin.kruppe@gmail.com> | 2018-02-14 19:39:04 +0100 |
|---|---|---|
| committer | Robin Kruppe <robin.kruppe@gmail.com> | 2018-02-15 18:10:54 +0100 |
| commit | 22a171609bf555833b277a70420a24696dd8805d (patch) | |
| tree | 52a0c7f754a2557b6c21de486790e31700a9dc21 | |
| parent | 9b5f47ec48e8c12b68cff7cc64afe166358183ef (diff) | |
| download | rust-22a171609bf555833b277a70420a24696dd8805d.tar.gz rust-22a171609bf555833b277a70420a24696dd8805d.zip | |
[improper_ctypes] Suggest repr(transparent) for structs
The suggestion is unconditional, so following it could lead to further errors. This is already the case for the repr(C) suggestion, which makes this acceptable, though not *good*. Checking up-front whether the suggestion can help would be great but applies more broadly (and would require some refactoring to avoid duplicating the checks).
| -rw-r--r-- | src/librustc_lint/types.rs | 3 | ||||
| -rw-r--r-- | src/test/ui/lint-ctypes.stderr | 10 |
2 files changed, 7 insertions, 6 deletions
diff --git a/src/librustc_lint/types.rs b/src/librustc_lint/types.rs index 7203b1b1e7d..378fe99bf31 100644 --- a/src/librustc_lint/types.rs +++ b/src/librustc_lint/types.rs @@ -425,7 +425,8 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> { return FfiUnsafe { ty: ty, reason: "this struct has unspecified layout", - help: Some("consider adding a #[repr(C)] attribute to this struct"), + help: Some("consider adding a #[repr(C)] or #[repr(transparent)] \ + attribute to this struct"), }; } diff --git a/src/test/ui/lint-ctypes.stderr b/src/test/ui/lint-ctypes.stderr index 8ecdae07a53..a8628c8b3d2 100644 --- a/src/test/ui/lint-ctypes.stderr +++ b/src/test/ui/lint-ctypes.stderr @@ -9,7 +9,7 @@ note: lint level defined here | 11 | #![deny(improper_ctypes)] | ^^^^^^^^^^^^^^^ - = help: consider adding a #[repr(C)] attribute to this struct + = help: consider adding a #[repr(C)] or #[repr(transparent)] attribute to this struct error: `extern` block uses type `Foo` which is not FFI-safe: this struct has unspecified layout --> $DIR/lint-ctypes.rs:55:28 @@ -17,7 +17,7 @@ error: `extern` block uses type `Foo` which is not FFI-safe: this struct has uns 55 | pub fn ptr_type2(size: *const Foo); //~ ERROR: uses type `Foo` | ^^^^^^^^^^ | - = help: consider adding a #[repr(C)] attribute to this struct + = help: consider adding a #[repr(C)] or #[repr(transparent)] attribute to this struct error: `extern` block uses type `[u32]` which is not FFI-safe: slices have no C equivalent --> $DIR/lint-ctypes.rs:56:26 @@ -41,7 +41,7 @@ error: `extern` block uses type `std::boxed::Box<u32>` which is not FFI-safe: th 58 | pub fn box_type(p: Box<u32>); //~ ERROR uses type `std::boxed::Box<u32>` | ^^^^^^^^ | - = help: consider adding a #[repr(C)] attribute to this struct + = help: consider adding a #[repr(C)] or #[repr(transparent)] attribute to this struct error: `extern` block uses type `char` which is not FFI-safe: the `char` type has no C equivalent --> $DIR/lint-ctypes.rs:59:25 @@ -129,7 +129,7 @@ error: `extern` block uses type `std::boxed::Box<u32>` which is not FFI-safe: th 71 | pub fn fn_contained(p: RustBadRet); //~ ERROR: uses type `std::boxed::Box<u32>` | ^^^^^^^^^^ | - = help: consider adding a #[repr(C)] attribute to this struct + = help: consider adding a #[repr(C)] or #[repr(transparent)] attribute to this struct error: `extern` block uses type `i128` which is not FFI-safe: 128-bit integers don't currently have a known stable ABI --> $DIR/lint-ctypes.rs:72:32 @@ -151,7 +151,7 @@ error: `extern` block uses type `std::boxed::Box<u32>` which is not FFI-safe: th 74 | pub fn transparent_fn(p: TransparentBadFn); //~ ERROR: uses type `std::boxed::Box<u32>` | ^^^^^^^^^^^^^^^^ | - = help: consider adding a #[repr(C)] attribute to this struct + = help: consider adding a #[repr(C)] or #[repr(transparent)] attribute to this struct error: aborting due to 20 previous errors |
