Skip to content

Commit 9b9dafb

Browse files
committed
Make use of Place: Copy
1 parent 1d90ed6 commit 9b9dafb

File tree

4 files changed

+34
-42
lines changed

4 files changed

+34
-42
lines changed

src/librustc_mir_build/build/matches/mod.rs

+20-22
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
9393
let scrutinee_place =
9494
unpack!(block = self.lower_scrutinee(block, scrutinee, scrutinee_span,));
9595

96-
let mut arm_candidates = self.create_match_candidates(&scrutinee_place, &arms);
96+
let mut arm_candidates = self.create_match_candidates(scrutinee_place, &arms);
9797

9898
let match_has_guard = arms.iter().any(|arm| arm.guard.is_some());
9999
let mut candidates =
@@ -103,7 +103,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
103103
self.lower_match_tree(block, scrutinee_span, match_has_guard, &mut candidates);
104104

105105
self.lower_match_arms(
106-
&destination,
106+
destination,
107107
scrutinee_place,
108108
scrutinee_span,
109109
arm_candidates,
@@ -137,23 +137,23 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
137137
// check safety.
138138
let cause_matched_place = FakeReadCause::ForMatchedPlace;
139139
let source_info = self.source_info(scrutinee_span);
140-
self.cfg.push_fake_read(block, source_info, cause_matched_place, scrutinee_place.clone());
140+
self.cfg.push_fake_read(block, source_info, cause_matched_place, scrutinee_place);
141141

142142
block.and(scrutinee_place)
143143
}
144144

145145
/// Create the initial `Candidate`s for a `match` expression.
146146
fn create_match_candidates<'pat>(
147147
&mut self,
148-
scrutinee: &Place<'tcx>,
148+
scrutinee: Place<'tcx>,
149149
arms: &'pat [Arm<'tcx>],
150150
) -> Vec<(&'pat Arm<'tcx>, Candidate<'pat, 'tcx>)> {
151151
// Assemble a list of candidates: there is one candidate per pattern,
152152
// which means there may be more than one candidate *per arm*.
153153
arms.iter()
154154
.map(|arm| {
155155
let arm_has_guard = arm.guard.is_some();
156-
let arm_candidate = Candidate::new(*scrutinee, &arm.pattern, arm_has_guard);
156+
let arm_candidate = Candidate::new(scrutinee, &arm.pattern, arm_has_guard);
157157
(arm, arm_candidate)
158158
})
159159
.collect()
@@ -391,7 +391,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
391391
// Inject a fake read, see comments on `FakeReadCause::ForLet`.
392392
let pattern_source_info = self.source_info(irrefutable_pat.span);
393393
let cause_let = FakeReadCause::ForLet;
394-
self.cfg.push_fake_read(block, pattern_source_info, cause_let, place.clone());
394+
self.cfg.push_fake_read(block, pattern_source_info, cause_let, place);
395395

396396
let ty_source_info = self.source_info(user_ty_span);
397397
let user_ty = pat_ascription_ty.user_ty(
@@ -430,7 +430,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
430430

431431
_ => {
432432
let place = unpack!(block = self.as_place(block, initializer));
433-
self.place_into_pattern(block, irrefutable_pat, &place, true)
433+
self.place_into_pattern(block, irrefutable_pat, place, true)
434434
}
435435
}
436436
}
@@ -439,10 +439,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
439439
&mut self,
440440
block: BasicBlock,
441441
irrefutable_pat: Pat<'tcx>,
442-
initializer: &Place<'tcx>,
442+
initializer: Place<'tcx>,
443443
set_match_place: bool,
444444
) -> BlockAnd<()> {
445-
let mut candidate = Candidate::new(*initializer, &irrefutable_pat, false);
445+
let mut candidate = Candidate::new(initializer, &irrefutable_pat, false);
446446

447447
let fake_borrow_temps =
448448
self.lower_match_tree(block, irrefutable_pat.span, false, &mut [&mut candidate]);
@@ -461,7 +461,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
461461
VarBindingForm { opt_match_place: Some((ref mut match_place, _)), .. },
462462
))) = self.local_decls[local].local_info
463463
{
464-
*match_place = Some(*initializer);
464+
*match_place = Some(initializer);
465465
} else {
466466
bug!("Let binding to non-user variable.")
467467
}
@@ -897,7 +897,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
897897
span: Span,
898898
start_block: BasicBlock,
899899
otherwise_block: &mut Option<BasicBlock>,
900-
candidates: &mut [&mut Candidate<_, 'tcx>],
900+
candidates: &mut [&mut Candidate<'_, 'tcx>],
901901
fake_borrows: &mut Option<FxHashSet<Place<'tcx>>>,
902902
) {
903903
// The candidates are sorted by priority. Check to see whether the
@@ -1121,7 +1121,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
11211121
for match_pair in match_pairs {
11221122
if let PatKind::Or { ref pats } = *match_pair.pattern.kind {
11231123
let or_span = match_pair.pattern.span;
1124-
let place = &match_pair.place;
1124+
let place = match_pair.place;
11251125

11261126
first_candidate.visit_leaves(|leaf_candidate| {
11271127
self.test_or_pattern(
@@ -1155,14 +1155,12 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
11551155
otherwise: &mut Option<BasicBlock>,
11561156
pats: &'pat [Pat<'tcx>],
11571157
or_span: Span,
1158-
place: &Place<'tcx>,
1158+
place: Place<'tcx>,
11591159
fake_borrows: &mut Option<FxHashSet<Place<'tcx>>>,
11601160
) {
11611161
debug!("test_or_pattern:\ncandidate={:#?}\npats={:#?}", candidate, pats);
1162-
let mut or_candidates: Vec<_> = pats
1163-
.iter()
1164-
.map(|pat| Candidate::new(place.clone(), pat, candidate.has_guard))
1165-
.collect();
1162+
let mut or_candidates: Vec<_> =
1163+
pats.iter().map(|pat| Candidate::new(place, pat, candidate.has_guard)).collect();
11661164
let mut or_candidate_refs: Vec<_> = or_candidates.iter_mut().collect();
11671165
let otherwise = if candidate.otherwise_block.is_some() {
11681166
&mut candidate.otherwise_block
@@ -1368,7 +1366,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
13681366
}
13691367

13701368
// Insert a Shallow borrow of any places that is switched on.
1371-
fake_borrows.as_mut().map(|fb| fb.insert(match_place.clone()));
1369+
fake_borrows.as_mut().map(|fb| fb.insert(match_place));
13721370

13731371
// perform the test, branching to one of N blocks. For each of
13741372
// those N possible outcomes, create a (initially empty)
@@ -1448,7 +1446,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
14481446
target_blocks
14491447
};
14501448

1451-
self.perform_test(block, &match_place, &test, make_target_blocks);
1449+
self.perform_test(block, match_place, &test, make_target_blocks);
14521450
}
14531451

14541452
/// Determine the fake borrows that are needed from a set of places that
@@ -1669,9 +1667,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
16691667

16701668
let re_erased = tcx.lifetimes.re_erased;
16711669
let scrutinee_source_info = self.source_info(scrutinee_span);
1672-
for (place, temp) in fake_borrows {
1673-
let borrow = Rvalue::Ref(re_erased, BorrowKind::Shallow, *place);
1674-
self.cfg.push_assign(block, scrutinee_source_info, &Place::from(*temp), borrow);
1670+
for &(place, temp) in fake_borrows {
1671+
let borrow = Rvalue::Ref(re_erased, BorrowKind::Shallow, place);
1672+
self.cfg.push_assign(block, scrutinee_source_info, &Place::from(temp), borrow);
16751673
}
16761674

16771675
// the block to branch to if the guard fails; if there is no

src/librustc_mir_build/build/matches/simplify.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
4545
loop {
4646
let match_pairs = mem::take(&mut candidate.match_pairs);
4747

48-
if let [MatchPair { pattern: Pat { kind: box PatKind::Or { pats }, .. }, ref place }] =
48+
if let [MatchPair { pattern: Pat { kind: box PatKind::Or { pats }, .. }, place }] =
4949
*match_pairs
5050
{
5151
candidate.subcandidates = self.create_or_subcandidates(candidate, place, pats);
@@ -78,12 +78,12 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
7878
fn create_or_subcandidates<'pat>(
7979
&mut self,
8080
candidate: &Candidate<'pat, 'tcx>,
81-
place: &Place<'tcx>,
81+
place: Place<'tcx>,
8282
pats: &'pat [Pat<'tcx>],
8383
) -> Vec<Candidate<'pat, 'tcx>> {
8484
pats.iter()
8585
.map(|pat| {
86-
let mut candidate = Candidate::new(place.clone(), pat, candidate.has_guard);
86+
let mut candidate = Candidate::new(place, pat, candidate.has_guard);
8787
self.simplify_candidate(&mut candidate);
8888
candidate
8989
})

src/librustc_mir_build/build/matches/test.rs

+10-16
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
155155
pub(super) fn perform_test(
156156
&mut self,
157157
block: BasicBlock,
158-
place: &Place<'tcx>,
158+
place: Place<'tcx>,
159159
test: &Test<'tcx>,
160160
make_target_blocks: impl FnOnce(&mut Self) -> Vec<BasicBlock>,
161161
) {
@@ -205,7 +205,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
205205
);
206206
let discr_ty = adt_def.repr.discr_type().to_ty(tcx);
207207
let discr = self.temp(discr_ty, test.span);
208-
self.cfg.push_assign(block, source_info, &discr, Rvalue::Discriminant(*place));
208+
self.cfg.push_assign(block, source_info, &discr, Rvalue::Discriminant(place));
209209
assert_eq!(values.len() + 1, targets.len());
210210
self.cfg.terminate(
211211
block,
@@ -229,20 +229,15 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
229229
0 => (second_bb, first_bb),
230230
v => span_bug!(test.span, "expected boolean value but got {:?}", v),
231231
};
232-
TerminatorKind::if_(
233-
self.hir.tcx(),
234-
Operand::Copy(*place),
235-
true_bb,
236-
false_bb,
237-
)
232+
TerminatorKind::if_(self.hir.tcx(), Operand::Copy(place), true_bb, false_bb)
238233
} else {
239234
bug!("`TestKind::SwitchInt` on `bool` should have two targets")
240235
}
241236
} else {
242237
// The switch may be inexhaustive so we have a catch all block
243238
debug_assert_eq!(options.len() + 1, target_blocks.len());
244239
TerminatorKind::SwitchInt {
245-
discr: Operand::Copy(*place),
240+
discr: Operand::Copy(place),
246241
switch_ty,
247242
values: options.clone().into(),
248243
targets: target_blocks,
@@ -267,7 +262,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
267262
if let [success, fail] = *make_target_blocks(self) {
268263
assert_eq!(value.ty, ty);
269264
let expect = self.literal_operand(test.span, value);
270-
let val = Operand::Copy(*place);
265+
let val = Operand::Copy(place);
271266
self.compare(block, success, fail, source_info, BinOp::Eq, expect, val);
272267
} else {
273268
bug!("`TestKind::Eq` should have two target blocks");
@@ -282,7 +277,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
282277
// Test `val` by computing `lo <= val && val <= hi`, using primitive comparisons.
283278
let lo = self.literal_operand(test.span, lo);
284279
let hi = self.literal_operand(test.span, hi);
285-
let val = Operand::Copy(*place);
280+
let val = Operand::Copy(place);
286281

287282
if let [success, fail] = *target_blocks {
288283
self.compare(
@@ -311,7 +306,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
311306
let actual = self.temp(usize_ty, test.span);
312307

313308
// actual = len(place)
314-
self.cfg.push_assign(block, source_info, &actual, Rvalue::Len(*place));
309+
self.cfg.push_assign(block, source_info, &actual, Rvalue::Len(place));
315310

316311
// expected = <N>
317312
let expected = self.push_usize(block, source_info, len);
@@ -367,13 +362,13 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
367362
make_target_blocks: impl FnOnce(&mut Self) -> Vec<BasicBlock>,
368363
source_info: SourceInfo,
369364
value: &'tcx ty::Const<'tcx>,
370-
place: &Place<'tcx>,
365+
place: Place<'tcx>,
371366
mut ty: Ty<'tcx>,
372367
) {
373368
use rustc::middle::lang_items::EqTraitLangItem;
374369

375370
let mut expect = self.literal_operand(source_info.span, value);
376-
let mut val = Operand::Copy(*place);
371+
let mut val = Operand::Copy(place);
377372

378373
// If we're using `b"..."` as a pattern, we need to insert an
379374
// unsizing coercion, as the byte string has the type `&[u8; N]`.
@@ -751,8 +746,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
751746
let downcast_place = tcx.mk_place_elem(match_pair.place, elem); // `(x as Variant)`
752747
let consequent_match_pairs = subpatterns.iter().map(|subpattern| {
753748
// e.g., `(x as Variant).0`
754-
let place =
755-
tcx.mk_place_field(downcast_place.clone(), subpattern.field, subpattern.pattern.ty);
749+
let place = tcx.mk_place_field(downcast_place, subpattern.field, subpattern.pattern.ty);
756750
// e.g., `(x as Variant).0 @ P1`
757751
MatchPair::new(place, &subpattern.pattern)
758752
});

src/librustc_mir_build/build/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -899,7 +899,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
899899
matches::ArmHasGuard(false),
900900
Some((Some(&place), span)),
901901
);
902-
unpack!(block = self.place_into_pattern(block, pattern, &place, false));
902+
unpack!(block = self.place_into_pattern(block, pattern, place, false));
903903
}
904904
}
905905
self.source_scope = original_source_scope;

0 commit comments

Comments
 (0)