improper_ctypes: add test for #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 <david@davidtw.co>
This commit is contained in:
parent
ccac43b86b
commit
a8640cdf47
17
src/test/ui/lint/lint-ctypes-66202.rs
Normal file
17
src/test/ui/lint/lint-ctypes-66202.rs
Normal file
@ -0,0 +1,17 @@
|
||||
#![deny(improper_ctypes)]
|
||||
|
||||
// This test checks that 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.
|
||||
|
||||
#[repr(transparent)]
|
||||
pub struct W<T>(T);
|
||||
|
||||
extern "C" {
|
||||
pub fn bare() -> ();
|
||||
pub fn normalize() -> <() as ToOwned>::Owned;
|
||||
//~^ ERROR uses type `()`
|
||||
pub fn transparent() -> W<()>;
|
||||
//~^ ERROR uses type `W<()>`
|
||||
}
|
||||
|
||||
fn main() {}
|
29
src/test/ui/lint/lint-ctypes-66202.stderr
Normal file
29
src/test/ui/lint/lint-ctypes-66202.stderr
Normal file
@ -0,0 +1,29 @@
|
||||
error: `extern` block uses type `()`, which is not FFI-safe
|
||||
--> $DIR/lint-ctypes-66202.rs:11:27
|
||||
|
|
||||
LL | pub fn normalize() -> <() as ToOwned>::Owned;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
|
||||
|
|
||||
note: the lint level is defined here
|
||||
--> $DIR/lint-ctypes-66202.rs:1:9
|
||||
|
|
||||
LL | #![deny(improper_ctypes)]
|
||||
| ^^^^^^^^^^^^^^^
|
||||
= help: consider using a struct instead
|
||||
= note: tuples have unspecified layout
|
||||
|
||||
error: `extern` block uses type `W<()>`, which is not FFI-safe
|
||||
--> $DIR/lint-ctypes-66202.rs:13:29
|
||||
|
|
||||
LL | pub fn transparent() -> W<()>;
|
||||
| ^^^^^ not FFI-safe
|
||||
|
|
||||
= note: composed only of `PhantomData`
|
||||
note: the type is defined here
|
||||
--> $DIR/lint-ctypes-66202.rs:7:1
|
||||
|
|
||||
LL | pub struct W<T>(T);
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
Loading…
Reference in New Issue
Block a user