@@ -101,7 +101,6 @@ use rustc_span::symbol::{kw, sym, Symbol};
101101use rustc_span:: DUMMY_SP ;
102102use rustc_span:: { BytePos , Span } ;
103103
104- use std:: collections:: VecDeque ;
105104use std:: io;
106105use std:: io:: prelude:: * ;
107106use 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