From bf87e17cd67805e3d1e5f422c4e8fa2b0e9a3ae7 Mon Sep 17 00:00:00 2001 From: Mark Simulacrum Date: Fri, 26 May 2017 10:54:56 -0600 Subject: [PATCH] Allow variadic functions with cdecl calling convention. --- src/librustc_typeck/diagnostics.rs | 2 +- src/librustc_typeck/lib.rs | 7 +++---- src/test/compile-fail/E0045.rs | 2 +- src/test/compile-fail/variadic-ffi-2.rs | 6 ++++-- src/test/compile-fail/variadic-ffi.rs | 6 ++++-- 5 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index f9ebe3fff5b..18f33dc22e7 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -4078,7 +4078,7 @@ fn main() { } // E0217, // ambiguous associated type, defined in multiple supertraits // E0218, // no associated type defined // E0219, // associated type defined in higher-ranked supertrait -// E0222, // Error code E0045 (variadic function must have C calling +// E0222, // Error code E0045 (variadic function must have C or cdecl calling // convention) duplicate E0224, // at least one non-builtin train is required for an object type E0227, // ambiguous lifetime bound, explicit lifetime bound required diff --git a/src/librustc_typeck/lib.rs b/src/librustc_typeck/lib.rs index 6f2c73b8925..699b5f330d4 100644 --- a/src/librustc_typeck/lib.rs +++ b/src/librustc_typeck/lib.rs @@ -141,11 +141,10 @@ fn require_c_abi_if_variadic(tcx: TyCtxt, decl: &hir::FnDecl, abi: Abi, span: Span) { - if decl.variadic && abi != Abi::C { + if decl.variadic && !(abi == Abi::C || abi == Abi::Cdecl) { let mut err = struct_span_err!(tcx.sess, span, E0045, - "variadic function must have C calling convention"); - err.span_label(span, "variadics require C calling conventions") - .emit(); + "variadic function must have C or cdecl calling convention"); + err.span_label(span, "variadics require C or cdecl calling convention").emit(); } } diff --git a/src/test/compile-fail/E0045.rs b/src/test/compile-fail/E0045.rs index a3fea8e0db2..3f098861eb6 100644 --- a/src/test/compile-fail/E0045.rs +++ b/src/test/compile-fail/E0045.rs @@ -9,7 +9,7 @@ // except according to those terms. extern "Rust" { fn foo(x: u8, ...); } //~ ERROR E0045 - //~| NOTE variadics require C calling conventions + //~| NOTE variadics require C or cdecl calling convention fn main() { } diff --git a/src/test/compile-fail/variadic-ffi-2.rs b/src/test/compile-fail/variadic-ffi-2.rs index afcad9d8f96..ec5669f6392 100644 --- a/src/test/compile-fail/variadic-ffi-2.rs +++ b/src/test/compile-fail/variadic-ffi-2.rs @@ -8,8 +8,10 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn baz(f: extern "cdecl" fn(usize, ...)) { - //~^ ERROR: variadic function must have C calling convention +// ignore-arm stdcall isn't suppported + +fn baz(f: extern "stdcall" fn(usize, ...)) { + //~^ ERROR: variadic function must have C or cdecl calling convention f(22, 44); } diff --git a/src/test/compile-fail/variadic-ffi.rs b/src/test/compile-fail/variadic-ffi.rs index af2b552e20f..125177efc53 100644 --- a/src/test/compile-fail/variadic-ffi.rs +++ b/src/test/compile-fail/variadic-ffi.rs @@ -8,8 +8,10 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -extern "cdecl" { - fn printf(_: *const u8, ...); //~ ERROR: variadic function must have C calling convention +// ignore-arm stdcall isn't suppported + +extern "stdcall" { + fn printf(_: *const u8, ...); //~ ERROR: variadic function must have C or cdecl calling } extern { -- 2.44.0