Auto merge of #138653 - matthiaskrgr:rollup-fwwqmr7, r=matthiaskrgr · rust-lang/rust@c4b38a5 (original) (raw)
`@@ -240,36 +240,45 @@ pub fn walk_pat<'thir, 'tcx: 'thir, V: Visitor<'thir, 'tcx>>(
`
240
240
`visitor: &mut V,
`
241
241
`pat: &'thir Pat<'tcx>,
`
242
242
`) {
`
243
``
`-
use PatKind::*;
`
``
243
`+
for_each_immediate_subpat(pat, |p| visitor.visit_pat(p));
`
``
244
`+
}
`
``
245
+
``
246
`` +
/// Invokes callback
on each immediate subpattern of pat
, if any.
``
``
247
`+
/// A building block for assembling THIR pattern visitors.
`
``
248
`+
pub(crate) fn for_each_immediate_subpat<'a, 'tcx>(
`
``
249
`+
pat: &'a Pat<'tcx>,
`
``
250
`+
mut callback: impl FnMut(&'a Pat<'tcx>),
`
``
251
`+
) {
`
244
252
`match &pat.kind {
`
245
``
`-
AscribeUserType { subpattern, ascription: _ }
`
246
``
`-
| Deref { subpattern }
`
247
``
`-
| DerefPattern { subpattern, .. }
`
248
``
`-
| Binding { subpattern: Some(subpattern), .. } => visitor.visit_pat(subpattern),
`
249
``
`-
Binding { .. } | Wild | Never | Error(_) => {}
`
250
``
`-
Variant { subpatterns, adt_def: _, args: _, variant_index: _ } | Leaf { subpatterns } => {
`
251
``
`-
for subpattern in subpatterns {
`
252
``
`-
visitor.visit_pat(&subpattern.pattern);
`
``
253
`+
PatKind::Wild
`
``
254
`+
| PatKind::Binding { subpattern: None, .. }
`
``
255
`+
| PatKind::Constant { value: _ }
`
``
256
`+
| PatKind::Range(_)
`
``
257
`+
| PatKind::Never
`
``
258
`+
| PatKind::Error(_) => {}
`
``
259
+
``
260
`+
PatKind::AscribeUserType { subpattern, .. }
`
``
261
`+
| PatKind::Binding { subpattern: Some(subpattern), .. }
`
``
262
`+
| PatKind::Deref { subpattern }
`
``
263
`+
| PatKind::DerefPattern { subpattern, .. }
`
``
264
`+
| PatKind::ExpandedConstant { subpattern, .. } => callback(subpattern),
`
``
265
+
``
266
`+
PatKind::Variant { subpatterns, .. } | PatKind::Leaf { subpatterns } => {
`
``
267
`+
for field_pat in subpatterns {
`
``
268
`+
callback(&field_pat.pattern);
`
253
269
`}
`
254
270
`}
`
255
``
`-
Constant { value: _ } => {}
`
256
``
`-
ExpandedConstant { def_id: _, is_inline: _, subpattern } => visitor.visit_pat(subpattern),
`
257
``
`-
Range(_) => {}
`
258
``
`-
Slice { prefix, slice, suffix } | Array { prefix, slice, suffix } => {
`
259
``
`-
for subpattern in prefix.iter() {
`
260
``
`-
visitor.visit_pat(subpattern);
`
261
``
`-
}
`
262
``
`-
if let Some(pat) = slice {
`
263
``
`-
visitor.visit_pat(pat);
`
264
``
`-
}
`
265
``
`-
for subpattern in suffix.iter() {
`
266
``
`-
visitor.visit_pat(subpattern);
`
``
271
+
``
272
`+
PatKind::Slice { prefix, slice, suffix } | PatKind::Array { prefix, slice, suffix } => {
`
``
273
`+
for pat in prefix.iter().chain(slice.as_deref()).chain(suffix) {
`
``
274
`+
callback(pat);
`
267
275
`}
`
268
276
`}
`
269
``
`-
Or { pats } => {
`
270
``
`-
for pat in pats.iter() {
`
271
``
`-
visitor.visit_pat(pat);
`
``
277
+
``
278
`+
PatKind::Or { pats } => {
`
``
279
`+
for pat in pats {
`
``
280
`+
callback(pat);
`
272
281
`}
`
273
282
`}
`
274
``
`-
};
`
``
283
`+
}
`
275
284
`}
`