Skip to content

Commit a8640cd

Browse files
committed
improper_ctypes: add test for rust-lang#66202
This commit adds a test of the improper ctypes lint, checking that return type are normalized bethat return types are normalized before being checked for FFI-safety, and that transparent newtype wrappers are FFI-safe if the type being wrapped is FFI-safe. Signed-off-by: David Wood <[email protected]>
1 parent ccac43b commit a8640cd

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

src/test/ui/lint/lint-ctypes-66202.rs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#![deny(improper_ctypes)]
2+
3+
// This test checks that return types are normalized before being checked for FFI-safety, and that
4+
// transparent newtype wrappers are FFI-safe if the type being wrapped is FFI-safe.
5+
6+
#[repr(transparent)]
7+
pub struct W<T>(T);
8+
9+
extern "C" {
10+
pub fn bare() -> ();
11+
pub fn normalize() -> <() as ToOwned>::Owned;
12+
//~^ ERROR uses type `()`
13+
pub fn transparent() -> W<()>;
14+
//~^ ERROR uses type `W<()>`
15+
}
16+
17+
fn main() {}
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
error: `extern` block uses type `()`, which is not FFI-safe
2+
--> $DIR/lint-ctypes-66202.rs:11:27
3+
|
4+
LL | pub fn normalize() -> <() as ToOwned>::Owned;
5+
| ^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
6+
|
7+
note: the lint level is defined here
8+
--> $DIR/lint-ctypes-66202.rs:1:9
9+
|
10+
LL | #![deny(improper_ctypes)]
11+
| ^^^^^^^^^^^^^^^
12+
= help: consider using a struct instead
13+
= note: tuples have unspecified layout
14+
15+
error: `extern` block uses type `W<()>`, which is not FFI-safe
16+
--> $DIR/lint-ctypes-66202.rs:13:29
17+
|
18+
LL | pub fn transparent() -> W<()>;
19+
| ^^^^^ not FFI-safe
20+
|
21+
= note: composed only of `PhantomData`
22+
note: the type is defined here
23+
--> $DIR/lint-ctypes-66202.rs:7:1
24+
|
25+
LL | pub struct W<T>(T);
26+
| ^^^^^^^^^^^^^^^^^^^
27+
28+
error: aborting due to 2 previous errors
29+

0 commit comments

Comments
 (0)