Skip to content

Commit 3c75b1e

Browse files
committed
rustdoc: support tuple and struct patterns in function arguments
1 parent aeab250 commit 3c75b1e

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
@@ -1948,9 +1948,16 @@ fn name_from_pat(p: &ast::Pat) -> String {
19481948
PatWildMulti => "..".to_string(),
19491949
PatIdent(_, ref p, _) => token::get_ident(p.node).get().to_string(),
19501950
PatEnum(ref p, _) => path_to_string(p),
1951-
PatStruct(..) => fail!("tried to get argument name from pat_struct, \
1952-
which is not allowed in function arguments"),
1953-
PatTup(..) => "(tuple arg NYI)".to_string(),
1951+
PatStruct(ref name, ref fields, etc) => {
1952+
format!("{} {{ {}{} }}", path_to_string(name),
1953+
fields.iter().map(|fp|
1954+
format!("{}: {}", fp.ident.as_str(), name_from_pat(&*fp.pat)))
1955+
.collect::<Vec<String>>().connect(", "),
1956+
if etc { ", ..." } else { "" }
1957+
)
1958+
},
1959+
PatTup(ref elts) => format!("({})", elts.iter().map(|p| name_from_pat(&**p))
1960+
.collect::<Vec<String>>().connect(", ")),
19541961
PatBox(p) => name_from_pat(&*p),
19551962
PatRegion(p) => name_from_pat(&*p),
19561963
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)