From 314e7238cf5f5fa6030035814193df455d337ad7 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 12 Apr 2020 10:32:36 +0200 Subject: [PATCH] avoid a bunch of as_ref/as_mut --- src/bin/cargo-miri.rs | 14 +++++++------- src/machine.rs | 12 ++++++------ src/shims/panic.rs | 2 +- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/bin/cargo-miri.rs b/src/bin/cargo-miri.rs index dfb5a5a9891..04020009c69 100644 --- a/src/bin/cargo-miri.rs +++ b/src/bin/cargo-miri.rs @@ -115,7 +115,7 @@ fn list_targets() -> impl Iterator { get_arg_flag_value("--manifest-path").map(|m| Path::new(&m).canonicalize().unwrap()); let mut cmd = cargo_metadata::MetadataCommand::new(); - if let Some(manifest_path) = manifest_path.as_ref() { + if let Some(manifest_path) = &manifest_path { cmd.manifest_path(manifest_path); } let mut metadata = if let Ok(metadata) = cmd.exec() { @@ -131,7 +131,7 @@ fn list_targets() -> impl Iterator { .iter() .position(|package| { let package_manifest_path = Path::new(&package.manifest_path); - if let Some(manifest_path) = manifest_path.as_ref() { + if let Some(manifest_path) = &manifest_path { package_manifest_path == manifest_path } else { let current_dir = current_dir.as_ref().expect("could not read current directory"); @@ -368,8 +368,8 @@ fn setup(ask_user: bool) { command.env("XARGO_HOME", &dir); command.env("XARGO_RUST_SRC", &rust_src); // Handle target flag. - if let Some(target) = target.as_ref() { - command.arg("--target").arg(&target); + if let Some(target) = &target { + command.arg("--target").arg(target); } // Finally run it! if command.status().expect("failed to run xargo").success().not() { @@ -379,7 +379,7 @@ fn setup(ask_user: bool) { // That should be it! But we need to figure out where xargo built stuff. // Unfortunately, it puts things into a different directory when the // architecture matches the host. - let is_host = match target.as_ref() { + let is_host = match &target { None => true, Some(target) => target == &rustc_version::version_meta().unwrap().host, }; @@ -404,12 +404,12 @@ fn main() { return; } - if let Some("miri") = std::env::args().nth(1).as_ref().map(AsRef::as_ref) { + if let Some("miri") = std::env::args().nth(1).as_deref() { // This arm is for when `cargo miri` is called. We call `cargo check` for each applicable target, // but with the `RUSTC` env var set to the `cargo-miri` binary so that we come back in the other branch, // and dispatch the invocations to `rustc` and `miri`, respectively. in_cargo_miri(); - } else if let Some("rustc") = std::env::args().nth(1).as_ref().map(AsRef::as_ref) { + } else if let Some("rustc") = std::env::args().nth(1).as_deref() { // This arm is executed when `cargo-miri` runs `cargo check` with the `RUSTC_WRAPPER` env var set to itself: // dependencies get dispatched to `rustc`, the final test/binary to `miri`. inside_cargo_rustc(); diff --git a/src/machine.rs b/src/machine.rs index 612f1bb328c..72635f7bf57 100644 --- a/src/machine.rs +++ b/src/machine.rs @@ -429,7 +429,7 @@ fn init_allocation_extra<'b>( let kind = kind.expect("we set our STATIC_KIND so this cannot be None"); let alloc = alloc.into_owned(); let (stacks, base_tag) = - if let Some(stacked_borrows) = memory_extra.stacked_borrows.as_ref() { + if let Some(stacked_borrows) = &memory_extra.stacked_borrows { let (stacks, base_tag) = Stacks::new_allocation(id, alloc.size, Rc::clone(stacked_borrows), kind); (Some(stacks), base_tag) @@ -440,7 +440,7 @@ fn init_allocation_extra<'b>( let mut stacked_borrows = memory_extra.stacked_borrows.as_ref().map(|sb| sb.borrow_mut()); let alloc: Allocation = alloc.with_tags_and_extra( |alloc| { - if let Some(stacked_borrows) = stacked_borrows.as_mut() { + if let Some(stacked_borrows) = &mut stacked_borrows { // Only globals may already contain pointers at this point assert_eq!(kind, MiriMemoryKind::Global.into()); stacked_borrows.global_base_ptr(alloc) @@ -455,7 +455,7 @@ fn init_allocation_extra<'b>( #[inline(always)] fn tag_global_base_pointer(memory_extra: &MemoryExtra, id: AllocId) -> Self::PointerTag { - if let Some(stacked_borrows) = memory_extra.stacked_borrows.as_ref() { + if let Some(stacked_borrows) = &memory_extra.stacked_borrows { stacked_borrows.borrow_mut().global_base_ptr(id) } else { Tag::Untagged @@ -518,7 +518,7 @@ fn memory_read<'tcx>( ptr: Pointer, size: Size, ) -> InterpResult<'tcx> { - if let Some(stacked_borrows) = alloc.extra.stacked_borrows.as_ref() { + if let Some(stacked_borrows) = &alloc.extra.stacked_borrows { stacked_borrows.memory_read(ptr, size) } else { Ok(()) @@ -531,7 +531,7 @@ fn memory_written<'tcx>( ptr: Pointer, size: Size, ) -> InterpResult<'tcx> { - if let Some(stacked_borrows) = alloc.extra.stacked_borrows.as_mut() { + if let Some(stacked_borrows) = &mut alloc.extra.stacked_borrows { stacked_borrows.memory_written(ptr, size) } else { Ok(()) @@ -544,7 +544,7 @@ fn memory_deallocated<'tcx>( ptr: Pointer, size: Size, ) -> InterpResult<'tcx> { - if let Some(stacked_borrows) = alloc.extra.stacked_borrows.as_mut() { + if let Some(stacked_borrows) = &mut alloc.extra.stacked_borrows { stacked_borrows.memory_deallocated(ptr, size) } else { Ok(()) diff --git a/src/shims/panic.rs b/src/shims/panic.rs index 281fe1e671b..1aec236a533 100644 --- a/src/shims/panic.rs +++ b/src/shims/panic.rs @@ -123,7 +123,7 @@ fn handle_stack_pop( let this = self.eval_context_mut(); trace!("handle_stack_pop(extra = {:?}, unwinding = {})", extra, unwinding); - if let Some(stacked_borrows) = this.memory.extra.stacked_borrows.as_ref() { + if let Some(stacked_borrows) = &this.memory.extra.stacked_borrows { stacked_borrows.borrow_mut().end_call(extra.call_id); } -- 2.44.0