Skip to content

Commit 3dca58e

Browse files
committed
rustc_const_eval: remove ref patterns (+some pattern matching imps)
1 parent 85357e3 commit 3dca58e

File tree

14 files changed

+130
-144
lines changed

14 files changed

+130
-144
lines changed

compiler/rustc_const_eval/src/const_eval/error.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,16 @@ impl<'tcx> Into<InterpErrorInfo<'tcx>> for ConstEvalErrKind {
3636
impl fmt::Display for ConstEvalErrKind {
3737
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3838
use self::ConstEvalErrKind::*;
39-
match *self {
39+
match self {
4040
ConstAccessesStatic => write!(f, "constant accesses static"),
4141
ModifiedGlobal => {
4242
write!(f, "modifying a static's initial value from another static's initializer")
4343
}
44-
AssertFailure(ref msg) => write!(f, "{:?}", msg),
44+
AssertFailure(msg) => write!(f, "{:?}", msg),
4545
Panic { msg, line, col, file } => {
4646
write!(f, "the evaluated program panicked at '{}', {}:{}:{}", msg, file, line, col)
4747
}
48-
Abort(ref msg) => write!(f, "{}", msg),
48+
Abort(msg) => write!(f, "{}", msg),
4949
}
5050
}
5151
}

compiler/rustc_const_eval/src/const_eval/eval_queries.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ pub(super) fn op_to_const<'tcx>(
167167
}
168168
};
169169
match immediate {
170-
Left(ref mplace) => to_const_value(mplace),
170+
Left(mplace) => to_const_value(&mplace),
171171
// see comment on `let try_as_immediate` above
172172
Right(imm) => match *imm {
173173
_ if imm.layout.is_zst() => ConstValue::ZeroSized,

compiler/rustc_const_eval/src/const_eval/machine.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
533533
let eval_to_int =
534534
|op| ecx.read_immediate(&ecx.eval_operand(op, None)?).map(|x| x.to_const_int());
535535
let err = match msg {
536-
BoundsCheck { ref len, ref index } => {
536+
BoundsCheck { len, index } => {
537537
let len = eval_to_int(len)?;
538538
let index = eval_to_int(index)?;
539539
BoundsCheck { len, index }

compiler/rustc_const_eval/src/interpret/cast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
347347
let new_vptr = self.get_vtable_ptr(ty, data_b.principal())?;
348348
self.write_immediate(Immediate::new_dyn_trait(old_data, new_vptr, self), dest)
349349
}
350-
(_, &ty::Dynamic(ref data, _, ty::Dyn)) => {
350+
(_, &ty::Dynamic(data, _, ty::Dyn)) => {
351351
// Initial cast from sized to dyn trait
352352
let vtable = self.get_vtable_ptr(src_pointee_ty, data.principal())?;
353353
let ptr = self.read_scalar(src)?;

compiler/rustc_const_eval/src/interpret/intrinsics.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,7 @@ pub(crate) fn eval_nullary_intrinsic<'tcx>(
7979
}
8080
sym::variant_count => match tp_ty.kind() {
8181
// Correctly handles non-monomorphic calls, so there is no need for ensure_monomorphic_enough.
82-
ty::Adt(ref adt, _) => {
83-
ConstValue::from_machine_usize(adt.variants().len() as u64, &tcx)
84-
}
82+
ty::Adt(adt, _) => ConstValue::from_machine_usize(adt.variants().len() as u64, &tcx),
8583
ty::Alias(..) | ty::Param(_) | ty::Placeholder(_) | ty::Infer(_) => {
8684
throw_inval!(TooGeneric)
8785
}

compiler/rustc_const_eval/src/interpret/memory.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -863,7 +863,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> std::fmt::Debug for DumpAllocs<'a,
863863

864864
write!(fmt, "{id:?}")?;
865865
match self.ecx.memory.alloc_map.get(id) {
866-
Some(&(kind, ref alloc)) => {
866+
Some((kind, alloc)) => {
867867
// normal alloc
868868
write!(fmt, " ({}, ", kind)?;
869869
write_allocation_track_relocs(

compiler/rustc_const_eval/src/interpret/operand.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -363,11 +363,11 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
363363
src: &OpTy<'tcx, M::Provenance>,
364364
) -> InterpResult<'tcx, Either<MPlaceTy<'tcx, M::Provenance>, ImmTy<'tcx, M::Provenance>>> {
365365
Ok(match src.as_mplace_or_imm() {
366-
Left(ref mplace) => {
367-
if let Some(val) = self.read_immediate_from_mplace_raw(mplace)? {
366+
Left(mplace) => {
367+
if let Some(val) = self.read_immediate_from_mplace_raw(&mplace)? {
368368
Right(val)
369369
} else {
370-
Left(*mplace)
370+
Left(mplace)
371371
}
372372
}
373373
Right(val) => Right(val),
@@ -533,11 +533,11 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
533533
layout: Option<TyAndLayout<'tcx>>,
534534
) -> InterpResult<'tcx, OpTy<'tcx, M::Provenance>> {
535535
use rustc_middle::mir::Operand::*;
536-
let op = match *mir_op {
536+
let op = match mir_op {
537537
// FIXME: do some more logic on `move` to invalidate the old location
538-
Copy(place) | Move(place) => self.eval_place_to_op(place, layout)?,
538+
&(Copy(place) | Move(place)) => self.eval_place_to_op(place, layout)?,
539539

540-
Constant(ref constant) => {
540+
Constant(constant) => {
541541
let c =
542542
self.subst_from_current_frame_and_normalize_erasing_regions(constant.literal)?;
543543

compiler/rustc_const_eval/src/interpret/projection.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ where
8787
field: usize,
8888
) -> InterpResult<'tcx, OpTy<'tcx, M::Provenance>> {
8989
let base = match base.as_mplace_or_imm() {
90-
Left(ref mplace) => {
90+
Left(mplace) => {
9191
// We can reuse the mplace field computation logic for indirect operands.
92-
let field = self.mplace_field(mplace, field)?;
92+
let field = self.mplace_field(&mplace, field)?;
9393
return Ok(field.into());
9494
}
9595
Right(value) => value,

compiler/rustc_const_eval/src/interpret/step.rs

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
111111
M::retag_place_contents(self, *kind, &dest)?;
112112
}
113113

114-
Intrinsic(box ref intrinsic) => self.emulate_nondiverging_intrinsic(intrinsic)?,
114+
Intrinsic(box intrinsic) => self.emulate_nondiverging_intrinsic(intrinsic)?,
115115

116116
// Statements we do not track.
117117
AscribeUserType(..) => {}
@@ -151,50 +151,50 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
151151
// Also see https://github.com/rust-lang/rust/issues/68364.
152152

153153
use rustc_middle::mir::Rvalue::*;
154-
match *rvalue {
154+
match rvalue {
155155
ThreadLocalRef(did) => {
156-
let ptr = M::thread_local_static_base_pointer(self, did)?;
156+
let ptr = M::thread_local_static_base_pointer(self, *did)?;
157157
self.write_pointer(ptr, &dest)?;
158158
}
159159

160-
Use(ref operand) => {
160+
Use(operand) => {
161161
// Avoid recomputing the layout
162162
let op = self.eval_operand(operand, Some(dest.layout))?;
163163
self.copy_op(&op, &dest, /*allow_transmute*/ false)?;
164164
}
165165

166-
CopyForDeref(ref place) => {
166+
CopyForDeref(place) => {
167167
let op = self.eval_place_to_op(*place, Some(dest.layout))?;
168168
self.copy_op(&op, &dest, /* allow_transmute*/ false)?;
169169
}
170170

171-
BinaryOp(bin_op, box (ref left, ref right)) => {
172-
let layout = binop_left_homogeneous(bin_op).then_some(dest.layout);
171+
BinaryOp(bin_op, box (left, right)) => {
172+
let layout = binop_left_homogeneous(*bin_op).then_some(dest.layout);
173173
let left = self.read_immediate(&self.eval_operand(left, layout)?)?;
174-
let layout = binop_right_homogeneous(bin_op).then_some(left.layout);
174+
let layout = binop_right_homogeneous(*bin_op).then_some(left.layout);
175175
let right = self.read_immediate(&self.eval_operand(right, layout)?)?;
176-
self.binop_ignore_overflow(bin_op, &left, &right, &dest)?;
176+
self.binop_ignore_overflow(*bin_op, &left, &right, &dest)?;
177177
}
178178

179-
CheckedBinaryOp(bin_op, box (ref left, ref right)) => {
179+
CheckedBinaryOp(bin_op, box (left, right)) => {
180180
// Due to the extra boolean in the result, we can never reuse the `dest.layout`.
181181
let left = self.read_immediate(&self.eval_operand(left, None)?)?;
182-
let layout = binop_right_homogeneous(bin_op).then_some(left.layout);
182+
let layout = binop_right_homogeneous(*bin_op).then_some(left.layout);
183183
let right = self.read_immediate(&self.eval_operand(right, layout)?)?;
184184
self.binop_with_overflow(
185-
bin_op, /*force_overflow_checks*/ false, &left, &right, &dest,
185+
*bin_op, /*force_overflow_checks*/ false, &left, &right, &dest,
186186
)?;
187187
}
188188

189-
UnaryOp(un_op, ref operand) => {
189+
UnaryOp(un_op, operand) => {
190190
// The operand always has the same type as the result.
191191
let val = self.read_immediate(&self.eval_operand(operand, Some(dest.layout))?)?;
192-
let val = self.unary_op(un_op, &val)?;
192+
let val = self.unary_op(*un_op, &val)?;
193193
assert_eq!(val.layout, dest.layout, "layout mismatch for result of {:?}", un_op);
194194
self.write_immediate(*val, &dest)?;
195195
}
196196

197-
Aggregate(box ref kind, ref operands) => {
197+
Aggregate(box kind, operands) => {
198198
assert!(matches!(kind, mir::AggregateKind::Array(..)));
199199

200200
for (field_index, operand) in operands.iter().enumerate() {
@@ -204,7 +204,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
204204
}
205205
}
206206

207-
Repeat(ref operand, _) => {
207+
Repeat(operand, _) => {
208208
let src = self.eval_operand(operand, None)?;
209209
assert!(src.layout.is_sized());
210210
let dest = self.force_allocation(&dest)?;
@@ -241,14 +241,14 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
241241
}
242242

243243
Len(place) => {
244-
let src = self.eval_place(place)?;
244+
let src = self.eval_place(*place)?;
245245
let op = self.place_to_op(&src)?;
246246
let len = op.len(self)?;
247247
self.write_scalar(Scalar::from_machine_usize(len, self), &dest)?;
248248
}
249249

250250
Ref(_, borrow_kind, place) => {
251-
let src = self.eval_place(place)?;
251+
let src = self.eval_place(*place)?;
252252
let place = self.force_allocation(&src)?;
253253
let val = ImmTy::from_immediate(place.to_ref(self), dest.layout);
254254
// A fresh reference was created, make sure it gets retagged.
@@ -274,7 +274,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
274274
false
275275
};
276276

277-
let src = self.eval_place(place)?;
277+
let src = self.eval_place(*place)?;
278278
let place = self.force_allocation(&src)?;
279279
let mut val = ImmTy::from_immediate(place.to_ref(self), dest.layout);
280280
if !place_base_raw {
@@ -285,7 +285,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
285285
}
286286

287287
NullaryOp(null_op, ty) => {
288-
let ty = self.subst_from_current_frame_and_normalize_erasing_regions(ty)?;
288+
let ty = self.subst_from_current_frame_and_normalize_erasing_regions(*ty)?;
289289
let layout = self.layout_of(ty)?;
290290
if layout.is_unsized() {
291291
// FIXME: This should be a span_bug (#80742)
@@ -302,21 +302,21 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
302302
self.write_scalar(Scalar::from_machine_usize(val, self), &dest)?;
303303
}
304304

305-
ShallowInitBox(ref operand, _) => {
305+
ShallowInitBox(operand, _) => {
306306
let src = self.eval_operand(operand, None)?;
307307
let v = self.read_immediate(&src)?;
308308
self.write_immediate(*v, &dest)?;
309309
}
310310

311-
Cast(cast_kind, ref operand, cast_ty) => {
311+
Cast(cast_kind, operand, cast_ty) => {
312312
let src = self.eval_operand(operand, None)?;
313313
let cast_ty =
314-
self.subst_from_current_frame_and_normalize_erasing_regions(cast_ty)?;
315-
self.cast(&src, cast_kind, cast_ty, &dest)?;
314+
self.subst_from_current_frame_and_normalize_erasing_regions(*cast_ty)?;
315+
self.cast(&src, *cast_kind, cast_ty, &dest)?;
316316
}
317317

318318
Discriminant(place) => {
319-
let op = self.eval_place_to_op(place, None)?;
319+
let op = self.eval_place_to_op(*place, None)?;
320320
let discr_val = self.read_discriminant(&op)?.0;
321321
self.write_scalar(discr_val, &dest)?;
322322
}

compiler/rustc_const_eval/src/interpret/terminator.rs

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
2222
terminator: &mir::Terminator<'tcx>,
2323
) -> InterpResult<'tcx> {
2424
use rustc_middle::mir::TerminatorKind::*;
25-
match terminator.kind {
25+
match &terminator.kind {
2626
Return => {
2727
self.pop_stack_frame(/* unwinding */ false)?
2828
}
2929

30-
Goto { target } => self.go_to_block(target),
30+
Goto { target } => self.go_to_block(*target),
3131

32-
SwitchInt { ref discr, ref targets } => {
32+
SwitchInt { discr, targets } => {
3333
let discr = self.read_immediate(&self.eval_operand(discr, None)?)?;
3434
trace!("SwitchInt({:?})", *discr);
3535

@@ -55,15 +55,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
5555
self.go_to_block(target_block);
5656
}
5757

58-
Call {
59-
ref func,
60-
ref args,
61-
destination,
62-
target,
63-
ref cleanup,
64-
from_hir_call: _,
65-
fn_span: _,
66-
} => {
58+
Call { func, args, destination, target, cleanup, from_hir_call: _, fn_span: _ } => {
6759
let old_stack = self.frame_idx();
6860
let old_loc = self.frame().loc;
6961
let func = self.eval_operand(func, None)?;
@@ -97,14 +89,14 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
9789
),
9890
};
9991

100-
let destination = self.eval_place(destination)?;
92+
let destination = self.eval_place(*destination)?;
10193
self.eval_fn_call(
10294
fn_val,
10395
(fn_sig.abi, fn_abi),
10496
&args,
10597
with_caller_location,
10698
&destination,
107-
target,
99+
*target,
108100
match (cleanup, fn_abi.can_unwind) {
109101
(Some(cleanup), true) => StackPopUnwind::Cleanup(*cleanup),
110102
(None, true) => StackPopUnwind::Skip,
@@ -118,7 +110,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
118110
}
119111
}
120112

121-
Drop { place, target, unwind } => {
113+
&Drop { place, target, unwind } => {
122114
let frame = self.frame();
123115
let ty = place.ty(&frame.body.local_decls, *self.tcx).ty;
124116
let ty = self.subst_from_frame_and_normalize_erasing_regions(frame, ty)?;
@@ -136,12 +128,12 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
136128
self.drop_in_place(&place, instance, target, unwind)?;
137129
}
138130

139-
Assert { ref cond, expected, ref msg, target, cleanup } => {
131+
Assert { cond, expected, msg, target, cleanup } => {
140132
let cond_val = self.read_scalar(&self.eval_operand(cond, None)?)?.to_bool()?;
141-
if expected == cond_val {
142-
self.go_to_block(target);
133+
if *expected == cond_val {
134+
self.go_to_block(*target);
143135
} else {
144-
M::assert_panic(self, msg, cleanup)?;
136+
M::assert_panic(self, msg, *cleanup)?;
145137
}
146138
}
147139

@@ -174,8 +166,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
174166
terminator.kind
175167
),
176168

177-
InlineAsm { template, ref operands, options, destination, .. } => {
178-
M::eval_inline_asm(self, template, operands, options)?;
169+
InlineAsm { template, operands, options, destination, .. } => {
170+
M::eval_inline_asm(self, template, operands, *options)?;
179171
if options.contains(InlineAsmOptions::NORETURN) {
180172
throw_ub_format!("returned from noreturn inline assembly");
181173
}

0 commit comments

Comments
 (0)