Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-ty/src/mir/lower/pattern_matching.rs')
-rw-r--r--crates/hir-ty/src/mir/lower/pattern_matching.rs56
1 files changed, 21 insertions, 35 deletions
diff --git a/crates/hir-ty/src/mir/lower/pattern_matching.rs b/crates/hir-ty/src/mir/lower/pattern_matching.rs
index bbb513b24c..ea0beef3c0 100644
--- a/crates/hir-ty/src/mir/lower/pattern_matching.rs
+++ b/crates/hir-ty/src/mir/lower/pattern_matching.rs
@@ -58,7 +58,7 @@ impl MirLowerCtx<'_> {
let (current, current_else) = self.pattern_match_inner(
current,
current_else,
- cond_place.clone(),
+ cond_place,
pattern,
MatchingMode::Check,
)?;
@@ -114,7 +114,7 @@ impl MirLowerCtx<'_> {
index: i as u32,
}))
}),
- &(&mut cond_place),
+ &mut cond_place,
mode,
)?
}
@@ -125,7 +125,7 @@ impl MirLowerCtx<'_> {
let (mut next, next_else) = self.pattern_match_inner(
current,
None,
- (&mut cond_place).clone(),
+ cond_place,
*pat,
MatchingMode::Check,
)?;
@@ -133,7 +133,7 @@ impl MirLowerCtx<'_> {
(next, _) = self.pattern_match_inner(
next,
None,
- (&mut cond_place).clone(),
+ cond_place,
*pat,
MatchingMode::Bind,
)?;
@@ -169,7 +169,7 @@ impl MirLowerCtx<'_> {
current,
pattern.into(),
current_else,
- AdtPatternShape::Record { args: &*args },
+ AdtPatternShape::Record { args },
mode,
)?
}
@@ -183,12 +183,8 @@ impl MirLowerCtx<'_> {
self.temp(TyBuilder::bool(), current, pattern.into())?.into();
self.push_assignment(
current,
- discr.clone(),
- Rvalue::CheckedBinaryOp(
- binop,
- lv,
- Operand::Copy((&mut cond_place).clone()),
- ),
+ discr,
+ Rvalue::CheckedBinaryOp(binop, lv, Operand::Copy(cond_place)),
pattern.into(),
);
let discr = Operand::Copy(discr);
@@ -222,8 +218,8 @@ impl MirLowerCtx<'_> {
self.temp(TyBuilder::usize(), current, pattern.into())?.into();
self.push_assignment(
current,
- place_len.clone(),
- Rvalue::Len((&mut cond_place).clone()),
+ place_len,
+ Rvalue::Len(cond_place),
pattern.into(),
);
let else_target =
@@ -252,7 +248,7 @@ impl MirLowerCtx<'_> {
self.temp(TyBuilder::bool(), current, pattern.into())?.into();
self.push_assignment(
current,
- discr.clone(),
+ discr,
Rvalue::CheckedBinaryOp(BinOp::Le, c, Operand::Copy(place_len)),
pattern.into(),
);
@@ -270,7 +266,7 @@ impl MirLowerCtx<'_> {
}
}
for (i, &pat) in prefix.iter().enumerate() {
- let next_place = (&mut cond_place).project(
+ let next_place = cond_place.project(
ProjectionElem::ConstantIndex { offset: i as u64, from_end: false },
&mut self.result.projection_store,
);
@@ -280,7 +276,7 @@ impl MirLowerCtx<'_> {
if let Some(slice) = slice {
if mode == MatchingMode::Bind {
if let Pat::Bind { id, subpat: _ } = self.body[*slice] {
- let next_place = (&mut cond_place).project(
+ let next_place = cond_place.project(
ProjectionElem::Subslice {
from: prefix.len() as u64,
to: suffix.len() as u64,
@@ -299,7 +295,7 @@ impl MirLowerCtx<'_> {
}
}
for (i, &pat) in suffix.iter().enumerate() {
- let next_place = (&mut cond_place).project(
+ let next_place = cond_place.project(
ProjectionElem::ConstantIndex { offset: i as u64, from_end: true },
&mut self.result.projection_store,
);
@@ -348,7 +344,7 @@ impl MirLowerCtx<'_> {
self.lower_const(
c.into(),
current,
- tmp.clone(),
+ tmp,
subst,
span,
self.infer[pattern].clone(),
@@ -356,7 +352,7 @@ impl MirLowerCtx<'_> {
let tmp2: Place = self.temp(TyBuilder::bool(), current, pattern.into())?.into();
self.push_assignment(
current,
- tmp2.clone(),
+ tmp2,
Rvalue::CheckedBinaryOp(
BinOp::Eq,
Operand::Copy(tmp),
@@ -390,13 +386,8 @@ impl MirLowerCtx<'_> {
},
Pat::Bind { id, subpat } => {
if let Some(subpat) = subpat {
- (current, current_else) = self.pattern_match_inner(
- current,
- current_else,
- (&mut cond_place).clone(),
- *subpat,
- mode,
- )?
+ (current, current_else) =
+ self.pattern_match_inner(current, current_else, cond_place, *subpat, mode)?
}
if mode == MatchingMode::Bind {
self.pattern_match_binding(
@@ -475,7 +466,7 @@ impl MirLowerCtx<'_> {
let discr: Place = self.temp(TyBuilder::bool(), current, pattern.into())?.into();
self.push_assignment(
current,
- discr.clone(),
+ discr,
Rvalue::CheckedBinaryOp(BinOp::Eq, c, Operand::Copy(cond_place)),
pattern.into(),
);
@@ -506,12 +497,7 @@ impl MirLowerCtx<'_> {
if mode == MatchingMode::Check {
let e = self.const_eval_discriminant(v)? as u128;
let tmp = self.discr_temp_place(current);
- self.push_assignment(
- current,
- tmp.clone(),
- Rvalue::Discriminant(cond_place.clone()),
- span,
- );
+ self.push_assignment(current, tmp, Rvalue::Discriminant(cond_place), span);
let next = self.new_basic_block();
let else_target = current_else.get_or_insert_with(|| self.new_basic_block());
self.set_terminator(
@@ -568,7 +554,7 @@ impl MirLowerCtx<'_> {
variant_data.field(&x.name).ok_or(MirLowerError::UnresolvedField)?;
Ok((
PlaceElem::Field(Either::Left(FieldId {
- parent: v.into(),
+ parent: v,
local_id: field_id,
})),
x.pat,
@@ -579,7 +565,7 @@ impl MirLowerCtx<'_> {
}
AdtPatternShape::Tuple { args, ellipsis } => {
let fields = variant_data.fields().iter().map(|(x, _)| {
- PlaceElem::Field(Either::Left(FieldId { parent: v.into(), local_id: x }))
+ PlaceElem::Field(Either::Left(FieldId { parent: v, local_id: x }))
});
self.pattern_match_tuple_like(
current,