summary refs log tree commit diff
path: root/tests/ui/foreign
diff options
context:
space:
mode:
authorAlbert Larsan <74931857+albertlarsan68@users.noreply.github.com>2023-01-05 09:13:28 +0100
committerAlbert Larsan <74931857+albertlarsan68@users.noreply.github.com>2023-01-11 09:32:08 +0000
commitcf2dff2b1e3fa55fa5415d524200070d0d7aacfe (patch)
tree40a88d9a46aaf3e8870676eb2538378b75a263eb /tests/ui/foreign
parentca855e6e42787ecd062d81d53336fe6788ef51a9 (diff)
downloadrust-cf2dff2b1e3fa55fa5415d524200070d0d7aacfe.tar.gz
rust-cf2dff2b1e3fa55fa5415d524200070d0d7aacfe.zip
Move /src/test to /tests
Diffstat (limited to 'tests/ui/foreign')
-rw-r--r--tests/ui/foreign/auxiliary/fn-abi.rs2
-rw-r--r--tests/ui/foreign/foreign-fn-linkname.rs28
-rw-r--r--tests/ui/foreign/foreign-int-types.rs12
-rw-r--r--tests/ui/foreign/foreign-mod-src/compiletest-ignore-dir0
-rw-r--r--tests/ui/foreign/foreign-mod-src/inner.rs14
-rw-r--r--tests/ui/foreign/foreign-mod-unused-const.rs11
-rw-r--r--tests/ui/foreign/foreign-pub-super.rs12
-rw-r--r--tests/ui/foreign/foreign-src/compiletest-ignore-dir0
-rw-r--r--tests/ui/foreign/foreign-src/foreign.rs9
-rw-r--r--tests/ui/foreign/foreign-truncated-arguments.rs20
-rw-r--r--tests/ui/foreign/foreign2.rs29
-rw-r--r--tests/ui/foreign/issue-74120-lowering-of-ffi-block-bodies.rs11
-rw-r--r--tests/ui/foreign/issue-74120-lowering-of-ffi-block-bodies.stderr19
-rw-r--r--tests/ui/foreign/issue-91370-foreign-fn-block-impl.rs12
-rw-r--r--tests/ui/foreign/issue-91370-foreign-fn-block-impl.stderr21
-rw-r--r--tests/ui/foreign/issue-99276-same-type-lifetimes.rs24
-rw-r--r--tests/ui/foreign/nil-decl-in-foreign.rs14
17 files changed, 238 insertions, 0 deletions
diff --git a/tests/ui/foreign/auxiliary/fn-abi.rs b/tests/ui/foreign/auxiliary/fn-abi.rs
new file mode 100644
index 00000000000..25c9e1b4ca3
--- /dev/null
+++ b/tests/ui/foreign/auxiliary/fn-abi.rs
@@ -0,0 +1,2 @@
+#[no_mangle]
+pub extern fn foo() {}
diff --git a/tests/ui/foreign/foreign-fn-linkname.rs b/tests/ui/foreign/foreign-fn-linkname.rs
new file mode 100644
index 00000000000..f6d820594f9
--- /dev/null
+++ b/tests/ui/foreign/foreign-fn-linkname.rs
@@ -0,0 +1,28 @@
+// run-pass
+// ignore-wasm32-bare no libc to test ffi with
+// ignore-sgx no libc
+
+#![feature(rustc_private)]
+
+extern crate libc;
+use std::ffi::CString;
+
+mod mlibc {
+    use libc::{c_char, size_t};
+
+    extern "C" {
+        #[link_name = "strlen"]
+        pub fn my_strlen(str: *const c_char) -> size_t;
+    }
+}
+
+fn strlen(str: String) -> usize {
+    // C string is terminated with a zero
+    let s = CString::new(str).unwrap();
+    unsafe { mlibc::my_strlen(s.as_ptr()) as usize }
+}
+
+pub fn main() {
+    let len = strlen("Rust".to_string());
+    assert_eq!(len, 4);
+}
diff --git a/tests/ui/foreign/foreign-int-types.rs b/tests/ui/foreign/foreign-int-types.rs
new file mode 100644
index 00000000000..2d01d320425
--- /dev/null
+++ b/tests/ui/foreign/foreign-int-types.rs
@@ -0,0 +1,12 @@
+// run-pass
+#![forbid(improper_ctypes)]
+#![allow(dead_code)]
+
+mod xx {
+    extern "C" {
+        pub fn strlen(str: *const u8) -> usize;
+        pub fn foo(x: isize, y: usize);
+    }
+}
+
+fn main() {}
diff --git a/tests/ui/foreign/foreign-mod-src/compiletest-ignore-dir b/tests/ui/foreign/foreign-mod-src/compiletest-ignore-dir
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/tests/ui/foreign/foreign-mod-src/compiletest-ignore-dir
diff --git a/tests/ui/foreign/foreign-mod-src/inner.rs b/tests/ui/foreign/foreign-mod-src/inner.rs
new file mode 100644
index 00000000000..cf484878b07
--- /dev/null
+++ b/tests/ui/foreign/foreign-mod-src/inner.rs
@@ -0,0 +1,14 @@
+// run-pass
+
+
+
+pub fn main() {
+    let f = "Makefile";
+    let s = rustrt.str_buf(f);
+    let buf = libc.malloc(1024);
+    let fd = libc.open(s, 0, 0);
+    libc.read(fd, buf, 1024);
+    libc.write(1, buf, 1024);
+    libc.close(fd);
+    libc.free(buf);
+}
diff --git a/tests/ui/foreign/foreign-mod-unused-const.rs b/tests/ui/foreign/foreign-mod-unused-const.rs
new file mode 100644
index 00000000000..7d79c30f469
--- /dev/null
+++ b/tests/ui/foreign/foreign-mod-unused-const.rs
@@ -0,0 +1,11 @@
+// run-pass
+#![allow(dead_code)]
+// pretty-expanded FIXME #23616
+
+mod foo {
+    extern "C" {
+        pub static errno: u32;
+    }
+}
+
+pub fn main() {}
diff --git a/tests/ui/foreign/foreign-pub-super.rs b/tests/ui/foreign/foreign-pub-super.rs
new file mode 100644
index 00000000000..19f9e4e339e
--- /dev/null
+++ b/tests/ui/foreign/foreign-pub-super.rs
@@ -0,0 +1,12 @@
+// Test for #79487
+// check-pass
+
+#![allow(dead_code)]
+
+mod sha2 {
+    extern "C" {
+        pub(super) fn GFp_sha512_block_data_order();
+    }
+}
+
+fn main() {}
diff --git a/tests/ui/foreign/foreign-src/compiletest-ignore-dir b/tests/ui/foreign/foreign-src/compiletest-ignore-dir
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/tests/ui/foreign/foreign-src/compiletest-ignore-dir
diff --git a/tests/ui/foreign/foreign-src/foreign.rs b/tests/ui/foreign/foreign-src/foreign.rs
new file mode 100644
index 00000000000..47016ad6ce7
--- /dev/null
+++ b/tests/ui/foreign/foreign-src/foreign.rs
@@ -0,0 +1,9 @@
+// run-pass
+
+
+
+pub fn main() {
+    libc.puts(rustrt.str_buf("hello, extern world 1"));
+    libc.puts(rustrt.str_buf("hello, extern world 2"));
+    libc.puts(rustrt.str_buf("hello, extern world 3"));
+}
diff --git a/tests/ui/foreign/foreign-truncated-arguments.rs b/tests/ui/foreign/foreign-truncated-arguments.rs
new file mode 100644
index 00000000000..c61c2b587b6
--- /dev/null
+++ b/tests/ui/foreign/foreign-truncated-arguments.rs
@@ -0,0 +1,20 @@
+// run-pass
+// compile-flags: -O
+// Regression test for https://github.com/rust-lang/rust/issues/33868
+
+#[repr(C)]
+pub struct S {
+    a: u32,
+    b: f32,
+    c: u32
+}
+
+#[no_mangle]
+#[inline(never)]
+pub extern "C" fn test(s: S) -> u32 {
+    s.c
+}
+
+fn main() {
+    assert_eq!(test(S{a: 0, b: 0.0, c: 42}), 42);
+}
diff --git a/tests/ui/foreign/foreign2.rs b/tests/ui/foreign/foreign2.rs
new file mode 100644
index 00000000000..df431f2999c
--- /dev/null
+++ b/tests/ui/foreign/foreign2.rs
@@ -0,0 +1,29 @@
+// run-pass
+#![allow(dead_code)]
+// ignore-wasm32-bare no libc to test ffi with
+// pretty-expanded FIXME #23616
+#![feature(rustc_private)]
+
+extern crate libc;
+
+mod bar {
+    extern "C" {}
+}
+
+mod zed {
+    extern "C" {}
+}
+
+mod mlibc {
+    use libc::{c_int, c_void, size_t, ssize_t};
+
+    extern "C" {
+        pub fn write(fd: c_int, buf: *const c_void, count: size_t) -> ssize_t;
+    }
+}
+
+mod baz {
+    extern "C" {}
+}
+
+pub fn main() {}
diff --git a/tests/ui/foreign/issue-74120-lowering-of-ffi-block-bodies.rs b/tests/ui/foreign/issue-74120-lowering-of-ffi-block-bodies.rs
new file mode 100644
index 00000000000..a84065e0218
--- /dev/null
+++ b/tests/ui/foreign/issue-74120-lowering-of-ffi-block-bodies.rs
@@ -0,0 +1,11 @@
+// Previously this ICE'd because `fn g()` would be lowered, but the block associated with `fn f()`
+// wasn't.
+
+// compile-flags: --crate-type=lib
+
+extern "C" {
+    fn f() {
+    //~^ incorrect function inside `extern` block
+        fn g() {}
+    }
+}
diff --git a/tests/ui/foreign/issue-74120-lowering-of-ffi-block-bodies.stderr b/tests/ui/foreign/issue-74120-lowering-of-ffi-block-bodies.stderr
new file mode 100644
index 00000000000..d4a9ca3e7c6
--- /dev/null
+++ b/tests/ui/foreign/issue-74120-lowering-of-ffi-block-bodies.stderr
@@ -0,0 +1,19 @@
+error: incorrect function inside `extern` block
+  --> $DIR/issue-74120-lowering-of-ffi-block-bodies.rs:7:8
+   |
+LL |   extern "C" {
+   |   ---------- `extern` blocks define existing foreign functions and functions inside of them cannot have a body
+LL |       fn f() {
+   |  ________^___-
+   | |        |
+   | |        cannot have a body
+LL | |
+LL | |         fn g() {}
+LL | |     }
+   | |_____- help: remove the invalid body: `;`
+   |
+   = help: you might have meant to write a function accessible through FFI, which can be done by writing `extern fn` outside of the `extern` block
+   = note: for more information, visit https://doc.rust-lang.org/std/keyword.extern.html
+
+error: aborting due to previous error
+
diff --git a/tests/ui/foreign/issue-91370-foreign-fn-block-impl.rs b/tests/ui/foreign/issue-91370-foreign-fn-block-impl.rs
new file mode 100644
index 00000000000..2ac3ca29355
--- /dev/null
+++ b/tests/ui/foreign/issue-91370-foreign-fn-block-impl.rs
@@ -0,0 +1,12 @@
+// Regression test for issue #91370.
+
+extern {
+    //~^ `extern` blocks define existing foreign functions
+    fn f() {
+        //~^ incorrect function inside `extern` block
+        //~| cannot have a body
+        impl Copy for u8 {}
+    }
+}
+
+fn main() {}
diff --git a/tests/ui/foreign/issue-91370-foreign-fn-block-impl.stderr b/tests/ui/foreign/issue-91370-foreign-fn-block-impl.stderr
new file mode 100644
index 00000000000..4fb2f8c659c
--- /dev/null
+++ b/tests/ui/foreign/issue-91370-foreign-fn-block-impl.stderr
@@ -0,0 +1,21 @@
+error: incorrect function inside `extern` block
+  --> $DIR/issue-91370-foreign-fn-block-impl.rs:5:8
+   |
+LL |   extern {
+   |   ------ `extern` blocks define existing foreign functions and functions inside of them cannot have a body
+LL |
+LL |       fn f() {
+   |  ________^___-
+   | |        |
+   | |        cannot have a body
+LL | |
+LL | |
+LL | |         impl Copy for u8 {}
+LL | |     }
+   | |_____- help: remove the invalid body: `;`
+   |
+   = help: you might have meant to write a function accessible through FFI, which can be done by writing `extern fn` outside of the `extern` block
+   = note: for more information, visit https://doc.rust-lang.org/std/keyword.extern.html
+
+error: aborting due to previous error
+
diff --git a/tests/ui/foreign/issue-99276-same-type-lifetimes.rs b/tests/ui/foreign/issue-99276-same-type-lifetimes.rs
new file mode 100644
index 00000000000..fce603c801f
--- /dev/null
+++ b/tests/ui/foreign/issue-99276-same-type-lifetimes.rs
@@ -0,0 +1,24 @@
+// Check that we do not ICE when structurally comparing types with lifetimes present.
+// check-pass
+
+pub struct Record<'a> {
+    pub args: &'a [(usize, &'a str)],
+}
+
+mod a {
+    extern "Rust" {
+        fn foo<'a, 'b>(record: &'a super::Record<'b>);
+
+        fn bar<'a, 'b>(record: &'a super::Record<'b>);
+    }
+}
+
+mod b {
+    extern "Rust" {
+        fn foo<'a, 'b>(record: &'a super::Record<'b>);
+
+        fn bar<'a, 'b>(record: &'a super::Record<'b>);
+    }
+}
+
+fn main() {}
diff --git a/tests/ui/foreign/nil-decl-in-foreign.rs b/tests/ui/foreign/nil-decl-in-foreign.rs
new file mode 100644
index 00000000000..f3be948781b
--- /dev/null
+++ b/tests/ui/foreign/nil-decl-in-foreign.rs
@@ -0,0 +1,14 @@
+// run-pass
+
+#![allow(improper_ctypes)]
+#![allow(dead_code)]
+// Issue #901
+// pretty-expanded FIXME #23616
+
+mod libc {
+    extern "C" {
+        pub fn printf(x: ());
+    }
+}
+
+pub fn main() {}