]> git.lizzy.rs Git - rust.git/commitdiff
Fix C-variadic function printing
authorDan Robertson <dan@dlrobertson.com>
Sat, 2 Mar 2019 03:14:29 +0000 (03:14 +0000)
committerDan Robertson <dan@dlrobertson.com>
Sat, 2 Mar 2019 15:03:09 +0000 (15:03 +0000)
There is no longer a need to append the string `", ..."` to a functions
args as `...` is parsed as an argument and will appear in the functions
arguments.

src/libsyntax/print/pprust.rs
src/test/pretty/fn-variadic.rs [new file with mode: 0644]

index 942bd96939173bf20f4e100f6cb6833617d75b20..49e3fad4af0ffdc76671655f3379319ec69a1551 100644 (file)
@@ -2814,9 +2814,6 @@ pub fn print_fn_args_and_ret(&mut self, decl: &ast::FnDecl)
         -> io::Result<()> {
         self.popen()?;
         self.commasep(Inconsistent, &decl.inputs, |s, arg| s.print_arg(arg, false))?;
-        if decl.c_variadic {
-            self.s.word(", ...")?;
-        }
         self.pclose()?;
 
         self.print_fn_output(decl)
diff --git a/src/test/pretty/fn-variadic.rs b/src/test/pretty/fn-variadic.rs
new file mode 100644 (file)
index 0000000..d3b193a
--- /dev/null
@@ -0,0 +1,15 @@
+// Check that `fn foo(x: i32, ...)` does not print as `fn foo(x: i32, ..., ...)`.
+// See issue #58853.
+//
+// pp-exact
+#![feature(c_variadic)]
+
+extern "C" {
+    pub fn foo(x: i32, ...);
+}
+
+pub unsafe extern "C" fn bar(_: i32, mut ap: ...) -> usize {
+    ap.arg::<usize>()
+}
+
+fn main() { }