Skip to content

Commit

Permalink
rustdoc: support tuple and struct patterns in function arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
emberian committed Jul 11, 2014
1 parent aeab250 commit 3c75b1e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/librustdoc/clean/mod.rs
Expand Up @@ -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(..) => {
Expand Down
4 changes: 4 additions & 0 deletions src/test/run-make/rustdoc-smoke/foo.rs
Expand Up @@ -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) { }
}

5 comments on commit 3c75b1e

@bors
Copy link
Contributor

@bors bors commented on 3c75b1e Jul 12, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on 3c75b1e Jul 12, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging cmr/rust/rustdoc-arg-patterns = 3c75b1e into auto

@bors
Copy link
Contributor

@bors bors commented on 3c75b1e Jul 12, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cmr/rust/rustdoc-arg-patterns = 3c75b1e merged ok, testing candidate = e178ebf

@bors
Copy link
Contributor

@bors bors commented on 3c75b1e Jul 12, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = e178ebf

Please sign in to comment.