Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Render destructured struct function param names as underscore #83863

Merged
merged 3 commits into from
Apr 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 1 addition & 11 deletions src/librustdoc/clean/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,19 +251,9 @@ crate fn name_from_pat(p: &hir::Pat<'_>) -> Symbol {
debug!("trying to get a name from pattern: {:?}", p);

Symbol::intern(&match p.kind {
PatKind::Wild => return kw::Underscore,
PatKind::Wild | PatKind::Struct(..) => return kw::Underscore,
PatKind::Binding(_, _, ident, _) => return ident.name,
PatKind::TupleStruct(ref p, ..) | PatKind::Path(ref p) => qpath_to_string(p),
PatKind::Struct(ref name, ref fields, etc) => format!(
"{} {{ {}{} }}",
qpath_to_string(name),
fields
.iter()
.map(|fp| format!("{}: {}", fp.ident, name_from_pat(&fp.pat)))
.collect::<Vec<String>>()
.join(", "),
if etc { ", .." } else { "" }
),
PatKind::Or(ref pats) => pats
.iter()
.map(|p| name_from_pat(&**p).to_string())
Expand Down
10 changes: 10 additions & 0 deletions src/test/rustdoc/struct-arg-pattern.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#![crate_name = "foo"]

struct BodyId {
hir_id: usize,
}

// @has 'foo/fn.body_owner.html' '//*[@class="rust fn"]' 'pub fn body_owner(_: BodyId)'
pub fn body_owner(BodyId { hir_id }: BodyId) {
// ...
}