Skip to content

Commit d5f8ddf

Browse files
committed
use deref_patterns in rustc_mir_transform
1 parent 8d2116e commit d5f8ddf

30 files changed

Lines changed: 114 additions & 119 deletions

compiler/rustc_mir_transform/src/check_const_item_mutation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ impl<'tcx> ConstMutationChecker<'_, 'tcx> {
9595

9696
impl<'tcx> Visitor<'tcx> for ConstMutationChecker<'_, 'tcx> {
9797
fn visit_statement(&mut self, stmt: &Statement<'tcx>, loc: Location) {
98-
if let StatementKind::Assign(box (lhs, _)) = &stmt.kind {
98+
if let StatementKind::Assign((lhs, _)) = &stmt.kind {
9999
// Check for assignment to fields of a constant
100100
// Assigning directly to a constant (e.g. `FOO = true;`) is a hard error,
101101
// so emitting a lint would be redundant.

compiler/rustc_mir_transform/src/cleanup_post_borrowck.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ impl<'tcx> crate::MirPass<'tcx> for CleanupPostBorrowck {
3131
for statement in basic_block.statements.iter_mut() {
3232
match statement.kind {
3333
StatementKind::AscribeUserType(..)
34-
| StatementKind::Assign(box (_, Rvalue::Ref(_, BorrowKind::Fake(_), _)))
34+
| StatementKind::Assign((_, Rvalue::Ref(_, BorrowKind::Fake(_), _)))
3535
| StatementKind::Coverage(
3636
// These kinds of coverage statements are markers inserted during
3737
// MIR building, and are not needed after InstrumentCoverage.
@@ -41,7 +41,7 @@ impl<'tcx> crate::MirPass<'tcx> for CleanupPostBorrowck {
4141
| StatementKind::BackwardIncompatibleDropHint { .. } => {
4242
statement.make_nop(true)
4343
}
44-
StatementKind::Assign(box (
44+
StatementKind::Assign((
4545
_,
4646
Rvalue::Cast(
4747
ref mut cast_kind @ CastKind::PointerCoercion(

compiler/rustc_mir_transform/src/copy_prop.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ impl<'tcx> MutVisitor<'tcx> for Replacer<'_, 'tcx> {
151151
self.super_statement(stmt, loc);
152152

153153
// Do not leave tautological assignments around.
154-
if let StatementKind::Assign(box (lhs, ref rhs)) = stmt.kind
154+
if let StatementKind::Assign((lhs, ref rhs)) = stmt.kind
155155
&& let Rvalue::Use(Operand::Copy(rhs) | Operand::Move(rhs), _) = *rhs
156156
&& lhs == rhs
157157
{

compiler/rustc_mir_transform/src/coroutine.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -997,12 +997,10 @@ fn compute_layout<'tcx>(
997997
let ignore_for_traits = match decl.local_info {
998998
// Do not include raw pointers created from accessing `static` items, as those could
999999
// well be re-created by another access to the same static.
1000-
ClearCrossCrate::Set(box LocalInfo::StaticRef { is_thread_local, .. }) => {
1001-
!is_thread_local
1002-
}
1000+
ClearCrossCrate::Set(LocalInfo::StaticRef { is_thread_local, .. }) => !is_thread_local,
10031001
// Fake borrows are only read by fake reads, so do not have any reality in
10041002
// post-analysis MIR.
1005-
ClearCrossCrate::Set(box LocalInfo::FakeBorrow) => true,
1003+
ClearCrossCrate::Set(LocalInfo::FakeBorrow) => true,
10061004
_ => false,
10071005
};
10081006
let decl =
@@ -1747,7 +1745,7 @@ impl<'tcx> Visitor<'tcx> for EnsureCoroutineFieldAssignmentsNeverAlias<'_> {
17471745

17481746
fn visit_statement(&mut self, statement: &Statement<'tcx>, location: Location) {
17491747
match &statement.kind {
1750-
StatementKind::Assign(box (lhs, rhs)) => {
1748+
StatementKind::Assign((lhs, rhs)) => {
17511749
self.check_assigned_place(*lhs, |this| this.visit_rvalue(rhs, location));
17521750
}
17531751

compiler/rustc_mir_transform/src/coroutine/by_move_body.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ impl<'tcx> MutVisitor<'tcx> for MakeByMoveBody<'tcx> {
346346
// here at all since they're fully a MIR borrowck artifact, and we
347347
// don't need to borrowck by-move MIR bodies. But it's best to preserve
348348
// as much as we can between these two bodies :)
349-
if let mir::StatementKind::Assign(box (_, rvalue)) = &statement.kind
349+
if let mir::StatementKind::Assign((_, rvalue)) = &statement.kind
350350
&& let mir::Rvalue::Ref(_, mir::BorrowKind::Fake(mir::FakeBorrowKind::Shallow), place) =
351351
rvalue
352352
&& let mir::PlaceRef {

compiler/rustc_mir_transform/src/coverage/from_mir.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ fn filtered_statement_span(statement: &Statement<'_>) -> Option<Span> {
8080
// and `_1` is the `Place` for `somenum`.
8181
//
8282
// If and when the Issue is resolved, remove this special case match pattern:
83-
StatementKind::FakeRead(box (FakeReadCause::ForGuardBinding, _)) => None,
83+
StatementKind::FakeRead((FakeReadCause::ForGuardBinding, _)) => None,
8484

8585
// Retain spans from most other statements.
8686
StatementKind::FakeRead(_)

compiler/rustc_mir_transform/src/dataflow_const_prop.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,13 @@ impl<'a, 'tcx> ConstAnalysis<'a, 'tcx> {
164164

165165
fn handle_statement(&self, statement: &Statement<'tcx>, state: &mut State<FlatSet<Scalar>>) {
166166
match &statement.kind {
167-
StatementKind::Assign(box (place, rvalue)) => {
167+
StatementKind::Assign((place, rvalue)) => {
168168
self.handle_assign(*place, rvalue, state);
169169
}
170-
StatementKind::SetDiscriminant { box place, variant_index } => {
171-
self.handle_set_discriminant(*place, *variant_index, state);
170+
StatementKind::SetDiscriminant { place, variant_index } => {
171+
self.handle_set_discriminant(**place, *variant_index, state);
172172
}
173-
StatementKind::Intrinsic(box intrinsic) => {
173+
StatementKind::Intrinsic(intrinsic) => {
174174
self.handle_intrinsic(intrinsic);
175175
}
176176
StatementKind::StorageLive(local) | StatementKind::StorageDead(local) => {
@@ -214,7 +214,7 @@ impl<'a, 'tcx> ConstAnalysis<'a, 'tcx> {
214214
) -> ValueOrPlace<FlatSet<Scalar>> {
215215
match operand {
216216
Operand::RuntimeChecks(_) => ValueOrPlace::TOP,
217-
Operand::Constant(box constant) => {
217+
Operand::Constant(constant) => {
218218
ValueOrPlace::Value(self.handle_constant(constant, state))
219219
}
220220
Operand::Copy(place) | Operand::Move(place) => {
@@ -352,7 +352,7 @@ impl<'a, 'tcx> ConstAnalysis<'a, 'tcx> {
352352
}
353353
}
354354
}
355-
Rvalue::BinaryOp(op, box (left, right)) if op.is_overflowing() => {
355+
Rvalue::BinaryOp(op, (left, right)) if op.is_overflowing() => {
356356
// Flood everything now, so we can use `insert_value_idx` directly later.
357357
state.flood(target.as_ref(), &self.map);
358358

@@ -442,7 +442,7 @@ impl<'a, 'tcx> ConstAnalysis<'a, 'tcx> {
442442
FlatSet::Top => FlatSet::Top,
443443
}
444444
}
445-
Rvalue::BinaryOp(op, box (left, right)) if !op.is_overflowing() => {
445+
Rvalue::BinaryOp(op, (left, right)) if !op.is_overflowing() => {
446446
// Overflows must be ignored here.
447447
// The overflowing operators are handled in `handle_assign`.
448448
let (val, _overflow) = self.binary_op(state, *op, left, right);
@@ -546,7 +546,7 @@ impl<'a, 'tcx> ConstAnalysis<'a, 'tcx> {
546546
self.assign_constant(state, place, op, rhs.projection);
547547
}
548548
}
549-
Operand::Constant(box constant) => {
549+
Operand::Constant(constant) => {
550550
if let Some(constant) = self
551551
.ecx
552552
.borrow()
@@ -956,7 +956,7 @@ impl<'tcx> ResultsVisitor<'tcx, ConstAnalysis<'_, 'tcx>> for Collector<'_, 'tcx>
956956
location: Location,
957957
) {
958958
match &statement.kind {
959-
StatementKind::Assign(box (_, rvalue)) => {
959+
StatementKind::Assign((_, rvalue)) => {
960960
OperandCollector {
961961
state,
962962
visitor: self,
@@ -978,10 +978,10 @@ impl<'tcx> ResultsVisitor<'tcx, ConstAnalysis<'_, 'tcx>> for Collector<'_, 'tcx>
978978
location: Location,
979979
) {
980980
match statement.kind {
981-
StatementKind::Assign(box (_, Rvalue::Use(Operand::Constant(_), _))) => {
981+
StatementKind::Assign((_, Rvalue::Use(Operand::Constant(_), _))) => {
982982
// Don't overwrite the assignment if it already uses a constant (to keep the span).
983983
}
984-
StatementKind::Assign(box (place, _)) => {
984+
StatementKind::Assign((place, _)) => {
985985
if let Some(value) = self.try_make_constant(
986986
&mut analysis.ecx.borrow_mut(),
987987
place,
@@ -1020,7 +1020,7 @@ impl<'tcx> MutVisitor<'tcx> for Patch<'tcx> {
10201020
fn visit_statement(&mut self, statement: &mut Statement<'tcx>, location: Location) {
10211021
if let Some(value) = self.assignments.get(&location) {
10221022
match &mut statement.kind {
1023-
StatementKind::Assign(box (_, rvalue)) => {
1023+
StatementKind::Assign((_, rvalue)) => {
10241024
let old_retag = match rvalue {
10251025
Rvalue::Use(_, retag) => *retag,
10261026
_ => WithRetag::Yes,

compiler/rustc_mir_transform/src/dest_prop.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ impl<'tcx> MutVisitor<'tcx> for Merger<'tcx> {
282282
};
283283
self.super_statement(statement, location);
284284
match &statement.kind {
285-
StatementKind::Assign(box (dest, rvalue)) => {
285+
StatementKind::Assign((dest, rvalue)) => {
286286
match rvalue {
287287
Rvalue::Use(Operand::Copy(place) | Operand::Move(place), _) => {
288288
// These might've been turned into self-assignments by the replacement
@@ -396,10 +396,8 @@ struct FindAssignments<'a, 'tcx> {
396396

397397
impl<'tcx> Visitor<'tcx> for FindAssignments<'_, 'tcx> {
398398
fn visit_statement(&mut self, statement: &Statement<'tcx>, _: Location) {
399-
if let StatementKind::Assign(box (
400-
lhs,
401-
Rvalue::Use(Operand::Copy(rhs) | Operand::Move(rhs), _),
402-
)) = &statement.kind
399+
if let StatementKind::Assign((lhs, Rvalue::Use(Operand::Copy(rhs) | Operand::Move(rhs), _))) =
400+
&statement.kind
403401
&& let Some(src) = lhs.as_local()
404402
&& let Some(dest) = rhs.as_local()
405403
{
@@ -571,7 +569,7 @@ fn save_as_intervals<'tcx>(
571569
// We make an exception for simple assignments `_a.stuff = {copy|move} _b.stuff`,
572570
// as marking `_b` live here would prevent unification.
573571
let is_simple_assignment = match stmt.kind {
574-
StatementKind::Assign(box (
572+
StatementKind::Assign((
575573
lhs,
576574
Rvalue::CopyForDeref(rhs)
577575
| Rvalue::Use(Operand::Copy(rhs) | Operand::Move(rhs), _),

compiler/rustc_mir_transform/src/early_otherwise_branch.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,7 @@ fn evaluate_candidate<'tcx>(
303303
// ```
304304
let [
305305
Statement {
306-
kind: StatementKind::Assign(box (_, Rvalue::Discriminant(child_place))),
307-
..
306+
kind: StatementKind::Assign((_, Rvalue::Discriminant(child_place))), ..
308307
},
309308
] = bbs[child].statements.as_slice()
310309
else {
@@ -368,8 +367,7 @@ fn verify_candidate_branch<'tcx>(
368367
return false;
369368
};
370369
// The statement must assign the discriminant of `place`.
371-
let StatementKind::Assign(box (discr_place, Rvalue::Discriminant(from_place))) =
372-
statement.kind
370+
let StatementKind::Assign((discr_place, Rvalue::Discriminant(from_place))) = statement.kind
373371
else {
374372
return false;
375373
};

compiler/rustc_mir_transform/src/gvn.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,7 +1101,7 @@ impl<'body, 'a, 'tcx> VnState<'body, 'a, 'tcx> {
11011101
Rvalue::Cast(ref mut kind, ref mut value, to) => {
11021102
return self.simplify_cast(kind, value, to, location);
11031103
}
1104-
Rvalue::BinaryOp(op, box (ref mut lhs, ref mut rhs)) => {
1104+
Rvalue::BinaryOp(op, (ref mut lhs, ref mut rhs)) => {
11051105
return self.simplify_binary(op, lhs, rhs, location);
11061106
}
11071107
Rvalue::UnaryOp(op, ref mut arg_op) => {
@@ -1200,7 +1200,7 @@ impl<'body, 'a, 'tcx> VnState<'body, 'a, 'tcx> {
12001200
let tcx = self.tcx;
12011201
let ty = rvalue.ty(self.local_decls, tcx);
12021202

1203-
let Rvalue::Aggregate(box ref kind, ref mut field_ops) = *rvalue else { bug!() };
1203+
let Rvalue::Aggregate(ref kind, ref mut field_ops) = *rvalue else { bug!() };
12041204

12051205
if field_ops.is_empty() {
12061206
let is_zst = match *kind {

0 commit comments

Comments
 (0)