Skip to content

Commit 35dd87f

Browse files
Allow variadic functions with cdecl calling convention.
1 parent c732446 commit 35dd87f

File tree

5 files changed

+9
-10
lines changed

5 files changed

+9
-10
lines changed

src/librustc_typeck/diagnostics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4078,7 +4078,7 @@ register_diagnostics! {
40784078
// E0217, // ambiguous associated type, defined in multiple supertraits
40794079
// E0218, // no associated type defined
40804080
// E0219, // associated type defined in higher-ranked supertrait
4081-
// E0222, // Error code E0045 (variadic function must have C calling
4081+
// E0222, // Error code E0045 (variadic function must have C or cdecl calling
40824082
// convention) duplicate
40834083
E0224, // at least one non-builtin train is required for an object type
40844084
E0227, // ambiguous lifetime bound, explicit lifetime bound required

src/librustc_typeck/lib.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,10 @@ fn require_c_abi_if_variadic(tcx: TyCtxt,
141141
decl: &hir::FnDecl,
142142
abi: Abi,
143143
span: Span) {
144-
if decl.variadic && abi != Abi::C {
144+
if decl.variadic && !(abi == Abi::C || abi == Abi::Cdecl) {
145145
let mut err = struct_span_err!(tcx.sess, span, E0045,
146-
"variadic function must have C calling convention");
147-
err.span_label(span, "variadics require C calling conventions")
148-
.emit();
146+
"variadic function must have C or cdecl calling convention");
147+
err.span_label(span, "variadics require C or cdecl calling convention").emit();
149148
}
150149
}
151150

src/test/compile-fail/E0045.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

1111
extern "Rust" { fn foo(x: u8, ...); } //~ ERROR E0045
12-
//~| NOTE variadics require C calling conventions
12+
//~| NOTE variadics require C or cdecl calling convention
1313

1414
fn main() {
1515
}

src/test/compile-fail/variadic-ffi-2.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
fn baz(f: extern "cdecl" fn(usize, ...)) {
12-
//~^ ERROR: variadic function must have C calling convention
11+
fn baz(f: extern "stdcall" fn(usize, ...)) {
12+
//~^ ERROR: variadic function must have C or cdecl calling convention
1313
f(22, 44);
1414
}
1515

src/test/compile-fail/variadic-ffi.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
extern "cdecl" {
12-
fn printf(_: *const u8, ...); //~ ERROR: variadic function must have C calling convention
11+
extern "stdcall" {
12+
fn printf(_: *const u8, ...); //~ ERROR: variadic function must have C or cdecl calling
1313
}
1414

1515
extern {

0 commit comments

Comments
 (0)