mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-02 07:22:42 +00:00
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.
This commit is contained in:
parent
053874eecc
commit
bd1e6836a0
@ -160,7 +160,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||||||
ArmHasGuard(false),
|
ArmHasGuard(false),
|
||||||
Some((None, initializer_span)),
|
Some((None, initializer_span)),
|
||||||
);
|
);
|
||||||
this.expr_into_pattern(block, (**pattern).clone(), init) // irrefutable pattern
|
this.expr_into_pattern(block, pattern, init) // irrefutable pattern
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
@ -490,7 +490,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||||||
pub(super) fn expr_into_pattern(
|
pub(super) fn expr_into_pattern(
|
||||||
&mut self,
|
&mut self,
|
||||||
mut block: BasicBlock,
|
mut block: BasicBlock,
|
||||||
irrefutable_pat: Pat<'tcx>,
|
irrefutable_pat: &Pat<'tcx>,
|
||||||
initializer: &Expr<'tcx>,
|
initializer: &Expr<'tcx>,
|
||||||
) -> BlockAnd<()> {
|
) -> BlockAnd<()> {
|
||||||
match irrefutable_pat.kind {
|
match irrefutable_pat.kind {
|
||||||
@ -525,7 +525,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||||||
},
|
},
|
||||||
..
|
..
|
||||||
},
|
},
|
||||||
ascription: thir::Ascription { annotation, variance: _ },
|
ascription: thir::Ascription { ref annotation, variance: _ },
|
||||||
} => {
|
} => {
|
||||||
let place =
|
let place =
|
||||||
self.storage_live_binding(block, var, irrefutable_pat.span, OutsideGuard, true);
|
self.storage_live_binding(block, var, irrefutable_pat.span, OutsideGuard, true);
|
||||||
@ -538,7 +538,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||||||
|
|
||||||
let ty_source_info = self.source_info(annotation.span);
|
let ty_source_info = self.source_info(annotation.span);
|
||||||
|
|
||||||
let base = self.canonical_user_type_annotations.push(annotation);
|
let base = self.canonical_user_type_annotations.push(annotation.clone());
|
||||||
self.cfg.push(
|
self.cfg.push(
|
||||||
block,
|
block,
|
||||||
Statement {
|
Statement {
|
||||||
@ -578,7 +578,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||||||
pub(crate) fn place_into_pattern(
|
pub(crate) fn place_into_pattern(
|
||||||
&mut self,
|
&mut self,
|
||||||
block: BasicBlock,
|
block: BasicBlock,
|
||||||
irrefutable_pat: Pat<'tcx>,
|
irrefutable_pat: &Pat<'tcx>,
|
||||||
initializer: PlaceBuilder<'tcx>,
|
initializer: PlaceBuilder<'tcx>,
|
||||||
set_match_place: bool,
|
set_match_place: bool,
|
||||||
) -> BlockAnd<()> {
|
) -> BlockAnd<()> {
|
||||||
|
@ -1052,7 +1052,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||||||
Some((Some(&place), span)),
|
Some((Some(&place), span)),
|
||||||
);
|
);
|
||||||
let place_builder = PlaceBuilder::from(local);
|
let place_builder = PlaceBuilder::from(local);
|
||||||
unpack!(block = self.place_into_pattern(block, *pattern, place_builder, false));
|
unpack!(
|
||||||
|
block =
|
||||||
|
self.place_into_pattern(block, pattern.as_ref(), place_builder, false)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.source_scope = original_source_scope;
|
self.source_scope = original_source_scope;
|
||||||
|
Loading…
Reference in New Issue
Block a user