From 82b2863a204e727a37a2d23efd738387d2fbab70 Mon Sep 17 00:00:00 2001 From: Alan Egerton Date: Sun, 4 Apr 2021 22:42:19 +0100 Subject: [PATCH] Render destructured struct function param names as underscore. Fixes #83852 r? `@GuillaumeGomez` --- src/librustdoc/clean/utils.rs | 12 +----------- src/test/rustdoc/issue-83852.rs | 10 ++++++++++ 2 files changed, 11 insertions(+), 11 deletions(-) create mode 100644 src/test/rustdoc/issue-83852.rs diff --git a/src/librustdoc/clean/utils.rs b/src/librustdoc/clean/utils.rs index 60cbe9f376f0..9c0ed1480fef 100644 --- a/src/librustdoc/clean/utils.rs +++ b/src/librustdoc/clean/utils.rs @@ -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::>() - .join(", "), - if etc { ", .." } else { "" } - ), PatKind::Or(ref pats) => pats .iter() .map(|p| name_from_pat(&**p).to_string()) diff --git a/src/test/rustdoc/issue-83852.rs b/src/test/rustdoc/issue-83852.rs new file mode 100644 index 000000000000..3c0369e3d341 --- /dev/null +++ b/src/test/rustdoc/issue-83852.rs @@ -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) { + // ... +}