Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit f37d2b8

Browse files
committed
Use Place directly in librustc_mir_build, it's Copy
1 parent 6a95bf8 commit f37d2b8

File tree

13 files changed

+55
-63
lines changed

13 files changed

+55
-63
lines changed

src/librustc_mir_build/build/block.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_span::Span;
99
impl<'a, 'tcx> Builder<'a, 'tcx> {
1010
crate fn ast_block(
1111
&mut self,
12-
destination: &Place<'tcx>,
12+
destination: Place<'tcx>,
1313
block: BasicBlock,
1414
ast_block: &'tcx hir::Block<'tcx>,
1515
source_info: SourceInfo,
@@ -43,7 +43,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
4343

4444
fn ast_block_stmts(
4545
&mut self,
46-
destination: &Place<'tcx>,
46+
destination: Place<'tcx>,
4747
mut block: BasicBlock,
4848
span: Span,
4949
stmts: Vec<StmtRef<'tcx>>,

src/librustc_mir_build/build/cfg.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,20 @@ impl<'tcx> CFG<'tcx> {
3434
&mut self,
3535
block: BasicBlock,
3636
source_info: SourceInfo,
37-
place: &Place<'tcx>,
37+
place: Place<'tcx>,
3838
rvalue: Rvalue<'tcx>,
3939
) {
4040
self.push(
4141
block,
42-
Statement { source_info, kind: StatementKind::Assign(box (*place, rvalue)) },
42+
Statement { source_info, kind: StatementKind::Assign(box (place, rvalue)) },
4343
);
4444
}
4545

4646
crate fn push_assign_constant(
4747
&mut self,
4848
block: BasicBlock,
4949
source_info: SourceInfo,
50-
temp: &Place<'tcx>,
50+
temp: Place<'tcx>,
5151
constant: Constant<'tcx>,
5252
) {
5353
self.push_assign(block, source_info, temp, Rvalue::Use(Operand::Constant(box constant)));
@@ -57,7 +57,7 @@ impl<'tcx> CFG<'tcx> {
5757
&mut self,
5858
block: BasicBlock,
5959
source_info: SourceInfo,
60-
place: &Place<'tcx>,
60+
place: Place<'tcx>,
6161
) {
6262
self.push_assign(
6363
block,

src/librustc_mir_build/build/expr/as_place.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -341,12 +341,12 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
341341
let lt = self.temp(bool_ty, expr_span);
342342

343343
// len = len(slice)
344-
self.cfg.push_assign(block, source_info, &len, Rvalue::Len(slice));
344+
self.cfg.push_assign(block, source_info, len, Rvalue::Len(slice));
345345
// lt = idx < len
346346
self.cfg.push_assign(
347347
block,
348348
source_info,
349-
&lt,
349+
lt,
350350
Rvalue::BinaryOp(BinOp::Lt, Operand::Copy(Place::from(index)), Operand::Copy(len)),
351351
);
352352
let msg = BoundsCheck { len: Operand::Move(len), index: Operand::Copy(Place::from(index)) };
@@ -388,7 +388,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
388388
self.cfg.push_assign(
389389
block,
390390
source_info,
391-
&fake_borrow_temp.into(),
391+
fake_borrow_temp.into(),
392392
Rvalue::Ref(
393393
tcx.lifetimes.re_erased,
394394
BorrowKind::Shallow,

src/librustc_mir_build/build/expr/as_rvalue.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
7878
this.cfg.push_assign(
7979
block,
8080
source_info,
81-
&is_min,
81+
is_min,
8282
Rvalue::BinaryOp(BinOp::Eq, arg.to_copy(), minval),
8383
);
8484

@@ -109,15 +109,12 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
109109

110110
// malloc some memory of suitable type (thus far, uninitialized):
111111
let box_ = Rvalue::NullaryOp(NullOp::Box, value.ty);
112-
this.cfg.push_assign(block, source_info, &Place::from(result), box_);
112+
this.cfg.push_assign(block, source_info, Place::from(result), box_);
113113

114114
// initialize the box contents:
115115
unpack!(
116-
block = this.into(
117-
&this.hir.tcx().mk_place_deref(Place::from(result)),
118-
block,
119-
value
120-
)
116+
block =
117+
this.into(this.hir.tcx().mk_place_deref(Place::from(result)), block, value)
121118
);
122119
block.and(Rvalue::Use(Operand::Move(Place::from(result))))
123120
}
@@ -284,7 +281,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
284281
self.cfg.push_assign(
285282
block,
286283
source_info,
287-
&result_value,
284+
result_value,
288285
Rvalue::CheckedBinaryOp(op, lhs, rhs),
289286
);
290287
let val_fld = Field::new(0);
@@ -317,7 +314,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
317314
self.cfg.push_assign(
318315
block,
319316
source_info,
320-
&is_zero,
317+
is_zero,
321318
Rvalue::BinaryOp(BinOp::Eq, rhs.to_copy(), zero),
322319
);
323320

@@ -338,13 +335,13 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
338335
self.cfg.push_assign(
339336
block,
340337
source_info,
341-
&is_neg_1,
338+
is_neg_1,
342339
Rvalue::BinaryOp(BinOp::Eq, rhs.to_copy(), neg_1),
343340
);
344341
self.cfg.push_assign(
345342
block,
346343
source_info,
347-
&is_min,
344+
is_min,
348345
Rvalue::BinaryOp(BinOp::Eq, lhs.to_copy(), min),
349346
);
350347

@@ -353,7 +350,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
353350
self.cfg.push_assign(
354351
block,
355352
source_info,
356-
&of,
353+
of,
357354
Rvalue::BinaryOp(BinOp::BitAnd, is_neg_1, is_min),
358355
);
359356

@@ -428,7 +425,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
428425
this.cfg.push_assign(
429426
block,
430427
source_info,
431-
&Place::from(temp),
428+
Place::from(temp),
432429
Rvalue::Ref(this.hir.tcx().lifetimes.re_erased, borrow_kind, arg_place),
433430
);
434431

src/librustc_mir_build/build/expr/as_temp.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
6666
}
6767
this.local_decls.push(local_decl)
6868
};
69-
let temp_place = &Place::from(temp);
69+
let temp_place = Place::from(temp);
7070

7171
match expr.kind {
7272
// Don't bother with StorageLive and Dead for these temporaries,

src/librustc_mir_build/build/expr/into.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
1616
/// is assumed to be uninitialized.
1717
crate fn into_expr(
1818
&mut self,
19-
destination: &Place<'tcx>,
19+
destination: Place<'tcx>,
2020
mut block: BasicBlock,
2121
expr: Expr<'tcx>,
2222
) -> BlockAnd<()> {
@@ -160,7 +160,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
160160
// introduce a unit temporary as the destination for the loop body.
161161
let tmp = this.get_unit_temp();
162162
// Execute the body, branching back to the test.
163-
let body_block_end = unpack!(this.into(&tmp, body_block, body));
163+
let body_block_end = unpack!(this.into(tmp, body_block, body));
164164
this.cfg.goto(body_block_end, source_info, loop_block);
165165
},
166166
);
@@ -202,8 +202,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
202202
is_block_tail: None,
203203
});
204204
let ptr_temp = Place::from(ptr_temp);
205-
let block = unpack!(this.into(&ptr_temp, block, ptr));
206-
this.into(&this.hir.tcx().mk_place_deref(ptr_temp), block, val)
205+
let block = unpack!(this.into(ptr_temp, block, ptr));
206+
this.into(this.hir.tcx().mk_place_deref(ptr_temp), block, val)
207207
} else {
208208
let args: Vec<_> = args
209209
.into_iter()
@@ -228,7 +228,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
228228
destination: if expr.ty.is_never() {
229229
None
230230
} else {
231-
Some((*destination, success))
231+
Some((destination, success))
232232
},
233233
from_hir_call,
234234
},
@@ -373,12 +373,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
373373
this.cfg.terminate(
374374
block,
375375
source_info,
376-
TerminatorKind::Yield {
377-
value,
378-
resume,
379-
resume_arg: *destination,
380-
drop: cleanup,
381-
},
376+
TerminatorKind::Yield { value, resume, resume_arg: destination, drop: cleanup },
382377
);
383378
resume.unit()
384379
}

src/librustc_mir_build/build/expr/stmt.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
5050
} else {
5151
let rhs = unpack!(block = this.as_local_rvalue(block, rhs));
5252
let lhs = unpack!(block = this.as_place(block, lhs));
53-
this.cfg.push_assign(block, source_info, &lhs, rhs);
53+
this.cfg.push_assign(block, source_info, lhs, rhs);
5454
}
5555

5656
this.block_context.pop();
@@ -82,7 +82,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
8282
block =
8383
this.build_binary_op(block, op, expr_span, lhs_ty, Operand::Copy(lhs), rhs)
8484
);
85-
this.cfg.push_assign(block, source_info, &lhs, result);
85+
this.cfg.push_assign(block, source_info, lhs, result);
8686

8787
this.block_context.pop();
8888
block.unit()

src/librustc_mir_build/build/into.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ pub(in crate::build) trait EvalInto<'tcx> {
1212
fn eval_into(
1313
self,
1414
builder: &mut Builder<'_, 'tcx>,
15-
destination: &Place<'tcx>,
15+
destination: Place<'tcx>,
1616
block: BasicBlock,
1717
) -> BlockAnd<()>;
1818
}
1919

2020
impl<'a, 'tcx> Builder<'a, 'tcx> {
2121
crate fn into<E>(
2222
&mut self,
23-
destination: &Place<'tcx>,
23+
destination: Place<'tcx>,
2424
block: BasicBlock,
2525
expr: E,
2626
) -> BlockAnd<()>
@@ -35,7 +35,7 @@ impl<'tcx> EvalInto<'tcx> for ExprRef<'tcx> {
3535
fn eval_into(
3636
self,
3737
builder: &mut Builder<'_, 'tcx>,
38-
destination: &Place<'tcx>,
38+
destination: Place<'tcx>,
3939
block: BasicBlock,
4040
) -> BlockAnd<()> {
4141
let expr = builder.hir.mirror(self);
@@ -47,7 +47,7 @@ impl<'tcx> EvalInto<'tcx> for Expr<'tcx> {
4747
fn eval_into(
4848
self,
4949
builder: &mut Builder<'_, 'tcx>,
50-
destination: &Place<'tcx>,
50+
destination: Place<'tcx>,
5151
block: BasicBlock,
5252
) -> BlockAnd<()> {
5353
builder.into_expr(destination, block, self)

src/librustc_mir_build/build/matches/mod.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ use crate::build::ForGuard::{self, OutsideGuard, RefWithinGuard};
1010
use crate::build::{BlockAnd, BlockAndExtension, Builder};
1111
use crate::build::{GuardFrame, GuardFrameLocal, LocalsForNode};
1212
use crate::hair::{self, *};
13+
use rustc_ast::ast::Name;
14+
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
15+
use rustc_hir::HirId;
16+
use rustc_index::bit_set::BitSet;
1317
use rustc_middle::middle::region;
1418
use rustc_middle::mir::*;
1519
use rustc_middle::ty::layout::VariantIdx;
1620
use rustc_middle::ty::{self, CanonicalUserTypeAnnotation, Ty};
17-
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
18-
use rustc_hir::HirId;
19-
use rustc_index::bit_set::BitSet;
2021
use rustc_span::Span;
2122
use smallvec::{smallvec, SmallVec};
22-
use rustc_ast::ast::Name;
2323

2424
// helper functions, broken out by category:
2525
mod simplify;
@@ -83,7 +83,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
8383
/// * From each otherwise block to the next prebinding block.
8484
crate fn match_expr(
8585
&mut self,
86-
destination: &Place<'tcx>,
86+
destination: Place<'tcx>,
8787
span: Span,
8888
mut block: BasicBlock,
8989
scrutinee: ExprRef<'tcx>,
@@ -218,7 +218,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
218218
/// `outer_source_info` is the SourceInfo for the whole match.
219219
fn lower_match_arms(
220220
&mut self,
221-
destination: &Place<'tcx>,
221+
destination: Place<'tcx>,
222222
scrutinee_place: Place<'tcx>,
223223
scrutinee_span: Span,
224224
arm_candidates: Vec<(&'_ Arm<'tcx>, Candidate<'_, 'tcx>)>,
@@ -364,7 +364,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
364364
PatKind::Binding { mode: BindingMode::ByValue, var, subpattern: None, .. } => {
365365
let place =
366366
self.storage_live_binding(block, var, irrefutable_pat.span, OutsideGuard, true);
367-
unpack!(block = self.into(&place, block, initializer));
367+
unpack!(block = self.into(place, block, initializer));
368368

369369
// Inject a fake read, see comments on `FakeReadCause::ForLet`.
370370
let source_info = self.source_info(irrefutable_pat.span);
@@ -399,7 +399,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
399399
} => {
400400
let place =
401401
self.storage_live_binding(block, var, irrefutable_pat.span, OutsideGuard, true);
402-
unpack!(block = self.into(&place, block, initializer));
402+
unpack!(block = self.into(place, block, initializer));
403403

404404
// Inject a fake read, see comments on `FakeReadCause::ForLet`.
405405
let pattern_source_info = self.source_info(irrefutable_pat.span);
@@ -1691,7 +1691,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
16911691
let scrutinee_source_info = self.source_info(scrutinee_span);
16921692
for &(place, temp) in fake_borrows {
16931693
let borrow = Rvalue::Ref(re_erased, BorrowKind::Shallow, place);
1694-
self.cfg.push_assign(block, scrutinee_source_info, &Place::from(temp), borrow);
1694+
self.cfg.push_assign(block, scrutinee_source_info, Place::from(temp), borrow);
16951695
}
16961696

16971697
// the block to branch to if the guard fails; if there is no
@@ -1858,7 +1858,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
18581858
match binding.binding_mode {
18591859
BindingMode::ByValue => {
18601860
let rvalue = Rvalue::Ref(re_erased, BorrowKind::Shared, binding.source);
1861-
self.cfg.push_assign(block, source_info, &ref_for_guard, rvalue);
1861+
self.cfg.push_assign(block, source_info, ref_for_guard, rvalue);
18621862
}
18631863
BindingMode::ByRef(borrow_kind) => {
18641864
let value_for_arm = self.storage_live_binding(
@@ -1870,9 +1870,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
18701870
);
18711871

18721872
let rvalue = Rvalue::Ref(re_erased, borrow_kind, binding.source);
1873-
self.cfg.push_assign(block, source_info, &value_for_arm, rvalue);
1873+
self.cfg.push_assign(block, source_info, value_for_arm, rvalue);
18741874
let rvalue = Rvalue::Ref(re_erased, BorrowKind::Shared, value_for_arm);
1875-
self.cfg.push_assign(block, source_info, &ref_for_guard, rvalue);
1875+
self.cfg.push_assign(block, source_info, ref_for_guard, rvalue);
18761876
}
18771877
}
18781878
}
@@ -1910,7 +1910,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
19101910
Rvalue::Ref(re_erased, borrow_kind, binding.source)
19111911
}
19121912
};
1913-
self.cfg.push_assign(block, source_info, &local, rvalue);
1913+
self.cfg.push_assign(block, source_info, local, rvalue);
19141914
}
19151915
}
19161916

0 commit comments

Comments
 (0)