Rollup merge of #83863 - eggyal:issue-83852, r=jyn514

Render destructured struct function param names as underscore

Fixes #83852

r? ````@GuillaumeGomez````
This commit is contained in:
Dylan DPC 2021-04-05 13:03:43 +02:00 committed by GitHub
commit 98e7a4e784
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 11 deletions

View file

@ -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())

View file

@ -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) {
// ...
}