diff options
| author | Folkert de Vries <folkert@folkertdev.nl> | 2025-09-10 00:17:22 +0200 |
|---|---|---|
| committer | Folkert de Vries <folkert@folkertdev.nl> | 2025-09-11 10:18:48 +0200 |
| commit | fd48528d185f59f60e301bce1e01d670ff4bdb30 (patch) | |
| tree | 2fb3335987f19721fba3b61299552f4ddc477c70 /tests/ui/c-variadic/trait-method.rs | |
| parent | f4665ab8368ad2e8a86d4390ae35c28bdd9561bb (diff) | |
| download | rust-fd48528d185f59f60e301bce1e01d670ff4bdb30.tar.gz rust-fd48528d185f59f60e301bce1e01d670ff4bdb30.zip | |
c-variadic: allow inherent methods to be c-variadic
Diffstat (limited to 'tests/ui/c-variadic/trait-method.rs')
| -rw-r--r-- | tests/ui/c-variadic/trait-method.rs | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/ui/c-variadic/trait-method.rs b/tests/ui/c-variadic/trait-method.rs new file mode 100644 index 00000000000..4c468c1907b --- /dev/null +++ b/tests/ui/c-variadic/trait-method.rs @@ -0,0 +1,40 @@ +// For now C-variadic arguments in trait methods are rejected, though we aim to lift this +// restriction in the future. In particular we need to think about the interaction with +// `dyn Trait` and the `ReifyShim`s that it may generate for methods. +#![feature(c_variadic)] +#![crate_type = "lib"] +struct S; + +impl S { + unsafe extern "C" fn associated_function(mut ap: ...) -> i32 { + unsafe { ap.arg() } + } + + unsafe extern "C" fn method(&self, mut ap: ...) -> i32 { + unsafe { ap.arg() } + } +} + +trait T { + unsafe extern "C" fn trait_associated_function(mut ap: ...) -> i32 { + //~^ ERROR: associated functions cannot have a C variable argument list + unsafe { ap.arg() } + } + + unsafe extern "C" fn trait_method(&self, mut ap: ...) -> i32 { + //~^ ERROR: associated functions cannot have a C variable argument list + unsafe { ap.arg() } + } +} + +impl T for S {} + +fn main() { + unsafe { + assert_eq!(S::associated_function(32), 32); + assert_eq!(S.method(32), 32); + + assert_eq!(S::trait_associated_function(32), 32); + assert_eq!(S.trait_method(32), 32); + } +} |
