Move recursion out of MatchPairTree::for_pattern helpers #154943
Move recursion out of MatchPairTree::for_pattern helpers #154943Zalathar wants to merge 2 commits intorust-lang:mainfrom
MatchPairTree::for_pattern helpers #154943Conversation
The helper functions now just iterate over the relevant subpatterns, while leaving recursion up to the main function. This avoids passing parameters that were only used for recursive plumbing, and consolidates all recursive calls into `for_pattern` itself, which should make it easier to experiment with changes to the recursive structure. There should be no change to compiler behaviour.
`PatKind::Variant` is always used for enum variants, even for enums that only have one variant.
|
Some changes occurred in match lowering cc @Nadrieril |
|
r? @nnethercote rustbot has assigned @nnethercote. Use Why was this reviewer chosen?The reviewer was selected based on:
|
| fn for_each_field_subpat<'tcx>( | ||
| place: &PlaceBuilder<'tcx>, | ||
| subpatterns: &[FieldPat<'tcx>], | ||
| mut callback_fn: impl FnMut(PlaceBuilder<'tcx>, &Pat<'tcx>), |
There was a problem hiding this comment.
Does this need to be a closure? For every occurrence the callback just calls for_pattern. Seems more general than necessary.
| prefix: &[Pat<'tcx>], | ||
| opt_middle: &Option<Box<Pat<'tcx>>>, | ||
| suffix: &[Pat<'tcx>], | ||
| mut callback_fn: impl FnMut(PlaceBuilder<'tcx>, &Pat<'tcx>), |
|
Thinking about this some more, it might be worth just fully inlining both helpers. The field-subpat helper is trivial, and much of the complexity in the array/slice helper comes from generalising over array and slice patterns, which have significantly different indexing needs. |
You can try and see but I think keeping them together is clearer. I'm thinking, how about returning an
True, we could inline that one (Happy to take the r ? on this one, it's code I'm very familiar with) |
|
Ok, thanks! r? @Nadrieril |
|
|
The helper functions now just iterate over the relevant subpatterns, while leaving recursion up to the main function.
This avoids passing parameters that were only used for recursive plumbing, and consolidates all recursive calls into
for_patternitself, which should make it easier to experiment with changes to the recursive structure.There should be no change to compiler behaviour.