diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
commit | 698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch) | |
tree | 173a775858bd501c378080a10dca74132f05bc50 /src/test/ui/c-variadic | |
parent | Initial commit. (diff) | |
download | rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip |
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/ui/c-variadic')
-rw-r--r-- | src/test/ui/c-variadic/issue-32201.rs | 13 | ||||
-rw-r--r-- | src/test/ui/c-variadic/issue-32201.stderr | 9 | ||||
-rw-r--r-- | src/test/ui/c-variadic/issue-86053-1.rs | 12 | ||||
-rw-r--r-- | src/test/ui/c-variadic/issue-86053-1.stderr | 101 | ||||
-rw-r--r-- | src/test/ui/c-variadic/issue-86053-2.rs | 11 | ||||
-rw-r--r-- | src/test/ui/c-variadic/issue-86053-2.stderr | 16 | ||||
-rw-r--r-- | src/test/ui/c-variadic/variadic-ffi-1.rs | 33 | ||||
-rw-r--r-- | src/test/ui/c-variadic/variadic-ffi-1.stderr | 100 | ||||
-rw-r--r-- | src/test/ui/c-variadic/variadic-ffi-2.rs | 8 | ||||
-rw-r--r-- | src/test/ui/c-variadic/variadic-ffi-2.stderr | 9 | ||||
-rw-r--r-- | src/test/ui/c-variadic/variadic-ffi-4.rs | 38 | ||||
-rw-r--r-- | src/test/ui/c-variadic/variadic-ffi-4.stderr | 150 | ||||
-rw-r--r-- | src/test/ui/c-variadic/variadic-ffi-6.rs | 13 | ||||
-rw-r--r-- | src/test/ui/c-variadic/variadic-ffi-6.stderr | 15 | ||||
-rw-r--r-- | src/test/ui/c-variadic/variadic-ffi-no-fixed-args.rs | 6 | ||||
-rw-r--r-- | src/test/ui/c-variadic/variadic-ffi-no-fixed-args.stderr | 8 | ||||
-rw-r--r-- | src/test/ui/c-variadic/variadic-unreachable-arg-error.rs | 14 |
17 files changed, 556 insertions, 0 deletions
diff --git a/src/test/ui/c-variadic/issue-32201.rs b/src/test/ui/c-variadic/issue-32201.rs new file mode 100644 index 000000000..f27bb1c2e --- /dev/null +++ b/src/test/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/src/test/ui/c-variadic/issue-32201.stderr b/src/test/ui/c-variadic/issue-32201.stderr new file mode 100644 index 000000000..cedb58784 --- /dev/null +++ b/src/test/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/src/test/ui/c-variadic/issue-86053-1.rs b/src/test/ui/c-variadic/issue-86053-1.rs new file mode 100644 index 000000000..b30548e19 --- /dev/null +++ b/src/test/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 +// error-pattern:in type `&'a &'b usize`, reference has a longer lifetime than the data it references + +#![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/src/test/ui/c-variadic/issue-86053-1.stderr b/src/test/ui/c-variadic/issue-86053-1.stderr new file mode 100644 index 000000000..5d119bb85 --- /dev/null +++ b/src/test/ui/c-variadic/issue-86053-1.stderr @@ -0,0 +1,101 @@ +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 + | +LL | pub trait Fn<Args>: FnMut<Args> { + | ------------------------------- 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[E0491]: in type `&'a &'b usize`, reference has a longer lifetime than the data it references + --> $DIR/issue-86053-1.rs:11:52 + | +LL | self , ... , self , self , ... ) where F : FnOnce ( & 'a & 'b usize ) { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: the pointer is valid for the lifetime `'a` as defined here + --> $DIR/issue-86053-1.rs:10:16 + | +LL | fn ordering4 < 'a , 'b > ( a : , self , self , self , + | ^^ +note: but the referenced data is only valid for the lifetime `'b` as defined here + --> $DIR/issue-86053-1.rs:10:21 + | +LL | fn ordering4 < 'a , 'b > ( a : , self , self , self , + | ^^ + +error: aborting due to 12 previous errors + +Some errors have detailed explanations: E0412, E0491. +For more information about an error, try `rustc --explain E0412`. diff --git a/src/test/ui/c-variadic/issue-86053-2.rs b/src/test/ui/c-variadic/issue-86053-2.rs new file mode 100644 index 000000000..c545831f7 --- /dev/null +++ b/src/test/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/src/test/ui/c-variadic/issue-86053-2.stderr b/src/test/ui/c-variadic/issue-86053-2.stderr new file mode 100644 index 000000000..815b06e77 --- /dev/null +++ b/src/test/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/src/test/ui/c-variadic/variadic-ffi-1.rs b/src/test/ui/c-variadic/variadic-ffi-1.rs new file mode 100644 index 000000000..a76efd9a2 --- /dev/null +++ b/src/test/ui/c-variadic/variadic-ffi-1.rs @@ -0,0 +1,33 @@ +// 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: variadic function must have C or cdecl calling +} + +extern "C" { + fn foo(f: isize, x: u8, ...); +} + +extern "C" fn bar(f: isize, x: u8) {} + +fn main() { + unsafe { + foo(); //~ ERROR this function takes at least 2 arguments but 0 arguments were supplied + foo(1); //~ ERROR this 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/src/test/ui/c-variadic/variadic-ffi-1.stderr b/src/test/ui/c-variadic/variadic-ffi-1.stderr new file mode 100644 index 000000000..176bec819 --- /dev/null +++ b/src/test/ui/c-variadic/variadic-ffi-1.stderr @@ -0,0 +1,100 @@ +error[E0045]: C-variadic function must have C or cdecl calling convention + --> $DIR/variadic-ffi-1.rs:9:5 + | +LL | fn printf(_: *const u8, ...); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ C-variadics require C or cdecl calling convention + +error[E0060]: this function takes at least 2 arguments but 0 arguments were supplied + --> $DIR/variadic-ffi-1.rs:20:9 + | +LL | foo(); + | ^^^-- two arguments of type `isize` and `u8` are missing + | +note: function defined here + --> $DIR/variadic-ffi-1.rs:13: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:21:9 + | +LL | foo(1); + | ^^^--- an argument of type `u8` is missing + | +note: function defined here + --> $DIR/variadic-ffi-1.rs:13: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:23: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:24: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:26: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:27: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:28: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:29: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:30: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:31: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/src/test/ui/c-variadic/variadic-ffi-2.rs b/src/test/ui/c-variadic/variadic-ffi-2.rs new file mode 100644 index 000000000..224ac16f4 --- /dev/null +++ b/src/test/ui/c-variadic/variadic-ffi-2.rs @@ -0,0 +1,8 @@ +// ignore-arm stdcall isn't supported + +fn baz(f: extern "stdcall" fn(usize, ...)) { + //~^ ERROR: variadic function must have C or cdecl calling convention + f(22, 44); +} + +fn main() {} diff --git a/src/test/ui/c-variadic/variadic-ffi-2.stderr b/src/test/ui/c-variadic/variadic-ffi-2.stderr new file mode 100644 index 000000000..4c8b8d2b2 --- /dev/null +++ b/src/test/ui/c-variadic/variadic-ffi-2.stderr @@ -0,0 +1,9 @@ +error[E0045]: C-variadic function must have C or cdecl calling convention + --> $DIR/variadic-ffi-2.rs:3:11 + | +LL | fn baz(f: extern "stdcall" fn(usize, ...)) { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ C-variadics require C or cdecl calling convention + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0045`. diff --git a/src/test/ui/c-variadic/variadic-ffi-4.rs b/src/test/ui/c-variadic/variadic-ffi-4.rs new file mode 100644 index 000000000..806403794 --- /dev/null +++ b/src/test/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/src/test/ui/c-variadic/variadic-ffi-4.stderr b/src/test/ui/c-variadic/variadic-ffi-4.stderr new file mode 100644 index 000000000..6f8e53298 --- /dev/null +++ b/src/test/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/src/test/ui/c-variadic/variadic-ffi-6.rs b/src/test/ui/c-variadic/variadic-ffi-6.rs new file mode 100644 index 000000000..4dd8a2d45 --- /dev/null +++ b/src/test/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/src/test/ui/c-variadic/variadic-ffi-6.stderr b/src/test/ui/c-variadic/variadic-ffi-6.stderr new file mode 100644 index 000000000..4c7792d96 --- /dev/null +++ b/src/test/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/src/test/ui/c-variadic/variadic-ffi-no-fixed-args.rs b/src/test/ui/c-variadic/variadic-ffi-no-fixed-args.rs new file mode 100644 index 000000000..588c15a18 --- /dev/null +++ b/src/test/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/src/test/ui/c-variadic/variadic-ffi-no-fixed-args.stderr b/src/test/ui/c-variadic/variadic-ffi-no-fixed-args.stderr new file mode 100644 index 000000000..e11ba43ca --- /dev/null +++ b/src/test/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/src/test/ui/c-variadic/variadic-unreachable-arg-error.rs b/src/test/ui/c-variadic/variadic-unreachable-arg-error.rs new file mode 100644 index 000000000..f60f6f3e8 --- /dev/null +++ b/src/test/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); + } +} |