Skip to content

Commit bb08c13

Browse files
committed
Use Pat::walk_always instead of manual walk
1 parent 3ee6710 commit bb08c13

File tree

1 file changed

+7
-28
lines changed

1 file changed

+7
-28
lines changed

compiler/rustc_passes/src/liveness.rs

+7-28
Original file line numberDiff line numberDiff line change
@@ -317,35 +317,14 @@ impl<'tcx> IrMaps<'tcx> {
317317
// For struct patterns, take note of which fields used shorthand
318318
// (`x` rather than `x: x`).
319319
let mut shorthand_field_ids = HirIdSet::default();
320-
let mut pats = VecDeque::new();
321-
pats.push_back(pat);
322-
323-
while let Some(pat) = pats.pop_front() {
324-
use rustc_hir::PatKind::*;
325-
match &pat.kind {
326-
Binding(.., inner_pat) => {
327-
pats.extend(inner_pat.iter());
328-
}
329-
Struct(_, fields, _) => {
330-
let (short, not_short): (Vec<hir::PatField<'_>>, _) =
331-
fields.iter().partition(|f| f.is_shorthand);
332-
shorthand_field_ids.extend(short.iter().map(|f| f.pat.hir_id));
333-
pats.extend(not_short.iter().map(|f| f.pat));
334-
}
335-
Ref(inner_pat, _) | Box(inner_pat) => {
336-
pats.push_back(inner_pat);
337-
}
338-
TupleStruct(_, inner_pats, _) | Tuple(inner_pats, _) | Or(inner_pats) => {
339-
pats.extend(inner_pats.iter());
340-
}
341-
Slice(pre_pats, inner_pat, post_pats) => {
342-
pats.extend(pre_pats.iter());
343-
pats.extend(inner_pat.iter());
344-
pats.extend(post_pats.iter());
345-
}
346-
_ => {}
320+
321+
pat.walk_always(|pat| {
322+
if let hir::PatKind::Struct(_, fields, _) = pat.kind {
323+
let (short, not_short): (Vec<hir::PatField<'_>>, _) =
324+
fields.iter().partition(|f| f.is_shorthand);
325+
shorthand_field_ids.extend(short.iter().map(|f| f.pat.hir_id));
347326
}
348-
}
327+
});
349328

350329
shorthand_field_ids
351330
}

0 commit comments

Comments
 (0)