From 210c6071b02db76900d55e00bd46ee91285c3a07 Mon Sep 17 00:00:00 2001 From: Dan Robertson Date: Sun, 24 Feb 2019 22:40:11 +0000 Subject: [PATCH] Add c_variadic language feature item --- src/libsyntax/feature_gate.rs | 12 ++++++++++++ src/test/ui/c-variadic/variadic-ffi-6.rs | 1 + src/test/ui/feature-gate/feature-gate-c_variadic.rs | 4 ++++ .../ui/feature-gate/feature-gate-c_variadic.stderr | 11 +++++++++++ 4 files changed, 28 insertions(+) create mode 100644 src/test/ui/feature-gate/feature-gate-c_variadic.rs create mode 100644 src/test/ui/feature-gate/feature-gate-c_variadic.stderr diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index cc1953e69d4..fad370d768e 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -471,6 +471,9 @@ declare_features! ( // #[repr(align(X))] on enums (active, repr_align_enum, "1.34.0", Some(57996), None), + + // Allows the use of C-variadics + (active, c_variadic, "1.34.0", Some(44930), None), ); declare_features! ( @@ -1901,6 +1904,11 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> { if header.asyncness.is_async() { gate_feature_post!(&self, async_await, span, "async fn is unstable"); } + + if fn_decl.c_variadic { + gate_feature_post!(&self, c_variadic, span, + "C-varaidic functions are unstable"); + } // Stability of const fn methods are covered in // `visit_trait_item` and `visit_impl_item` below; this is // because default methods don't pass through this point. @@ -1929,6 +1937,10 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> { if block.is_none() { self.check_abi(sig.header.abi, ti.span); } + if sig.decl.c_variadic { + gate_feature_post!(&self, c_variadic, ti.span, + "C-varaidic functions are unstable"); + } if sig.header.constness.node == ast::Constness::Const { gate_feature_post!(&self, const_fn, ti.span, "const fn is unstable"); } diff --git a/src/test/ui/c-variadic/variadic-ffi-6.rs b/src/test/ui/c-variadic/variadic-ffi-6.rs index 9b5293fad3b..4dd8a2d4521 100644 --- a/src/test/ui/c-variadic/variadic-ffi-6.rs +++ b/src/test/ui/c-variadic/variadic-ffi-6.rs @@ -1,4 +1,5 @@ #![crate_type="lib"] +#![feature(c_variadic)] pub unsafe extern "C" fn use_vararg_lifetime( x: usize, diff --git a/src/test/ui/feature-gate/feature-gate-c_variadic.rs b/src/test/ui/feature-gate/feature-gate-c_variadic.rs new file mode 100644 index 00000000000..5801a2a89e2 --- /dev/null +++ b/src/test/ui/feature-gate/feature-gate-c_variadic.rs @@ -0,0 +1,4 @@ +#![crate_type="lib"] + +pub unsafe extern "C" fn test(_: i32, ap: ...) { } +//~^ C-varaidic functions are unstable diff --git a/src/test/ui/feature-gate/feature-gate-c_variadic.stderr b/src/test/ui/feature-gate/feature-gate-c_variadic.stderr new file mode 100644 index 00000000000..a876e16fdea --- /dev/null +++ b/src/test/ui/feature-gate/feature-gate-c_variadic.stderr @@ -0,0 +1,11 @@ +error[E0658]: C-varaidic functions are unstable (see issue #44930) + --> $DIR/feature-gate-c_variadic.rs:3:1 + | +LL | pub unsafe extern "C" fn test(_: i32, ap: ...) { } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: add #![feature(c_variadic)] to the crate attributes to enable + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0658`.