Skip to content

Commit 1d9e91e

Browse files
committed
Replace unneeded use of ref in favor of "match ergonomics"
1 parent e1068cf commit 1d9e91e

File tree

12 files changed

+219
-237
lines changed

12 files changed

+219
-237
lines changed

src/shims/backtrace.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
1515
dest: &PlaceTy<'tcx, Tag>,
1616
) -> InterpResult<'tcx> {
1717
let this = self.eval_context_mut();
18-
let &[ref flags] = this.check_shim(abi, Abi::Rust, link_name, args)?;
18+
let [flags] = this.check_shim(abi, Abi::Rust, link_name, args)?;
1919

2020
let flags = this.read_scalar(flags)?.to_u64()?;
2121
if flags != 0 {
@@ -77,7 +77,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
7777
// storage for pointers is allocated by miri
7878
// deallocating the slice is undefined behavior with a custom global allocator
7979
0 => {
80-
let &[_flags] = this.check_shim(abi, Abi::Rust, link_name, args)?;
80+
let [_flags] = this.check_shim(abi, Abi::Rust, link_name, args)?;
8181

8282
let alloc = this.allocate(array_layout, MiriMemoryKind::Rust.into())?;
8383

@@ -95,7 +95,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
9595
}
9696
// storage for pointers is allocated by the caller
9797
1 => {
98-
let &[_flags, ref buf] = this.check_shim(abi, Abi::Rust, link_name, args)?;
98+
let [_flags, buf] = this.check_shim(abi, Abi::Rust, link_name, args)?;
9999

100100
let buf_place = this.deref_operand(buf)?;
101101

@@ -150,7 +150,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
150150
dest: &PlaceTy<'tcx, Tag>,
151151
) -> InterpResult<'tcx> {
152152
let this = self.eval_context_mut();
153-
let &[ref ptr, ref flags] = this.check_shim(abi, Abi::Rust, link_name, args)?;
153+
let [ptr, flags] = this.check_shim(abi, Abi::Rust, link_name, args)?;
154154

155155
let flags = this.read_scalar(flags)?.to_u64()?;
156156

@@ -233,7 +233,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
233233
) -> InterpResult<'tcx> {
234234
let this = self.eval_context_mut();
235235

236-
let &[ref ptr, ref flags, ref name_ptr, ref filename_ptr] =
236+
let [ptr, flags, name_ptr, filename_ptr] =
237237
this.check_shim(abi, Abi::Rust, link_name, args)?;
238238

239239
let flags = this.read_scalar(flags)?.to_u64()?;

src/shims/foreign_items.rs

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -274,14 +274,13 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
274274
} else {
275275
Abi::System { unwind: false }
276276
};
277-
let &[ref code] = this.check_shim(abi, exp_abi, link_name, args)?;
277+
let [code] = this.check_shim(abi, exp_abi, link_name, args)?;
278278
// it's really u32 for ExitProcess, but we have to put it into the `Exit` variant anyway
279279
let code = this.read_scalar(code)?.to_i32()?;
280280
throw_machine_stop!(TerminationInfo::Exit(code.into()));
281281
}
282282
"abort" => {
283-
let &[] =
284-
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
283+
let [] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
285284
throw_machine_stop!(TerminationInfo::Abort(
286285
"the program aborted execution".to_owned()
287286
))
@@ -367,7 +366,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
367366
match &*link_name.as_str() {
368367
// Miri-specific extern functions
369368
"miri_static_root" => {
370-
let &[ref ptr] = this.check_shim(abi, Abi::Rust, link_name, args)?;
369+
let [ptr] = this.check_shim(abi, Abi::Rust, link_name, args)?;
371370
let ptr = this.read_pointer(ptr)?;
372371
let (alloc_id, offset, _) = this.ptr_get_alloc_id(ptr)?;
373372
if offset != Size::ZERO {
@@ -400,13 +399,13 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
400399

401400
// Standard C allocation
402401
"malloc" => {
403-
let &[ref size] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
402+
let [size] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
404403
let size = this.read_scalar(size)?.to_machine_usize(this)?;
405404
let res = this.malloc(size, /*zero_init:*/ false, MiriMemoryKind::C)?;
406405
this.write_pointer(res, dest)?;
407406
}
408407
"calloc" => {
409-
let &[ref items, ref len] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
408+
let [items, len] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
410409
let items = this.read_scalar(items)?.to_machine_usize(this)?;
411410
let len = this.read_scalar(len)?.to_machine_usize(this)?;
412411
let size =
@@ -415,12 +414,12 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
415414
this.write_pointer(res, dest)?;
416415
}
417416
"free" => {
418-
let &[ref ptr] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
417+
let [ptr] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
419418
let ptr = this.read_pointer(ptr)?;
420419
this.free(ptr, MiriMemoryKind::C)?;
421420
}
422421
"realloc" => {
423-
let &[ref old_ptr, ref new_size] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
422+
let [old_ptr, new_size] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
424423
let old_ptr = this.read_pointer(old_ptr)?;
425424
let new_size = this.read_scalar(new_size)?.to_machine_usize(this)?;
426425
let res = this.realloc(old_ptr, new_size, MiriMemoryKind::C)?;
@@ -429,7 +428,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
429428

430429
// Rust allocation
431430
"__rust_alloc" => {
432-
let &[ref size, ref align] = this.check_shim(abi, Abi::Rust, link_name, args)?;
431+
let [size, align] = this.check_shim(abi, Abi::Rust, link_name, args)?;
433432
let size = this.read_scalar(size)?.to_machine_usize(this)?;
434433
let align = this.read_scalar(align)?.to_machine_usize(this)?;
435434

@@ -446,7 +445,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
446445
});
447446
}
448447
"__rust_alloc_zeroed" => {
449-
let &[ref size, ref align] = this.check_shim(abi, Abi::Rust, link_name, args)?;
448+
let [size, align] = this.check_shim(abi, Abi::Rust, link_name, args)?;
450449
let size = this.read_scalar(size)?.to_machine_usize(this)?;
451450
let align = this.read_scalar(align)?.to_machine_usize(this)?;
452451

@@ -465,7 +464,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
465464
});
466465
}
467466
"__rust_dealloc" => {
468-
let &[ref ptr, ref old_size, ref align] = this.check_shim(abi, Abi::Rust, link_name, args)?;
467+
let [ptr, old_size, align] = this.check_shim(abi, Abi::Rust, link_name, args)?;
469468
let ptr = this.read_pointer(ptr)?;
470469
let old_size = this.read_scalar(old_size)?.to_machine_usize(this)?;
471470
let align = this.read_scalar(align)?.to_machine_usize(this)?;
@@ -480,7 +479,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
480479
});
481480
}
482481
"__rust_realloc" => {
483-
let &[ref ptr, ref old_size, ref align, ref new_size] = this.check_shim(abi, Abi::Rust, link_name, args)?;
482+
let [ptr, old_size, align, new_size] = this.check_shim(abi, Abi::Rust, link_name, args)?;
484483
let ptr = this.read_pointer(ptr)?;
485484
let old_size = this.read_scalar(old_size)?.to_machine_usize(this)?;
486485
let align = this.read_scalar(align)?.to_machine_usize(this)?;
@@ -504,7 +503,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
504503

505504
// C memory handling functions
506505
"memcmp" => {
507-
let &[ref left, ref right, ref n] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
506+
let [left, right, n] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
508507
let left = this.read_pointer(left)?;
509508
let right = this.read_pointer(right)?;
510509
let n = Size::from_bytes(this.read_scalar(n)?.to_machine_usize(this)?);
@@ -524,7 +523,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
524523
this.write_scalar(Scalar::from_i32(result), dest)?;
525524
}
526525
"memrchr" => {
527-
let &[ref ptr, ref val, ref num] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
526+
let [ptr, val, num] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
528527
let ptr = this.read_pointer(ptr)?;
529528
let val = this.read_scalar(val)?.to_i32()? as u8;
530529
let num = this.read_scalar(num)?.to_machine_usize(this)?;
@@ -541,7 +540,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
541540
}
542541
}
543542
"memchr" => {
544-
let &[ref ptr, ref val, ref num] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
543+
let [ptr, val, num] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
545544
let ptr = this.read_pointer(ptr)?;
546545
let val = this.read_scalar(val)?.to_i32()? as u8;
547546
let num = this.read_scalar(num)?.to_machine_usize(this)?;
@@ -557,7 +556,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
557556
}
558557
}
559558
"strlen" => {
560-
let &[ref ptr] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
559+
let [ptr] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
561560
let ptr = this.read_pointer(ptr)?;
562561
let n = this.read_c_str(ptr)?.len();
563562
this.write_scalar(Scalar::from_machine_usize(u64::try_from(n).unwrap(), this), dest)?;
@@ -573,7 +572,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
573572
| "asinf"
574573
| "atanf"
575574
=> {
576-
let &[ref f] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
575+
let [f] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
577576
// FIXME: Using host floats.
578577
let f = f32::from_bits(this.read_scalar(f)?.to_u32()?);
579578
let f = match &*link_name.as_str() {
@@ -593,7 +592,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
593592
| "hypotf"
594593
| "atan2f"
595594
=> {
596-
let &[ref f1, ref f2] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
595+
let [f1, f2] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
597596
// underscore case for windows, here and below
598597
// (see https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/floating-point-primitives?view=vs-2019)
599598
// FIXME: Using host floats.
@@ -615,7 +614,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
615614
| "asin"
616615
| "atan"
617616
=> {
618-
let &[ref f] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
617+
let [f] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
619618
// FIXME: Using host floats.
620619
let f = f64::from_bits(this.read_scalar(f)?.to_u64()?);
621620
let f = match &*link_name.as_str() {
@@ -635,7 +634,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
635634
| "hypot"
636635
| "atan2"
637636
=> {
638-
let &[ref f1, ref f2] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
637+
let [f1, f2] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
639638
// FIXME: Using host floats.
640639
let f1 = f64::from_bits(this.read_scalar(f1)?.to_u64()?);
641640
let f2 = f64::from_bits(this.read_scalar(f2)?.to_u64()?);
@@ -651,7 +650,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
651650
| "ldexp"
652651
| "scalbn"
653652
=> {
654-
let &[ref x, ref exp] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
653+
let [x, exp] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
655654
// For radix-2 (binary) systems, `ldexp` and `scalbn` are the same.
656655
let x = this.read_scalar(x)?.to_f64()?;
657656
let exp = this.read_scalar(exp)?.to_i32()?;
@@ -673,7 +672,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
673672
// Architecture-specific shims
674673
"llvm.x86.addcarry.64" if this.tcx.sess.target.arch == "x86_64" => {
675674
// Computes u8+u64+u64, returning tuple (u8,u64) comprising the output carry and truncated sum.
676-
let &[ref c_in, ref a, ref b] = this.check_shim(abi, Abi::Unadjusted, link_name, args)?;
675+
let [c_in, a, b] = this.check_shim(abi, Abi::Unadjusted, link_name, args)?;
677676
let c_in = this.read_scalar(c_in)?.to_u8()?;
678677
let a = this.read_scalar(a)?.to_u64()?;
679678
let b = this.read_scalar(b)?.to_u64()?;
@@ -687,11 +686,11 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
687686
this.write_scalar(Scalar::from_u64(sum), &sum_field)?;
688687
}
689688
"llvm.x86.sse2.pause" if this.tcx.sess.target.arch == "x86" || this.tcx.sess.target.arch == "x86_64" => {
690-
let &[] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
689+
let [] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
691690
this.yield_active_thread();
692691
}
693692
"llvm.aarch64.isb" if this.tcx.sess.target.arch == "aarch64" => {
694-
let &[ref arg] = this.check_shim(abi, Abi::Unadjusted, link_name, args)?;
693+
let [arg] = this.check_shim(abi, Abi::Unadjusted, link_name, args)?;
695694
let arg = this.read_scalar(arg)?.to_i32()?;
696695
match arg {
697696
15 => { // SY ("full system scope")

0 commit comments

Comments
 (0)