diff options
| author | Gurinder Singh <frederick.the.fool@gmail.com> | 2024-09-20 18:57:59 +0530 |
|---|---|---|
| committer | Gurinder Singh <frederick.the.fool@gmail.com> | 2024-09-20 18:57:59 +0530 |
| commit | 716044751b7a36c634be709e37923e3dbdf53888 (patch) | |
| tree | ca74a4c27182f43712955c03c425cde89de59860 /tests | |
| parent | e2dc1a1c0f97a90319181a721ab317210307617a (diff) | |
| download | rust-716044751b7a36c634be709e37923e3dbdf53888.tar.gz rust-716044751b7a36c634be709e37923e3dbdf53888.zip | |
Add recursion limit to FFI safety lint
Fixes stack overflow in the case of recursive types
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/crashes/130310.rs | 15 | ||||
| -rw-r--r-- | tests/ui/lint/improper-types-stack-overflow-130310.rs | 20 | ||||
| -rw-r--r-- | tests/ui/lint/improper-types-stack-overflow-130310.stderr | 11 |
3 files changed, 31 insertions, 15 deletions
diff --git a/tests/crashes/130310.rs b/tests/crashes/130310.rs deleted file mode 100644 index d59dd39983c..00000000000 --- a/tests/crashes/130310.rs +++ /dev/null @@ -1,15 +0,0 @@ -//@ known-bug: rust-lang/rust#130310 - -use std::marker::PhantomData; - -#[repr(C)] -struct A<T> { - a: *const A<A<T>>, - p: PhantomData<T>, -} - -extern "C" { - fn f(a: *const A<()>); -} - -fn main() {} diff --git a/tests/ui/lint/improper-types-stack-overflow-130310.rs b/tests/ui/lint/improper-types-stack-overflow-130310.rs new file mode 100644 index 00000000000..60eb8739817 --- /dev/null +++ b/tests/ui/lint/improper-types-stack-overflow-130310.rs @@ -0,0 +1,20 @@ +// Regression test for #130310 +// Tests that we do not fall into infinite +// recursion while checking FFI safety of +// recursive types like `A<T>` below + +//@ build-pass +use std::marker::PhantomData; + +#[repr(C)] +struct A<T> { + a: *const A<A<T>>, // Recursive because of this field + p: PhantomData<T>, +} + +extern "C" { + fn f(a: *const A<()>); + //~^ WARN `extern` block uses type `*const A<()>`, which is not FFI-safe +} + +fn main() {} diff --git a/tests/ui/lint/improper-types-stack-overflow-130310.stderr b/tests/ui/lint/improper-types-stack-overflow-130310.stderr new file mode 100644 index 00000000000..6981bb25755 --- /dev/null +++ b/tests/ui/lint/improper-types-stack-overflow-130310.stderr @@ -0,0 +1,11 @@ +warning: `extern` block uses type `*const A<()>`, which is not FFI-safe + --> $DIR/improper-types-stack-overflow-130310.rs:16:13 + | +LL | fn f(a: *const A<()>); + | ^^^^^^^^^^^^ not FFI-safe + | + = note: type is infinitely recursive + = note: `#[warn(improper_ctypes)]` on by default + +warning: 1 warning emitted + |
