summaryrefslogtreecommitdiffstats
path: root/tests/ui/c-variadic
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:03 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:03 +0000
commit64d98f8ee037282c35007b64c2649055c56af1db (patch)
tree5492bcf97fce41ee1c0b1cc2add283f3e66cdab0 /tests/ui/c-variadic
parentAdding debian version 1.67.1+dfsg1-1. (diff)
downloadrustc-64d98f8ee037282c35007b64c2649055c56af1db.tar.xz
rustc-64d98f8ee037282c35007b64c2649055c56af1db.zip
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/c-variadic')
-rw-r--r--tests/ui/c-variadic/feature-gate-extended_varargs_abi_support.rs17
-rw-r--r--tests/ui/c-variadic/feature-gate-extended_varargs_abi_support.stderr49
-rw-r--r--tests/ui/c-variadic/issue-32201.rs13
-rw-r--r--tests/ui/c-variadic/issue-32201.stderr9
-rw-r--r--tests/ui/c-variadic/issue-86053-1.rs12
-rw-r--r--tests/ui/c-variadic/issue-86053-1.stderr81
-rw-r--r--tests/ui/c-variadic/issue-86053-2.rs11
-rw-r--r--tests/ui/c-variadic/issue-86053-2.stderr16
-rw-r--r--tests/ui/c-variadic/variadic-ffi-1.rs35
-rw-r--r--tests/ui/c-variadic/variadic-ffi-1.stderr100
-rw-r--r--tests/ui/c-variadic/variadic-ffi-2.rs20
-rw-r--r--tests/ui/c-variadic/variadic-ffi-2.stderr9
-rw-r--r--tests/ui/c-variadic/variadic-ffi-4.rs38
-rw-r--r--tests/ui/c-variadic/variadic-ffi-4.stderr150
-rw-r--r--tests/ui/c-variadic/variadic-ffi-6.rs13
-rw-r--r--tests/ui/c-variadic/variadic-ffi-6.stderr15
-rw-r--r--tests/ui/c-variadic/variadic-ffi-no-fixed-args.rs6
-rw-r--r--tests/ui/c-variadic/variadic-ffi-no-fixed-args.stderr8
-rw-r--r--tests/ui/c-variadic/variadic-unreachable-arg-error.rs14
19 files changed, 616 insertions, 0 deletions
diff --git a/tests/ui/c-variadic/feature-gate-extended_varargs_abi_support.rs b/tests/ui/c-variadic/feature-gate-extended_varargs_abi_support.rs
new file mode 100644
index 000000000..fce6210b2
--- /dev/null
+++ b/tests/ui/c-variadic/feature-gate-extended_varargs_abi_support.rs
@@ -0,0 +1,17 @@
+fn efiapi(f: extern "efiapi" fn(usize, ...)) {
+ //~^ ERROR: C-variadic function must have a compatible calling convention, like `C` or `cdecl`
+ //~^^ ERROR: using calling conventions other than `C` or `cdecl` for varargs functions is unstable
+ f(22, 44);
+}
+fn sysv(f: extern "sysv64" fn(usize, ...)) {
+ //~^ ERROR: C-variadic function must have a compatible calling convention, like `C` or `cdecl`
+ //~^^ ERROR: using calling conventions other than `C` or `cdecl` for varargs functions is unstable
+ f(22, 44);
+}
+fn win(f: extern "win64" fn(usize, ...)) {
+ //~^ ERROR: C-variadic function must have a compatible calling convention, like `C` or `cdecl`
+ //~^^ ERROR: using calling conventions other than `C` or `cdecl` for varargs functions is unstable
+ f(22, 44);
+}
+
+fn main() {}
diff --git a/tests/ui/c-variadic/feature-gate-extended_varargs_abi_support.stderr b/tests/ui/c-variadic/feature-gate-extended_varargs_abi_support.stderr
new file mode 100644
index 000000000..5b97b396f
--- /dev/null
+++ b/tests/ui/c-variadic/feature-gate-extended_varargs_abi_support.stderr
@@ -0,0 +1,49 @@
+error[E0658]: using calling conventions other than `C` or `cdecl` for varargs functions is unstable
+ --> $DIR/feature-gate-extended_varargs_abi_support.rs:1:14
+ |
+LL | fn efiapi(f: extern "efiapi" fn(usize, ...)) {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: see issue #100189 <https://github.com/rust-lang/rust/issues/100189> for more information
+ = help: add `#![feature(extended_varargs_abi_support)]` to the crate attributes to enable
+
+error[E0045]: C-variadic function must have a compatible calling convention, like `C` or `cdecl`
+ --> $DIR/feature-gate-extended_varargs_abi_support.rs:1:14
+ |
+LL | fn efiapi(f: extern "efiapi" fn(usize, ...)) {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ C-variadic function must have a compatible calling convention
+
+error[E0658]: using calling conventions other than `C` or `cdecl` for varargs functions is unstable
+ --> $DIR/feature-gate-extended_varargs_abi_support.rs:6:12
+ |
+LL | fn sysv(f: extern "sysv64" fn(usize, ...)) {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: see issue #100189 <https://github.com/rust-lang/rust/issues/100189> for more information
+ = help: add `#![feature(extended_varargs_abi_support)]` to the crate attributes to enable
+
+error[E0045]: C-variadic function must have a compatible calling convention, like `C` or `cdecl`
+ --> $DIR/feature-gate-extended_varargs_abi_support.rs:6:12
+ |
+LL | fn sysv(f: extern "sysv64" fn(usize, ...)) {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ C-variadic function must have a compatible calling convention
+
+error[E0658]: using calling conventions other than `C` or `cdecl` for varargs functions is unstable
+ --> $DIR/feature-gate-extended_varargs_abi_support.rs:11:11
+ |
+LL | fn win(f: extern "win64" fn(usize, ...)) {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: see issue #100189 <https://github.com/rust-lang/rust/issues/100189> for more information
+ = help: add `#![feature(extended_varargs_abi_support)]` to the crate attributes to enable
+
+error[E0045]: C-variadic function must have a compatible calling convention, like `C` or `cdecl`
+ --> $DIR/feature-gate-extended_varargs_abi_support.rs:11:11
+ |
+LL | fn win(f: extern "win64" fn(usize, ...)) {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ C-variadic function must have a compatible calling convention
+
+error: aborting due to 6 previous errors
+
+Some errors have detailed explanations: E0045, E0658.
+For more information about an error, try `rustc --explain E0045`.
diff --git a/tests/ui/c-variadic/issue-32201.rs b/tests/ui/c-variadic/issue-32201.rs
new file mode 100644
index 000000000..f27bb1c2e
--- /dev/null
+++ b/tests/ui/c-variadic/issue-32201.rs
@@ -0,0 +1,13 @@
+extern "C" {
+ fn foo(a: i32, ...);
+}
+
+fn bar(_: *const u8) {}
+
+fn main() {
+ unsafe {
+ foo(0, bar);
+ //~^ ERROR can't pass `fn(*const u8) {bar}` to variadic function
+ //~| HELP cast the value to `fn(*const u8)`
+ }
+}
diff --git a/tests/ui/c-variadic/issue-32201.stderr b/tests/ui/c-variadic/issue-32201.stderr
new file mode 100644
index 000000000..cedb58784
--- /dev/null
+++ b/tests/ui/c-variadic/issue-32201.stderr
@@ -0,0 +1,9 @@
+error[E0617]: can't pass `fn(*const u8) {bar}` to variadic function
+ --> $DIR/issue-32201.rs:9:16
+ |
+LL | foo(0, bar);
+ | ^^^ help: cast the value to `fn(*const u8)`: `bar as fn(*const u8)`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0617`.
diff --git a/tests/ui/c-variadic/issue-86053-1.rs b/tests/ui/c-variadic/issue-86053-1.rs
new file mode 100644
index 000000000..49d5c0390
--- /dev/null
+++ b/tests/ui/c-variadic/issue-86053-1.rs
@@ -0,0 +1,12 @@
+// Regression test for the ICE described in issue #86053.
+// error-pattern:unexpected `self` parameter in function
+// error-pattern:`...` must be the last argument of a C-variadic function
+// error-pattern:cannot find type `F` in this scope
+
+
+#![feature(c_variadic)]
+#![crate_type="lib"]
+
+fn ordering4 < 'a , 'b > ( a : , self , self , self ,
+ self , ... , self , self , ... ) where F : FnOnce ( & 'a & 'b usize ) {
+}
diff --git a/tests/ui/c-variadic/issue-86053-1.stderr b/tests/ui/c-variadic/issue-86053-1.stderr
new file mode 100644
index 000000000..5a02f4aa9
--- /dev/null
+++ b/tests/ui/c-variadic/issue-86053-1.stderr
@@ -0,0 +1,81 @@
+error: expected type, found `,`
+ --> $DIR/issue-86053-1.rs:10:47
+ |
+LL | fn ordering4 < 'a , 'b > ( a : , self , self , self ,
+ | ^ expected type
+
+error: unexpected `self` parameter in function
+ --> $DIR/issue-86053-1.rs:10:51
+ |
+LL | fn ordering4 < 'a , 'b > ( a : , self , self , self ,
+ | ^^^^ must be the first parameter of an associated function
+
+error: unexpected `self` parameter in function
+ --> $DIR/issue-86053-1.rs:10:58
+ |
+LL | fn ordering4 < 'a , 'b > ( a : , self , self , self ,
+ | ^^^^ must be the first parameter of an associated function
+
+error: unexpected `self` parameter in function
+ --> $DIR/issue-86053-1.rs:10:67
+ |
+LL | fn ordering4 < 'a , 'b > ( a : , self , self , self ,
+ | ^^^^ must be the first parameter of an associated function
+
+error: unexpected `self` parameter in function
+ --> $DIR/issue-86053-1.rs:11:5
+ |
+LL | self , ... , self , self , ... ) where F : FnOnce ( & 'a & 'b usize ) {
+ | ^^^^ must be the first parameter of an associated function
+
+error: unexpected `self` parameter in function
+ --> $DIR/issue-86053-1.rs:11:20
+ |
+LL | self , ... , self , self , ... ) where F : FnOnce ( & 'a & 'b usize ) {
+ | ^^^^ must be the first parameter of an associated function
+
+error: unexpected `self` parameter in function
+ --> $DIR/issue-86053-1.rs:11:29
+ |
+LL | self , ... , self , self , ... ) where F : FnOnce ( & 'a & 'b usize ) {
+ | ^^^^ must be the first parameter of an associated function
+
+error: `...` must be the last argument of a C-variadic function
+ --> $DIR/issue-86053-1.rs:11:12
+ |
+LL | self , ... , self , self , ... ) where F : FnOnce ( & 'a & 'b usize ) {
+ | ^^^
+
+error: only foreign or `unsafe extern "C"` functions may be C-variadic
+ --> $DIR/issue-86053-1.rs:11:12
+ |
+LL | self , ... , self , self , ... ) where F : FnOnce ( & 'a & 'b usize ) {
+ | ^^^
+
+error: only foreign or `unsafe extern "C"` functions may be C-variadic
+ --> $DIR/issue-86053-1.rs:11:36
+ |
+LL | self , ... , self , self , ... ) where F : FnOnce ( & 'a & 'b usize ) {
+ | ^^^
+
+error[E0412]: cannot find type `F` in this scope
+ --> $DIR/issue-86053-1.rs:11:48
+ |
+LL | self , ... , self , self , ... ) where F : FnOnce ( & 'a & 'b usize ) {
+ | ^
+ --> $SRC_DIR/core/src/ops/function.rs:LL:COL
+ |
+ = note: similarly named trait `Fn` defined here
+ |
+help: a trait with a similar name exists
+ |
+LL | self , ... , self , self , ... ) where Fn : FnOnce ( & 'a & 'b usize ) {
+ | ~~
+help: you might be missing a type parameter
+ |
+LL | fn ordering4 < 'a , 'b, F > ( a : , self , self , self ,
+ | +++
+
+error: aborting due to 11 previous errors
+
+For more information about this error, try `rustc --explain E0412`.
diff --git a/tests/ui/c-variadic/issue-86053-2.rs b/tests/ui/c-variadic/issue-86053-2.rs
new file mode 100644
index 000000000..c545831f7
--- /dev/null
+++ b/tests/ui/c-variadic/issue-86053-2.rs
@@ -0,0 +1,11 @@
+// Regression test for the ICE caused by the example in
+// https://github.com/rust-lang/rust/issues/86053#issuecomment-855672258
+
+#![feature(c_variadic)]
+
+trait H<T> {}
+
+unsafe extern "C" fn ordering4<'a, F: H<&'static &'a ()>>(_: (), ...) {}
+//~^ ERROR: in type `&'static &'a ()`, reference has a longer lifetime than the data it references [E0491]
+
+fn main() {}
diff --git a/tests/ui/c-variadic/issue-86053-2.stderr b/tests/ui/c-variadic/issue-86053-2.stderr
new file mode 100644
index 000000000..815b06e77
--- /dev/null
+++ b/tests/ui/c-variadic/issue-86053-2.stderr
@@ -0,0 +1,16 @@
+error[E0491]: in type `&'static &'a ()`, reference has a longer lifetime than the data it references
+ --> $DIR/issue-86053-2.rs:8:39
+ |
+LL | unsafe extern "C" fn ordering4<'a, F: H<&'static &'a ()>>(_: (), ...) {}
+ | ^^^^^^^^^^^^^^^^^^
+ |
+ = note: the pointer is valid for the static lifetime
+note: but the referenced data is only valid for the lifetime `'a` as defined here
+ --> $DIR/issue-86053-2.rs:8:32
+ |
+LL | unsafe extern "C" fn ordering4<'a, F: H<&'static &'a ()>>(_: (), ...) {}
+ | ^^
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0491`.
diff --git a/tests/ui/c-variadic/variadic-ffi-1.rs b/tests/ui/c-variadic/variadic-ffi-1.rs
new file mode 100644
index 000000000..acd8a25dc
--- /dev/null
+++ b/tests/ui/c-variadic/variadic-ffi-1.rs
@@ -0,0 +1,35 @@
+// needs-llvm-components: x86
+// compile-flags: --target=i686-pc-windows-msvc --crate-type=rlib
+#![no_core]
+#![feature(no_core, lang_items)]
+#[lang="sized"]
+trait Sized { }
+
+extern "stdcall" {
+ fn printf(_: *const u8, ...);
+ //~^ ERROR: C-variadic function must have a compatible calling convention,
+ // like C, cdecl, win64, sysv64 or efiapi
+}
+
+extern "C" {
+ fn foo(f: isize, x: u8, ...);
+}
+
+extern "C" fn bar(f: isize, x: u8) {}
+
+fn main() {
+ unsafe {
+ foo(); //~ ERROR function takes at least 2 arguments but 0 arguments were supplied
+ foo(1); //~ ERROR function takes at least 2 arguments but 1 argument was supplied
+
+ let x: unsafe extern "C" fn(f: isize, x: u8) = foo; //~ ERROR mismatched types
+ let y: extern "C" fn(f: isize, x: u8, ...) = bar; //~ ERROR mismatched types
+
+ foo(1, 2, 3f32); //~ ERROR can't pass
+ foo(1, 2, true); //~ ERROR can't pass
+ foo(1, 2, 1i8); //~ ERROR can't pass
+ foo(1, 2, 1u8); //~ ERROR can't pass
+ foo(1, 2, 1i16); //~ ERROR can't pass
+ foo(1, 2, 1u16); //~ ERROR can't pass
+ }
+}
diff --git a/tests/ui/c-variadic/variadic-ffi-1.stderr b/tests/ui/c-variadic/variadic-ffi-1.stderr
new file mode 100644
index 000000000..4beea83d8
--- /dev/null
+++ b/tests/ui/c-variadic/variadic-ffi-1.stderr
@@ -0,0 +1,100 @@
+error[E0045]: C-variadic function must have a compatible calling convention, like `C` or `cdecl`
+ --> $DIR/variadic-ffi-1.rs:9:5
+ |
+LL | fn printf(_: *const u8, ...);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ C-variadic function must have a compatible calling convention
+
+error[E0060]: this function takes at least 2 arguments but 0 arguments were supplied
+ --> $DIR/variadic-ffi-1.rs:22:9
+ |
+LL | foo();
+ | ^^^-- two arguments of type `isize` and `u8` are missing
+ |
+note: function defined here
+ --> $DIR/variadic-ffi-1.rs:15:8
+ |
+LL | fn foo(f: isize, x: u8, ...);
+ | ^^^
+help: provide the arguments
+ |
+LL | foo(/* isize */, /* u8 */);
+ | ~~~~~~~~~~~~~~~~~~~~~~~
+
+error[E0060]: this function takes at least 2 arguments but 1 argument was supplied
+ --> $DIR/variadic-ffi-1.rs:23:9
+ |
+LL | foo(1);
+ | ^^^--- an argument of type `u8` is missing
+ |
+note: function defined here
+ --> $DIR/variadic-ffi-1.rs:15:8
+ |
+LL | fn foo(f: isize, x: u8, ...);
+ | ^^^
+help: provide the argument
+ |
+LL | foo(1, /* u8 */);
+ | ~~~~~~~~~~~~~
+
+error[E0308]: mismatched types
+ --> $DIR/variadic-ffi-1.rs:25:56
+ |
+LL | let x: unsafe extern "C" fn(f: isize, x: u8) = foo;
+ | ------------------------------------- ^^^ expected non-variadic fn, found variadic function
+ | |
+ | expected due to this
+ |
+ = note: expected fn pointer `unsafe extern "C" fn(_, _)`
+ found fn item `unsafe extern "C" fn(_, _, ...) {foo}`
+
+error[E0308]: mismatched types
+ --> $DIR/variadic-ffi-1.rs:26:54
+ |
+LL | let y: extern "C" fn(f: isize, x: u8, ...) = bar;
+ | ----------------------------------- ^^^ expected variadic fn, found non-variadic function
+ | |
+ | expected due to this
+ |
+ = note: expected fn pointer `extern "C" fn(_, _, ...)`
+ found fn item `extern "C" fn(_, _) {bar}`
+
+error[E0617]: can't pass `f32` to variadic function
+ --> $DIR/variadic-ffi-1.rs:28:19
+ |
+LL | foo(1, 2, 3f32);
+ | ^^^^ help: cast the value to `c_double`: `3f32 as c_double`
+
+error[E0617]: can't pass `bool` to variadic function
+ --> $DIR/variadic-ffi-1.rs:29:19
+ |
+LL | foo(1, 2, true);
+ | ^^^^ help: cast the value to `c_int`: `true as c_int`
+
+error[E0617]: can't pass `i8` to variadic function
+ --> $DIR/variadic-ffi-1.rs:30:19
+ |
+LL | foo(1, 2, 1i8);
+ | ^^^ help: cast the value to `c_int`: `1i8 as c_int`
+
+error[E0617]: can't pass `u8` to variadic function
+ --> $DIR/variadic-ffi-1.rs:31:19
+ |
+LL | foo(1, 2, 1u8);
+ | ^^^ help: cast the value to `c_uint`: `1u8 as c_uint`
+
+error[E0617]: can't pass `i16` to variadic function
+ --> $DIR/variadic-ffi-1.rs:32:19
+ |
+LL | foo(1, 2, 1i16);
+ | ^^^^ help: cast the value to `c_int`: `1i16 as c_int`
+
+error[E0617]: can't pass `u16` to variadic function
+ --> $DIR/variadic-ffi-1.rs:33:19
+ |
+LL | foo(1, 2, 1u16);
+ | ^^^^ help: cast the value to `c_uint`: `1u16 as c_uint`
+
+error: aborting due to 11 previous errors
+
+Some errors have detailed explanations: E0045, E0060, E0308, E0617.
+For more information about an error, try `rustc --explain E0045`.
diff --git a/tests/ui/c-variadic/variadic-ffi-2.rs b/tests/ui/c-variadic/variadic-ffi-2.rs
new file mode 100644
index 000000000..c34b7e55f
--- /dev/null
+++ b/tests/ui/c-variadic/variadic-ffi-2.rs
@@ -0,0 +1,20 @@
+// ignore-arm stdcall isn't supported
+#![feature(extended_varargs_abi_support)]
+
+fn baz(f: extern "stdcall" fn(usize, ...)) {
+ //~^ ERROR: C-variadic function must have a compatible calling convention,
+ // like C, cdecl, win64, sysv64 or efiapi
+ f(22, 44);
+}
+
+fn sysv(f: extern "sysv64" fn(usize, ...)) {
+ f(22, 44);
+}
+fn win(f: extern "win64" fn(usize, ...)) {
+ f(22, 44);
+}
+fn efiapi(f: extern "efiapi" fn(usize, ...)) {
+ f(22, 44);
+}
+
+fn main() {}
diff --git a/tests/ui/c-variadic/variadic-ffi-2.stderr b/tests/ui/c-variadic/variadic-ffi-2.stderr
new file mode 100644
index 000000000..e21001eca
--- /dev/null
+++ b/tests/ui/c-variadic/variadic-ffi-2.stderr
@@ -0,0 +1,9 @@
+error[E0045]: C-variadic function must have a compatible calling convention, like `C`, `cdecl`, `win64`, `sysv64` or `efiapi`
+ --> $DIR/variadic-ffi-2.rs:4:11
+ |
+LL | fn baz(f: extern "stdcall" fn(usize, ...)) {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ C-variadic function must have a compatible calling convention
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0045`.
diff --git a/tests/ui/c-variadic/variadic-ffi-4.rs b/tests/ui/c-variadic/variadic-ffi-4.rs
new file mode 100644
index 000000000..806403794
--- /dev/null
+++ b/tests/ui/c-variadic/variadic-ffi-4.rs
@@ -0,0 +1,38 @@
+#![crate_type = "lib"]
+#![no_std]
+#![feature(c_variadic)]
+
+use core::ffi::{VaList, VaListImpl};
+
+pub unsafe extern "C" fn no_escape0<'f>(_: usize, ap: ...) -> VaListImpl<'f> {
+ ap
+ //~^ ERROR: lifetime may not live long enough
+ //~| ERROR: lifetime may not live long enough
+}
+
+pub unsafe extern "C" fn no_escape1(_: usize, ap: ...) -> VaListImpl<'static> {
+ ap //~ ERROR: lifetime may not live long enough
+}
+
+pub unsafe extern "C" fn no_escape2(_: usize, ap: ...) {
+ let _ = ap.with_copy(|ap| ap); //~ ERROR: lifetime may not live long enough
+}
+
+pub unsafe extern "C" fn no_escape3(_: usize, mut ap0: &mut VaListImpl, mut ap1: ...) {
+ *ap0 = ap1;
+ //~^ ERROR: lifetime may not live long enough
+ //~| ERROR: lifetime may not live long enough
+}
+
+pub unsafe extern "C" fn no_escape4(_: usize, mut ap0: &mut VaListImpl, mut ap1: ...) {
+ ap0 = &mut ap1;
+ //~^ ERROR: `ap1` does not live long enough
+ //~| ERROR: lifetime may not live long enough
+ //~| ERROR: lifetime may not live long enough
+}
+
+pub unsafe extern "C" fn no_escape5(_: usize, mut ap0: &mut VaListImpl, mut ap1: ...) {
+ *ap0 = ap1.clone();
+ //~^ ERROR: lifetime may not live long enough
+ //~| ERROR: lifetime may not live long enough
+}
diff --git a/tests/ui/c-variadic/variadic-ffi-4.stderr b/tests/ui/c-variadic/variadic-ffi-4.stderr
new file mode 100644
index 000000000..6f8e53298
--- /dev/null
+++ b/tests/ui/c-variadic/variadic-ffi-4.stderr
@@ -0,0 +1,150 @@
+error: lifetime may not live long enough
+ --> $DIR/variadic-ffi-4.rs:8:5
+ |
+LL | pub unsafe extern "C" fn no_escape0<'f>(_: usize, ap: ...) -> VaListImpl<'f> {
+ | -- -- has type `VaListImpl<'1>`
+ | |
+ | lifetime `'f` defined here
+LL | ap
+ | ^^ function was supposed to return data with lifetime `'1` but it is returning data with lifetime `'f`
+ |
+ = note: requirement occurs because of the type `VaListImpl<'_>`, which makes the generic argument `'_` invariant
+ = note: the struct `VaListImpl<'f>` is invariant over the parameter `'f`
+ = help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
+
+error: lifetime may not live long enough
+ --> $DIR/variadic-ffi-4.rs:8:5
+ |
+LL | pub unsafe extern "C" fn no_escape0<'f>(_: usize, ap: ...) -> VaListImpl<'f> {
+ | -- -- has type `VaListImpl<'1>`
+ | |
+ | lifetime `'f` defined here
+LL | ap
+ | ^^ function was supposed to return data with lifetime `'f` but it is returning data with lifetime `'1`
+ |
+ = note: requirement occurs because of the type `VaListImpl<'_>`, which makes the generic argument `'_` invariant
+ = note: the struct `VaListImpl<'f>` is invariant over the parameter `'f`
+ = help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
+
+error: lifetime may not live long enough
+ --> $DIR/variadic-ffi-4.rs:14:5
+ |
+LL | pub unsafe extern "C" fn no_escape1(_: usize, ap: ...) -> VaListImpl<'static> {
+ | -- has type `VaListImpl<'1>`
+LL | ap
+ | ^^ returning this value requires that `'1` must outlive `'static`
+ |
+ = note: requirement occurs because of the type `VaListImpl<'_>`, which makes the generic argument `'_` invariant
+ = note: the struct `VaListImpl<'f>` is invariant over the parameter `'f`
+ = help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
+
+error: lifetime may not live long enough
+ --> $DIR/variadic-ffi-4.rs:18:31
+ |
+LL | let _ = ap.with_copy(|ap| ap);
+ | --- ^^ returning this value requires that `'1` must outlive `'2`
+ | | |
+ | | return type of closure is VaList<'2, '_>
+ | has type `VaList<'1, '_>`
+
+error: lifetime may not live long enough
+ --> $DIR/variadic-ffi-4.rs:22:5
+ |
+LL | pub unsafe extern "C" fn no_escape3(_: usize, mut ap0: &mut VaListImpl, mut ap1: ...) {
+ | ------- ------- has type `VaListImpl<'2>`
+ | |
+ | has type `&mut VaListImpl<'1>`
+LL | *ap0 = ap1;
+ | ^^^^ assignment requires that `'1` must outlive `'2`
+ |
+ = note: requirement occurs because of the type `VaListImpl<'_>`, which makes the generic argument `'_` invariant
+ = note: the struct `VaListImpl<'f>` is invariant over the parameter `'f`
+ = help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
+
+error: lifetime may not live long enough
+ --> $DIR/variadic-ffi-4.rs:22:5
+ |
+LL | pub unsafe extern "C" fn no_escape3(_: usize, mut ap0: &mut VaListImpl, mut ap1: ...) {
+ | ------- ------- has type `VaListImpl<'2>`
+ | |
+ | has type `&mut VaListImpl<'1>`
+LL | *ap0 = ap1;
+ | ^^^^ assignment requires that `'2` must outlive `'1`
+ |
+ = note: requirement occurs because of the type `VaListImpl<'_>`, which makes the generic argument `'_` invariant
+ = note: the struct `VaListImpl<'f>` is invariant over the parameter `'f`
+ = help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
+
+error: lifetime may not live long enough
+ --> $DIR/variadic-ffi-4.rs:28:5
+ |
+LL | pub unsafe extern "C" fn no_escape4(_: usize, mut ap0: &mut VaListImpl, mut ap1: ...) {
+ | ------- ------- has type `VaListImpl<'2>`
+ | |
+ | has type `&mut VaListImpl<'1>`
+LL | ap0 = &mut ap1;
+ | ^^^^^^^^^^^^^^ assignment requires that `'1` must outlive `'2`
+ |
+ = note: requirement occurs because of a mutable reference to `VaListImpl<'_>`
+ = note: mutable references are invariant over their type parameter
+ = help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
+
+error: lifetime may not live long enough
+ --> $DIR/variadic-ffi-4.rs:28:5
+ |
+LL | pub unsafe extern "C" fn no_escape4(_: usize, mut ap0: &mut VaListImpl, mut ap1: ...) {
+ | ------- ------- has type `VaListImpl<'2>`
+ | |
+ | has type `&mut VaListImpl<'1>`
+LL | ap0 = &mut ap1;
+ | ^^^^^^^^^^^^^^ assignment requires that `'2` must outlive `'1`
+ |
+ = note: requirement occurs because of a mutable reference to `VaListImpl<'_>`
+ = note: mutable references are invariant over their type parameter
+ = help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
+
+error[E0597]: `ap1` does not live long enough
+ --> $DIR/variadic-ffi-4.rs:28:11
+ |
+LL | pub unsafe extern "C" fn no_escape4(_: usize, mut ap0: &mut VaListImpl, mut ap1: ...) {
+ | - let's call the lifetime of this reference `'3`
+LL | ap0 = &mut ap1;
+ | ------^^^^^^^^
+ | | |
+ | | borrowed value does not live long enough
+ | assignment requires that `ap1` is borrowed for `'3`
+...
+LL | }
+ | - `ap1` dropped here while still borrowed
+
+error: lifetime may not live long enough
+ --> $DIR/variadic-ffi-4.rs:35:12
+ |
+LL | pub unsafe extern "C" fn no_escape5(_: usize, mut ap0: &mut VaListImpl, mut ap1: ...) {
+ | ------- ------- has type `VaListImpl<'2>`
+ | |
+ | has type `&mut VaListImpl<'1>`
+LL | *ap0 = ap1.clone();
+ | ^^^^^^^^^^^ argument requires that `'1` must outlive `'2`
+ |
+ = note: requirement occurs because of the type `VaListImpl<'_>`, which makes the generic argument `'_` invariant
+ = note: the struct `VaListImpl<'f>` is invariant over the parameter `'f`
+ = help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
+
+error: lifetime may not live long enough
+ --> $DIR/variadic-ffi-4.rs:35:12
+ |
+LL | pub unsafe extern "C" fn no_escape5(_: usize, mut ap0: &mut VaListImpl, mut ap1: ...) {
+ | ------- ------- has type `VaListImpl<'2>`
+ | |
+ | has type `&mut VaListImpl<'1>`
+LL | *ap0 = ap1.clone();
+ | ^^^^^^^^^^^ argument requires that `'2` must outlive `'1`
+ |
+ = note: requirement occurs because of the type `VaListImpl<'_>`, which makes the generic argument `'_` invariant
+ = note: the struct `VaListImpl<'f>` is invariant over the parameter `'f`
+ = help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
+
+error: aborting due to 11 previous errors
+
+For more information about this error, try `rustc --explain E0597`.
diff --git a/tests/ui/c-variadic/variadic-ffi-6.rs b/tests/ui/c-variadic/variadic-ffi-6.rs
new file mode 100644
index 000000000..4dd8a2d45
--- /dev/null
+++ b/tests/ui/c-variadic/variadic-ffi-6.rs
@@ -0,0 +1,13 @@
+#![crate_type="lib"]
+#![feature(c_variadic)]
+
+pub unsafe extern "C" fn use_vararg_lifetime(
+ x: usize,
+ y: ...
+) -> &usize { //~ ERROR missing lifetime specifier
+ &0
+}
+
+pub unsafe extern "C" fn use_normal_arg_lifetime(x: &usize, y: ...) -> &usize { // OK
+ x
+}
diff --git a/tests/ui/c-variadic/variadic-ffi-6.stderr b/tests/ui/c-variadic/variadic-ffi-6.stderr
new file mode 100644
index 000000000..4c7792d96
--- /dev/null
+++ b/tests/ui/c-variadic/variadic-ffi-6.stderr
@@ -0,0 +1,15 @@
+error[E0106]: missing lifetime specifier
+ --> $DIR/variadic-ffi-6.rs:7:6
+ |
+LL | ) -> &usize {
+ | ^ expected named lifetime parameter
+ |
+ = help: this function's return type contains a borrowed value, but there is no value for it to be borrowed from
+help: consider using the `'static` lifetime
+ |
+LL | ) -> &'static usize {
+ | +++++++
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0106`.
diff --git a/tests/ui/c-variadic/variadic-ffi-no-fixed-args.rs b/tests/ui/c-variadic/variadic-ffi-no-fixed-args.rs
new file mode 100644
index 000000000..588c15a18
--- /dev/null
+++ b/tests/ui/c-variadic/variadic-ffi-no-fixed-args.rs
@@ -0,0 +1,6 @@
+extern "C" {
+ fn foo(...);
+//~^ ERROR C-variadic function must be declared with at least one named argument
+}
+
+fn main() {}
diff --git a/tests/ui/c-variadic/variadic-ffi-no-fixed-args.stderr b/tests/ui/c-variadic/variadic-ffi-no-fixed-args.stderr
new file mode 100644
index 000000000..e11ba43ca
--- /dev/null
+++ b/tests/ui/c-variadic/variadic-ffi-no-fixed-args.stderr
@@ -0,0 +1,8 @@
+error: C-variadic function must be declared with at least one named argument
+ --> $DIR/variadic-ffi-no-fixed-args.rs:2:12
+ |
+LL | fn foo(...);
+ | ^^^
+
+error: aborting due to previous error
+
diff --git a/tests/ui/c-variadic/variadic-unreachable-arg-error.rs b/tests/ui/c-variadic/variadic-unreachable-arg-error.rs
new file mode 100644
index 000000000..f60f6f3e8
--- /dev/null
+++ b/tests/ui/c-variadic/variadic-unreachable-arg-error.rs
@@ -0,0 +1,14 @@
+// check-pass
+
+#![feature(c_variadic)]
+
+extern "C" {
+ fn foo(f: isize, x: u8, ...);
+}
+
+fn main() {
+ unsafe {
+ // FIXME: Ideally we could give an unreachable warning
+ foo(1, loop {}, 1usize);
+ }
+}