about summary refs log tree commit diff
diff options
context:
space:
mode:
authorCorey Richardson <corey@octayn.net>2014-07-11 11:59:18 -0700
committerCorey Richardson <corey@octayn.net>2014-07-11 11:59:18 -0700
commit3c75b1e38233bb5aeced0a54dab986369641550a (patch)
tree62f1715ce2c08ed5d2440743494374369342d091
parentaeab2501d1b2dabba567ee3d48270049087ee603 (diff)
downloadrust-3c75b1e38233bb5aeced0a54dab986369641550a.tar.gz
rust-3c75b1e38233bb5aeced0a54dab986369641550a.zip
rustdoc: support tuple and struct patterns in function arguments
-rw-r--r--src/librustdoc/clean/mod.rs13
-rw-r--r--src/test/run-make/rustdoc-smoke/foo.rs4
2 files changed, 14 insertions, 3 deletions
diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs
index af0b6a1cb21..d6cfdb5fcc6 100644
--- a/src/librustdoc/clean/mod.rs
+++ b/src/librustdoc/clean/mod.rs
@@ -1948,9 +1948,16 @@ fn name_from_pat(p: &ast::Pat) -> String {
         PatWildMulti => "..".to_string(),
         PatIdent(_, ref p, _) => token::get_ident(p.node).get().to_string(),
         PatEnum(ref p, _) => path_to_string(p),
-        PatStruct(..) => fail!("tried to get argument name from pat_struct, \
-                                which is not allowed in function arguments"),
-        PatTup(..) => "(tuple arg NYI)".to_string(),
+        PatStruct(ref name, ref fields, etc) => {
+            format!("{} {{ {}{} }}", path_to_string(name),
+                fields.iter().map(|fp|
+                                  format!("{}: {}", fp.ident.as_str(), name_from_pat(&*fp.pat)))
+                             .collect::<Vec<String>>().connect(", "),
+                if etc { ", ..." } else { "" }
+            )
+        },
+        PatTup(ref elts) => format!("({})", elts.iter().map(|p| name_from_pat(&**p))
+                                            .collect::<Vec<String>>().connect(", ")),
         PatBox(p) => name_from_pat(&*p),
         PatRegion(p) => name_from_pat(&*p),
         PatLit(..) => {
diff --git a/src/test/run-make/rustdoc-smoke/foo.rs b/src/test/run-make/rustdoc-smoke/foo.rs
index dda66f051bc..b783dd39a06 100644
--- a/src/test/run-make/rustdoc-smoke/foo.rs
+++ b/src/test/run-make/rustdoc-smoke/foo.rs
@@ -22,4 +22,8 @@ pub mod bar {
 
     /// *wow*
     pub trait Doge { }
+
+    pub struct Foo { x: int, y: uint }
+
+    pub fn prawns((a, b): (int, uint), Foo { x, y }: Foo) { }
 }