Avoid matching on PatKind::Wild
in write_struct_like
This commit is contained in:
parent
c9bd03cb72
commit
0a777090d8
@ -847,7 +847,11 @@ fn hoist_witness_pat(&self, pat: &WitnessPat<'p, 'tcx>) -> print::Pat<'tcx> {
|
|||||||
let subpatterns = pat
|
let subpatterns = pat
|
||||||
.iter_fields()
|
.iter_fields()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.map(|(i, pat)| FieldPat { field: FieldIdx::new(i), pattern: hoist(pat) })
|
.map(|(i, pat)| FieldPat {
|
||||||
|
field: FieldIdx::new(i),
|
||||||
|
pattern: hoist(pat),
|
||||||
|
is_wildcard: would_print_as_wildcard(cx.tcx, pat),
|
||||||
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
PatKind::StructLike { enum_info, subpatterns }
|
PatKind::StructLike { enum_info, subpatterns }
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
pub(crate) struct FieldPat<'tcx> {
|
pub(crate) struct FieldPat<'tcx> {
|
||||||
pub(crate) field: FieldIdx,
|
pub(crate) field: FieldIdx,
|
||||||
pub(crate) pattern: Box<Pat<'tcx>>,
|
pub(crate) pattern: Box<Pat<'tcx>>,
|
||||||
|
pub(crate) is_wildcard: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
@ -139,12 +140,12 @@ fn write_struct_like<'tcx>(
|
|||||||
write!(f, " {{ ")?;
|
write!(f, " {{ ")?;
|
||||||
|
|
||||||
let mut printed = 0;
|
let mut printed = 0;
|
||||||
for p in subpatterns {
|
for &FieldPat { field, ref pattern, is_wildcard } in subpatterns {
|
||||||
if let PatKind::Wild = p.pattern.kind {
|
if is_wildcard {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let name = variant.fields[p.field].name;
|
let field_name = variant.fields[field].name;
|
||||||
write!(f, "{}{}: {}", start_or_comma(), name, p.pattern)?;
|
write!(f, "{}{field_name}: {pattern}", start_or_comma())?;
|
||||||
printed += 1;
|
printed += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user