Skip to content

Commit bd1e683

Browse files
committed
Avoid some clones.
`Builder::expr_into_pattern` has a single call site. Currently the `pattern` argument at the call site is always cloned. This commit changes things so that we instead do a clone within `expr_into_pattern`, but only if the pattern has the `PatKind::AscribeUserType` kind, and we only clone the annotation within the pattern instead of the entire pattern.
1 parent 053874e commit bd1e683

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

compiler/rustc_mir_build/src/build/block.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
160160
ArmHasGuard(false),
161161
Some((None, initializer_span)),
162162
);
163-
this.expr_into_pattern(block, (**pattern).clone(), init) // irrefutable pattern
163+
this.expr_into_pattern(block, pattern, init) // irrefutable pattern
164164
}
165165
})
166166
},

compiler/rustc_mir_build/src/build/matches/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
490490
pub(super) fn expr_into_pattern(
491491
&mut self,
492492
mut block: BasicBlock,
493-
irrefutable_pat: Pat<'tcx>,
493+
irrefutable_pat: &Pat<'tcx>,
494494
initializer: &Expr<'tcx>,
495495
) -> BlockAnd<()> {
496496
match irrefutable_pat.kind {
@@ -525,7 +525,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
525525
},
526526
..
527527
},
528-
ascription: thir::Ascription { annotation, variance: _ },
528+
ascription: thir::Ascription { ref annotation, variance: _ },
529529
} => {
530530
let place =
531531
self.storage_live_binding(block, var, irrefutable_pat.span, OutsideGuard, true);
@@ -538,7 +538,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
538538

539539
let ty_source_info = self.source_info(annotation.span);
540540

541-
let base = self.canonical_user_type_annotations.push(annotation);
541+
let base = self.canonical_user_type_annotations.push(annotation.clone());
542542
self.cfg.push(
543543
block,
544544
Statement {
@@ -578,7 +578,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
578578
pub(crate) fn place_into_pattern(
579579
&mut self,
580580
block: BasicBlock,
581-
irrefutable_pat: Pat<'tcx>,
581+
irrefutable_pat: &Pat<'tcx>,
582582
initializer: PlaceBuilder<'tcx>,
583583
set_match_place: bool,
584584
) -> BlockAnd<()> {

compiler/rustc_mir_build/src/build/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1052,7 +1052,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
10521052
Some((Some(&place), span)),
10531053
);
10541054
let place_builder = PlaceBuilder::from(local);
1055-
unpack!(block = self.place_into_pattern(block, *pattern, place_builder, false));
1055+
unpack!(
1056+
block =
1057+
self.place_into_pattern(block, pattern.as_ref(), place_builder, false)
1058+
);
10561059
}
10571060
}
10581061
self.source_scope = original_source_scope;

0 commit comments

Comments
 (0)