]> git.lizzy.rs Git - rust.git/commitdiff
avoid a bunch of as_ref/as_mut
authorRalf Jung <post@ralfj.de>
Sun, 12 Apr 2020 08:32:36 +0000 (10:32 +0200)
committerRalf Jung <post@ralfj.de>
Sun, 12 Apr 2020 08:32:36 +0000 (10:32 +0200)
src/bin/cargo-miri.rs
src/machine.rs
src/shims/panic.rs

index dfb5a5a9891250889c0e1b493fe345b28cb3e15f..04020009c6943c2e8227c181e6e7eaaf2ff495e0 100644 (file)
@@ -115,7 +115,7 @@ fn list_targets() -> impl Iterator<Item = cargo_metadata::Target> {
         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<Item = cargo_metadata::Target> {
         .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();
index 612f1bb328cc49c8760eebd1dc382c07453b71cf..72635f7bf57b0547191a3c098f3656ebd1c6b32e 100644 (file)
@@ -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<Tag, Self::AllocExtra> = 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<Tag>,
         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<Tag>,
         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<Tag>,
         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(())
index 281fe1e671bb440fa748bc81d7233f01b779c245..1aec236a533c7cab817579f99e40631030eebbef 100644 (file)
@@ -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);
         }