From 500fb78a3393a76e7790a38eb4df0b346eda9fe5 Mon Sep 17 00:00:00 2001
From: Marcus Klaas <mail@marcusklaas.nl>
Date: Sun, 19 Jul 2015 14:33:02 +0200
Subject: [PATCH] Format unnamed function arguments

---
 src/items.rs          | 30 +++++++++++++++++++++++++-----
 tests/target/trait.rs |  4 ++++
 2 files changed, 29 insertions(+), 5 deletions(-)

diff --git a/src/items.rs b/src/items.rs
index b3f4a0a63a4..3250a93b997 100644
--- a/src/items.rs
+++ b/src/items.rs
@@ -289,10 +289,10 @@ impl<'a> FmtVisitor<'a> {
 
             arg_items = itemize_list(self.codemap,
                                      arg_items,
-                                     args[min_args-1..].iter(),
+                                     args[min_args-1..].iter().cloned(),
                                      ",",
                                      ")",
-                                     |arg| arg.pat.span.lo,
+                                     span_lo_for_arg,
                                      |arg| arg.ty.span.hi,
                                      |_| String::new(),
                                      comment_span_start,
@@ -780,9 +780,29 @@ impl<'a> FmtVisitor<'a> {
     // TODO we farm this out, but this could spill over the column limit, so we
     // ought to handle it properly.
     fn rewrite_fn_input(&self, arg: &ast::Arg) -> String {
-        format!("{}: {}",
-                pprust::pat_to_string(&arg.pat),
-                pprust::ty_to_string(&arg.ty))
+        if is_named_arg(arg) {
+            format!("{}: {}",
+                    pprust::pat_to_string(&arg.pat),
+                    pprust::ty_to_string(&arg.ty))
+        } else {
+            pprust::ty_to_string(&arg.ty)
+        }
+    }
+}
+
+fn span_lo_for_arg(arg: &ast::Arg) -> BytePos {
+    if is_named_arg(arg) {
+        arg.pat.span.lo
+    } else {
+        arg.ty.span.lo
+    }
+}
+
+fn is_named_arg(arg: &ast::Arg) -> bool {
+    if let ast::Pat_::PatIdent(_, ident, _) = arg.pat.node {
+        ident.node != token::special_idents::invalid
+    } else {
+        true
     }
 }
 
diff --git a/tests/target/trait.rs b/tests/target/trait.rs
index 8f7f4be67c9..b7d711f8b00 100644
--- a/tests/target/trait.rs
+++ b/tests/target/trait.rs
@@ -18,3 +18,7 @@ trait Foo {
     fn read(&mut self, x: BufReader<R> /* Used to be MemReader */)
         where R: Read;
 }
+
+pub trait WriteMessage {
+    fn write_message(&mut self, &FrontendMessage) -> io::Result<()>;
+}