Skip to content

Commit dfb1f5e

Browse files
committed
Auto merge of #119395 - Nilstrieb:walk-pat, r=est31
Use `Pat::walk_always` instead of manual walk It's also a bit faster, but I doubt that it will have a noticeable perf impact. Mostly doing it because it's shorter and nicer.
2 parents 6362304 + 8fe4d0d commit dfb1f5e

File tree

1 file changed

+6
-29
lines changed

1 file changed

+6
-29
lines changed

compiler/rustc_passes/src/liveness.rs

+6-29
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ use rustc_span::symbol::{kw, sym, Symbol};
101101
use rustc_span::DUMMY_SP;
102102
use rustc_span::{BytePos, Span};
103103

104-
use std::collections::VecDeque;
105104
use std::io;
106105
use std::io::prelude::*;
107106
use std::rc::Rc;
@@ -317,35 +316,13 @@ impl<'tcx> IrMaps<'tcx> {
317316
// For struct patterns, take note of which fields used shorthand
318317
// (`x` rather than `x: x`).
319318
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-
_ => {}
319+
320+
pat.walk_always(|pat| {
321+
if let hir::PatKind::Struct(_, fields, _) = pat.kind {
322+
let short = fields.iter().filter(|f| f.is_shorthand);
323+
shorthand_field_ids.extend(short.map(|f| f.pat.hir_id));
347324
}
348-
}
325+
});
349326

350327
shorthand_field_ids
351328
}

0 commit comments

Comments
 (0)