diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:13 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:13 +0000 |
commit | 218caa410aa38c29984be31a5229b9fa717560ee (patch) | |
tree | c54bd55eeb6e4c508940a30e94c0032fbd45d677 /tests/ui/foreign | |
parent | Releasing progress-linux version 1.67.1+dfsg1-1~progress7.99u1. (diff) | |
download | rustc-218caa410aa38c29984be31a5229b9fa717560ee.tar.xz rustc-218caa410aa38c29984be31a5229b9fa717560ee.zip |
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/foreign')
-rw-r--r-- | tests/ui/foreign/auxiliary/fn-abi.rs | 2 | ||||
-rw-r--r-- | tests/ui/foreign/foreign-fn-linkname.rs | 28 | ||||
-rw-r--r-- | tests/ui/foreign/foreign-int-types.rs | 12 | ||||
-rw-r--r-- | tests/ui/foreign/foreign-mod-src/compiletest-ignore-dir | 0 | ||||
-rw-r--r-- | tests/ui/foreign/foreign-mod-src/inner.rs | 14 | ||||
-rw-r--r-- | tests/ui/foreign/foreign-mod-unused-const.rs | 11 | ||||
-rw-r--r-- | tests/ui/foreign/foreign-pub-super.rs | 12 | ||||
-rw-r--r-- | tests/ui/foreign/foreign-src/compiletest-ignore-dir | 0 | ||||
-rw-r--r-- | tests/ui/foreign/foreign-src/foreign.rs | 9 | ||||
-rw-r--r-- | tests/ui/foreign/foreign-truncated-arguments.rs | 20 | ||||
-rw-r--r-- | tests/ui/foreign/foreign2.rs | 29 | ||||
-rw-r--r-- | tests/ui/foreign/issue-74120-lowering-of-ffi-block-bodies.rs | 11 | ||||
-rw-r--r-- | tests/ui/foreign/issue-74120-lowering-of-ffi-block-bodies.stderr | 19 | ||||
-rw-r--r-- | tests/ui/foreign/issue-91370-foreign-fn-block-impl.rs | 12 | ||||
-rw-r--r-- | tests/ui/foreign/issue-91370-foreign-fn-block-impl.stderr | 21 | ||||
-rw-r--r-- | tests/ui/foreign/issue-99276-same-type-lifetimes.rs | 24 | ||||
-rw-r--r-- | tests/ui/foreign/nil-decl-in-foreign.rs | 14 |
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 000000000..25c9e1b4c --- /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 000000000..f6d820594 --- /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 000000000..2d01d3204 --- /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 000000000..e69de29bb --- /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 000000000..cf484878b --- /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 000000000..7d79c30f4 --- /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 000000000..19f9e4e33 --- /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 000000000..e69de29bb --- /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 000000000..47016ad6c --- /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 000000000..c61c2b587 --- /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 000000000..df431f299 --- /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 000000000..a84065e02 --- /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 000000000..d4a9ca3e7 --- /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 000000000..2ac3ca293 --- /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 000000000..4fb2f8c65 --- /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 000000000..fce603c80 --- /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 000000000..f3be94878 --- /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() {} |