From 8fe4d0d1568e6f8c410c7fe399b2c35ae037f7a6 Mon Sep 17 00:00:00 2001 From: Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> Date: Thu, 28 Dec 2023 22:18:18 +0100 Subject: [PATCH] Use `Pat::walk_always` instead of manual walk --- compiler/rustc_passes/src/liveness.rs | 35 +++++---------------------- 1 file changed, 6 insertions(+), 29 deletions(-) diff --git a/compiler/rustc_passes/src/liveness.rs b/compiler/rustc_passes/src/liveness.rs index 6be01e0d88fca..e8b6218a10735 100644 --- a/compiler/rustc_passes/src/liveness.rs +++ b/compiler/rustc_passes/src/liveness.rs @@ -101,7 +101,6 @@ use rustc_span::symbol::{kw, sym, Symbol}; use rustc_span::DUMMY_SP; use rustc_span::{BytePos, Span}; -use std::collections::VecDeque; use std::io; use std::io::prelude::*; use std::rc::Rc; @@ -317,35 +316,13 @@ impl<'tcx> IrMaps<'tcx> { // For struct patterns, take note of which fields used shorthand // (`x` rather than `x: x`). let mut shorthand_field_ids = HirIdSet::default(); - let mut pats = VecDeque::new(); - pats.push_back(pat); - - while let Some(pat) = pats.pop_front() { - use rustc_hir::PatKind::*; - match &pat.kind { - Binding(.., inner_pat) => { - pats.extend(inner_pat.iter()); - } - Struct(_, fields, _) => { - let (short, not_short): (Vec>, _) = - fields.iter().partition(|f| f.is_shorthand); - shorthand_field_ids.extend(short.iter().map(|f| f.pat.hir_id)); - pats.extend(not_short.iter().map(|f| f.pat)); - } - Ref(inner_pat, _) | Box(inner_pat) => { - pats.push_back(inner_pat); - } - TupleStruct(_, inner_pats, _) | Tuple(inner_pats, _) | Or(inner_pats) => { - pats.extend(inner_pats.iter()); - } - Slice(pre_pats, inner_pat, post_pats) => { - pats.extend(pre_pats.iter()); - pats.extend(inner_pat.iter()); - pats.extend(post_pats.iter()); - } - _ => {} + + pat.walk_always(|pat| { + if let hir::PatKind::Struct(_, fields, _) = pat.kind { + let short = fields.iter().filter(|f| f.is_shorthand); + shorthand_field_ids.extend(short.map(|f| f.pat.hir_id)); } - } + }); shorthand_field_ids }