Skip to content

Commit 314e723

Browse files
committed
avoid a bunch of as_ref/as_mut
1 parent 97791a5 commit 314e723

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

src/bin/cargo-miri.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ fn list_targets() -> impl Iterator<Item = cargo_metadata::Target> {
115115
get_arg_flag_value("--manifest-path").map(|m| Path::new(&m).canonicalize().unwrap());
116116

117117
let mut cmd = cargo_metadata::MetadataCommand::new();
118-
if let Some(manifest_path) = manifest_path.as_ref() {
118+
if let Some(manifest_path) = &manifest_path {
119119
cmd.manifest_path(manifest_path);
120120
}
121121
let mut metadata = if let Ok(metadata) = cmd.exec() {
@@ -131,7 +131,7 @@ fn list_targets() -> impl Iterator<Item = cargo_metadata::Target> {
131131
.iter()
132132
.position(|package| {
133133
let package_manifest_path = Path::new(&package.manifest_path);
134-
if let Some(manifest_path) = manifest_path.as_ref() {
134+
if let Some(manifest_path) = &manifest_path {
135135
package_manifest_path == manifest_path
136136
} else {
137137
let current_dir = current_dir.as_ref().expect("could not read current directory");
@@ -368,8 +368,8 @@ path = "lib.rs"
368368
command.env("XARGO_HOME", &dir);
369369
command.env("XARGO_RUST_SRC", &rust_src);
370370
// Handle target flag.
371-
if let Some(target) = target.as_ref() {
372-
command.arg("--target").arg(&target);
371+
if let Some(target) = &target {
372+
command.arg("--target").arg(target);
373373
}
374374
// Finally run it!
375375
if command.status().expect("failed to run xargo").success().not() {
@@ -379,7 +379,7 @@ path = "lib.rs"
379379
// That should be it! But we need to figure out where xargo built stuff.
380380
// Unfortunately, it puts things into a different directory when the
381381
// architecture matches the host.
382-
let is_host = match target.as_ref() {
382+
let is_host = match &target {
383383
None => true,
384384
Some(target) => target == &rustc_version::version_meta().unwrap().host,
385385
};
@@ -404,12 +404,12 @@ fn main() {
404404
return;
405405
}
406406

407-
if let Some("miri") = std::env::args().nth(1).as_ref().map(AsRef::as_ref) {
407+
if let Some("miri") = std::env::args().nth(1).as_deref() {
408408
// This arm is for when `cargo miri` is called. We call `cargo check` for each applicable target,
409409
// but with the `RUSTC` env var set to the `cargo-miri` binary so that we come back in the other branch,
410410
// and dispatch the invocations to `rustc` and `miri`, respectively.
411411
in_cargo_miri();
412-
} else if let Some("rustc") = std::env::args().nth(1).as_ref().map(AsRef::as_ref) {
412+
} else if let Some("rustc") = std::env::args().nth(1).as_deref() {
413413
// This arm is executed when `cargo-miri` runs `cargo check` with the `RUSTC_WRAPPER` env var set to itself:
414414
// dependencies get dispatched to `rustc`, the final test/binary to `miri`.
415415
inside_cargo_rustc();

src/machine.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'tcx> {
429429
let kind = kind.expect("we set our STATIC_KIND so this cannot be None");
430430
let alloc = alloc.into_owned();
431431
let (stacks, base_tag) =
432-
if let Some(stacked_borrows) = memory_extra.stacked_borrows.as_ref() {
432+
if let Some(stacked_borrows) = &memory_extra.stacked_borrows {
433433
let (stacks, base_tag) =
434434
Stacks::new_allocation(id, alloc.size, Rc::clone(stacked_borrows), kind);
435435
(Some(stacks), base_tag)
@@ -440,7 +440,7 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'tcx> {
440440
let mut stacked_borrows = memory_extra.stacked_borrows.as_ref().map(|sb| sb.borrow_mut());
441441
let alloc: Allocation<Tag, Self::AllocExtra> = alloc.with_tags_and_extra(
442442
|alloc| {
443-
if let Some(stacked_borrows) = stacked_borrows.as_mut() {
443+
if let Some(stacked_borrows) = &mut stacked_borrows {
444444
// Only globals may already contain pointers at this point
445445
assert_eq!(kind, MiriMemoryKind::Global.into());
446446
stacked_borrows.global_base_ptr(alloc)
@@ -455,7 +455,7 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'tcx> {
455455

456456
#[inline(always)]
457457
fn tag_global_base_pointer(memory_extra: &MemoryExtra, id: AllocId) -> Self::PointerTag {
458-
if let Some(stacked_borrows) = memory_extra.stacked_borrows.as_ref() {
458+
if let Some(stacked_borrows) = &memory_extra.stacked_borrows {
459459
stacked_borrows.borrow_mut().global_base_ptr(id)
460460
} else {
461461
Tag::Untagged
@@ -518,7 +518,7 @@ impl AllocationExtra<Tag> for AllocExtra {
518518
ptr: Pointer<Tag>,
519519
size: Size,
520520
) -> InterpResult<'tcx> {
521-
if let Some(stacked_borrows) = alloc.extra.stacked_borrows.as_ref() {
521+
if let Some(stacked_borrows) = &alloc.extra.stacked_borrows {
522522
stacked_borrows.memory_read(ptr, size)
523523
} else {
524524
Ok(())
@@ -531,7 +531,7 @@ impl AllocationExtra<Tag> for AllocExtra {
531531
ptr: Pointer<Tag>,
532532
size: Size,
533533
) -> InterpResult<'tcx> {
534-
if let Some(stacked_borrows) = alloc.extra.stacked_borrows.as_mut() {
534+
if let Some(stacked_borrows) = &mut alloc.extra.stacked_borrows {
535535
stacked_borrows.memory_written(ptr, size)
536536
} else {
537537
Ok(())
@@ -544,7 +544,7 @@ impl AllocationExtra<Tag> for AllocExtra {
544544
ptr: Pointer<Tag>,
545545
size: Size,
546546
) -> InterpResult<'tcx> {
547-
if let Some(stacked_borrows) = alloc.extra.stacked_borrows.as_mut() {
547+
if let Some(stacked_borrows) = &mut alloc.extra.stacked_borrows {
548548
stacked_borrows.memory_deallocated(ptr, size)
549549
} else {
550550
Ok(())

src/shims/panic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
123123
let this = self.eval_context_mut();
124124

125125
trace!("handle_stack_pop(extra = {:?}, unwinding = {})", extra, unwinding);
126-
if let Some(stacked_borrows) = this.memory.extra.stacked_borrows.as_ref() {
126+
if let Some(stacked_borrows) = &this.memory.extra.stacked_borrows {
127127
stacked_borrows.borrow_mut().end_call(extra.call_id);
128128
}
129129

0 commit comments

Comments
 (0)