Skip to content

Commit 7299d1e

Browse files
committed
Stop using the unpack! macro
1 parent 5f82371 commit 7299d1e

File tree

9 files changed

+140
-178
lines changed

9 files changed

+140
-178
lines changed

compiler/rustc_mir_build/src/build/block.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
226226
});
227227
matching.and(failure)
228228
});
229-
let failure = unpack!(block = failure_and_block);
229+
let failure = failure_and_block.unpack(&mut block);
230230
this.cfg.goto(failure, source_info, failure_entry);
231231

232232
if let Some(source_scope) = visibility_scope {

compiler/rustc_mir_build/src/build/expr/as_operand.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
128128
block.and(Operand::Constant(Box::new(constant)))
129129
}
130130
Category::Constant | Category::Place | Category::Rvalue(..) => {
131-
let operand = unpack!(block = this.as_temp(block, scope, expr_id, Mutability::Mut));
131+
let operand =
132+
this.as_temp(block, scope, expr_id, Mutability::Mut).unpack(&mut block);
132133
// Overwrite temp local info if we have something more interesting to record.
133134
if !matches!(local_info, LocalInfo::Boring) {
134135
let decl_info =
@@ -174,7 +175,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
174175
// type, and that value is coming from the deref of a box.
175176
if let ExprKind::Deref { arg } = expr.kind {
176177
// Generate let tmp0 = arg0
177-
let operand = unpack!(block = this.as_temp(block, scope, arg, Mutability::Mut));
178+
let operand =
179+
this.as_temp(block, scope, arg, Mutability::Mut).unpack(&mut block);
178180

179181
// Return the operand *tmp0 to be used as the call argument
180182
let place = Place {

compiler/rustc_mir_build/src/build/expr/as_place.rs

+17-15
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
369369
mut block: BasicBlock,
370370
expr_id: ExprId,
371371
) -> BlockAnd<Place<'tcx>> {
372-
let place_builder = unpack!(block = self.as_place_builder(block, expr_id));
372+
let place_builder = self.as_place_builder(block, expr_id).unpack(&mut block);
373373
block.and(place_builder.to_place(self))
374374
}
375375

@@ -393,7 +393,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
393393
mut block: BasicBlock,
394394
expr_id: ExprId,
395395
) -> BlockAnd<Place<'tcx>> {
396-
let place_builder = unpack!(block = self.as_read_only_place_builder(block, expr_id));
396+
let place_builder = self.as_read_only_place_builder(block, expr_id).unpack(&mut block);
397397
block.and(place_builder.to_place(self))
398398
}
399399

@@ -432,8 +432,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
432432
}
433433
ExprKind::Field { lhs, variant_index, name } => {
434434
let lhs_expr = &this.thir[lhs];
435-
let mut place_builder =
436-
unpack!(block = this.expr_as_place(block, lhs, mutability, fake_borrow_temps,));
435+
let mut place_builder = this
436+
.expr_as_place(block, lhs, mutability, fake_borrow_temps)
437+
.unpack(&mut block);
437438
if let ty::Adt(adt_def, _) = lhs_expr.ty.kind() {
438439
if adt_def.is_enum() {
439440
place_builder = place_builder.downcast(*adt_def, variant_index);
@@ -442,8 +443,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
442443
block.and(place_builder.field(name, expr.ty))
443444
}
444445
ExprKind::Deref { arg } => {
445-
let place_builder =
446-
unpack!(block = this.expr_as_place(block, arg, mutability, fake_borrow_temps,));
446+
let place_builder = this
447+
.expr_as_place(block, arg, mutability, fake_borrow_temps)
448+
.unpack(&mut block);
447449
block.and(place_builder.deref())
448450
}
449451
ExprKind::Index { lhs, index } => this.lower_index_expression(
@@ -472,9 +474,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
472474
}
473475

474476
ExprKind::PlaceTypeAscription { source, ref user_ty } => {
475-
let place_builder = unpack!(
476-
block = this.expr_as_place(block, source, mutability, fake_borrow_temps,)
477-
);
477+
let place_builder = this
478+
.expr_as_place(block, source, mutability, fake_borrow_temps)
479+
.unpack(&mut block);
478480
if let Some(user_ty) = user_ty {
479481
let annotation_index =
480482
this.canonical_user_type_annotations.push(CanonicalUserTypeAnnotation {
@@ -502,9 +504,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
502504
}
503505
ExprKind::ValueTypeAscription { source, ref user_ty } => {
504506
let source_expr = &this.thir[source];
505-
let temp = unpack!(
506-
block = this.as_temp(block, source_expr.temp_lifetime, source, mutability)
507-
);
507+
let temp = this
508+
.as_temp(block, source_expr.temp_lifetime, source, mutability)
509+
.unpack(&mut block);
508510
if let Some(user_ty) = user_ty {
509511
let annotation_index =
510512
this.canonical_user_type_annotations.push(CanonicalUserTypeAnnotation {
@@ -570,7 +572,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
570572
// these are not places, so we need to make a temporary.
571573
debug_assert!(!matches!(Category::of(&expr.kind), Some(Category::Place)));
572574
let temp =
573-
unpack!(block = this.as_temp(block, expr.temp_lifetime, expr_id, mutability));
575+
this.as_temp(block, expr.temp_lifetime, expr_id, mutability).unpack(&mut block);
574576
block.and(PlaceBuilder::from(temp))
575577
}
576578
}
@@ -612,12 +614,12 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
612614
let fake_borrow_temps = fake_borrow_temps.unwrap_or(base_fake_borrow_temps);
613615

614616
let base_place =
615-
unpack!(block = self.expr_as_place(block, base, mutability, Some(fake_borrow_temps),));
617+
self.expr_as_place(block, base, mutability, Some(fake_borrow_temps)).unpack(&mut block);
616618

617619
// Making this a *fresh* temporary means we do not have to worry about
618620
// the index changing later: Nothing will ever change this temporary.
619621
// The "retagging" transformation (for Stacked Borrows) relies on this.
620-
let idx = unpack!(block = self.as_temp(block, temp_lifetime, index, Mutability::Not));
622+
let idx = self.as_temp(block, temp_lifetime, index, Mutability::Not).unpack(&mut block);
621623

622624
block = self.bounds_check(block, &base_place, idx, expr_span, source_info);
623625

compiler/rustc_mir_build/src/build/expr/as_rvalue.rs

+45-91
Original file line numberDiff line numberDiff line change
@@ -60,39 +60,25 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
6060
if Some(0) == count.try_eval_target_usize(this.tcx, this.param_env) {
6161
this.build_zero_repeat(block, value, scope, source_info)
6262
} else {
63-
let value_operand = unpack!(
64-
block = this.as_operand(
65-
block,
66-
scope,
67-
value,
68-
LocalInfo::Boring,
69-
NeedsTemporary::No
70-
)
71-
);
63+
let value_operand = this
64+
.as_operand(block, scope, value, LocalInfo::Boring, NeedsTemporary::No)
65+
.unpack(&mut block);
7266
block.and(Rvalue::Repeat(value_operand, count))
7367
}
7468
}
7569
ExprKind::Binary { op, lhs, rhs } => {
76-
let lhs = unpack!(
77-
block = this.as_operand(
78-
block,
79-
scope,
80-
lhs,
81-
LocalInfo::Boring,
82-
NeedsTemporary::Maybe
83-
)
84-
);
85-
let rhs = unpack!(
86-
block =
87-
this.as_operand(block, scope, rhs, LocalInfo::Boring, NeedsTemporary::No)
88-
);
70+
let lhs = this
71+
.as_operand(block, scope, lhs, LocalInfo::Boring, NeedsTemporary::Maybe)
72+
.unpack(&mut block);
73+
let rhs = this
74+
.as_operand(block, scope, rhs, LocalInfo::Boring, NeedsTemporary::No)
75+
.unpack(&mut block);
8976
this.build_binary_op(block, op, expr_span, expr.ty, lhs, rhs)
9077
}
9178
ExprKind::Unary { op, arg } => {
92-
let arg = unpack!(
93-
block =
94-
this.as_operand(block, scope, arg, LocalInfo::Boring, NeedsTemporary::No)
95-
);
79+
let arg = this
80+
.as_operand(block, scope, arg, LocalInfo::Boring, NeedsTemporary::No)
81+
.unpack(&mut block);
9682
// Check for -MIN on signed integers
9783
if this.check_overflow && op == UnOp::Neg && expr.ty.is_signed() {
9884
let bool_ty = this.tcx.types.bool;
@@ -200,7 +186,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
200186
&& adt_def.is_enum()
201187
{
202188
let discr_ty = adt_def.repr().discr_type().to_ty(this.tcx);
203-
let temp = unpack!(block = this.as_temp(block, scope, source, Mutability::Not));
189+
let temp =
190+
this.as_temp(block, scope, source, Mutability::Not).unpack(&mut block);
204191
let layout = this.tcx.layout_of(this.param_env.and(source_expr.ty));
205192
let discr = this.temp(discr_ty, source_expr.span);
206193
this.cfg.push_assign(
@@ -282,15 +269,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
282269
(op, ty)
283270
} else {
284271
let ty = source_expr.ty;
285-
let source = unpack!(
286-
block = this.as_operand(
287-
block,
288-
scope,
289-
source,
290-
LocalInfo::Boring,
291-
NeedsTemporary::No
292-
)
293-
);
272+
let source = this
273+
.as_operand(block, scope, source, LocalInfo::Boring, NeedsTemporary::No)
274+
.unpack(&mut block);
294275
(source, ty)
295276
};
296277
let from_ty = CastTy::from_ty(ty);
@@ -300,15 +281,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
300281
block.and(Rvalue::Cast(cast_kind, source, expr.ty))
301282
}
302283
ExprKind::PointerCoercion { cast, source } => {
303-
let source = unpack!(
304-
block = this.as_operand(
305-
block,
306-
scope,
307-
source,
308-
LocalInfo::Boring,
309-
NeedsTemporary::No
310-
)
311-
);
284+
let source = this
285+
.as_operand(block, scope, source, LocalInfo::Boring, NeedsTemporary::No)
286+
.unpack(&mut block);
312287
block.and(Rvalue::Cast(CastKind::PointerCoercion(cast), source, expr.ty))
313288
}
314289
ExprKind::Array { ref fields } => {
@@ -344,15 +319,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
344319
.into_iter()
345320
.copied()
346321
.map(|f| {
347-
unpack!(
348-
block = this.as_operand(
349-
block,
350-
scope,
351-
f,
352-
LocalInfo::Boring,
353-
NeedsTemporary::Maybe
354-
)
355-
)
322+
this.as_operand(block, scope, f, LocalInfo::Boring, NeedsTemporary::Maybe)
323+
.unpack(&mut block)
356324
})
357325
.collect();
358326

@@ -365,15 +333,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
365333
.into_iter()
366334
.copied()
367335
.map(|f| {
368-
unpack!(
369-
block = this.as_operand(
370-
block,
371-
scope,
372-
f,
373-
LocalInfo::Boring,
374-
NeedsTemporary::Maybe
375-
)
376-
)
336+
this.as_operand(block, scope, f, LocalInfo::Boring, NeedsTemporary::Maybe)
337+
.unpack(&mut block)
377338
})
378339
.collect();
379340

@@ -401,7 +362,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
401362
// ```
402363
//
403364
for (thir_place, cause, hir_id) in fake_reads.into_iter() {
404-
let place_builder = unpack!(block = this.as_place_builder(block, *thir_place));
365+
let place_builder =
366+
this.as_place_builder(block, *thir_place).unpack(&mut block);
405367

406368
if let Some(mir_place) = place_builder.try_to_place(this) {
407369
this.cfg.push_fake_read(
@@ -429,7 +391,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
429391
// This occurs when capturing by copy/move, while
430392
// by reference captures use as_operand
431393
Some(Category::Place) => {
432-
let place = unpack!(block = this.as_place(block, upvar));
394+
let place = this.as_place(block, upvar).unpack(&mut block);
433395
this.consume_by_copy_or_move(place)
434396
}
435397
_ => {
@@ -442,26 +404,24 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
442404
borrow_kind:
443405
BorrowKind::Mut { kind: MutBorrowKind::Default },
444406
arg,
445-
} => unpack!(
446-
block = this.limit_capture_mutability(
407+
} => this
408+
.limit_capture_mutability(
447409
upvar_expr.span,
448410
upvar_expr.ty,
449411
scope,
450412
block,
451413
arg,
452414
)
453-
),
454-
_ => {
455-
unpack!(
456-
block = this.as_operand(
457-
block,
458-
scope,
459-
upvar,
460-
LocalInfo::Boring,
461-
NeedsTemporary::Maybe
462-
)
415+
.unpack(&mut block),
416+
_ => this
417+
.as_operand(
418+
block,
419+
scope,
420+
upvar,
421+
LocalInfo::Boring,
422+
NeedsTemporary::Maybe,
463423
)
464-
}
424+
.unpack(&mut block),
465425
}
466426
}
467427
}
@@ -536,15 +496,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
536496
Category::of(&expr.kind),
537497
Some(Category::Rvalue(RvalueFunc::AsRvalue) | Category::Constant)
538498
));
539-
let operand = unpack!(
540-
block = this.as_operand(
541-
block,
542-
scope,
543-
expr_id,
544-
LocalInfo::Boring,
545-
NeedsTemporary::No,
546-
)
547-
);
499+
let operand = this
500+
.as_operand(block, scope, expr_id, LocalInfo::Boring, NeedsTemporary::No)
501+
.unpack(&mut block);
548502
block.and(Rvalue::Use(operand))
549503
}
550504
}
@@ -716,9 +670,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
716670
// Repeating a const does nothing
717671
} else {
718672
// For a non-const, we may need to generate an appropriate `Drop`
719-
let value_operand = unpack!(
720-
block = this.as_operand(block, scope, value, LocalInfo::Boring, NeedsTemporary::No)
721-
);
673+
let value_operand = this
674+
.as_operand(block, scope, value, LocalInfo::Boring, NeedsTemporary::No)
675+
.unpack(&mut block);
722676
if let Operand::Move(to_drop) = value_operand {
723677
let success = this.cfg.start_new_block();
724678
this.cfg.terminate(
@@ -754,7 +708,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
754708

755709
this.cfg.push(block, Statement { source_info, kind: StatementKind::StorageLive(temp) });
756710

757-
let arg_place_builder = unpack!(block = this.as_place_builder(block, arg));
711+
let arg_place_builder = this.as_place_builder(block, arg).unpack(&mut block);
758712

759713
let mutability = match arg_place_builder.base() {
760714
// We are capturing a path that starts off a local variable in the parent.

0 commit comments

Comments
 (0)