Skip to content

Commit e178ebf

Browse files
committed
auto merge of #15613 : cmr/rust/rustdoc-arg-patterns, r=alexcrichton
2 parents f2d251d + 3c75b1e commit e178ebf

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/librustdoc/clean/mod.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1951,9 +1951,16 @@ fn name_from_pat(p: &ast::Pat) -> String {
19511951
PatWildMulti => "..".to_string(),
19521952
PatIdent(_, ref p, _) => token::get_ident(p.node).get().to_string(),
19531953
PatEnum(ref p, _) => path_to_string(p),
1954-
PatStruct(..) => fail!("tried to get argument name from pat_struct, \
1955-
which is not allowed in function arguments"),
1956-
PatTup(..) => "(tuple arg NYI)".to_string(),
1954+
PatStruct(ref name, ref fields, etc) => {
1955+
format!("{} {{ {}{} }}", path_to_string(name),
1956+
fields.iter().map(|fp|
1957+
format!("{}: {}", fp.ident.as_str(), name_from_pat(&*fp.pat)))
1958+
.collect::<Vec<String>>().connect(", "),
1959+
if etc { ", ..." } else { "" }
1960+
)
1961+
},
1962+
PatTup(ref elts) => format!("({})", elts.iter().map(|p| name_from_pat(&**p))
1963+
.collect::<Vec<String>>().connect(", ")),
19571964
PatBox(p) => name_from_pat(&*p),
19581965
PatRegion(p) => name_from_pat(&*p),
19591966
PatLit(..) => {

src/test/run-make/rustdoc-smoke/foo.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,8 @@ pub mod bar {
2222

2323
/// *wow*
2424
pub trait Doge { }
25+
26+
pub struct Foo { x: int, y: uint }
27+
28+
pub fn prawns((a, b): (int, uint), Foo { x, y }: Foo) { }
2529
}

0 commit comments

Comments
 (0)