From 175763a953ebd753f171f0f4f6f9ed941f378585 Mon Sep 17 00:00:00 2001 From: Jim Blandy Date: Mon, 30 Jul 2018 03:07:35 -0700 Subject: [PATCH] Avoid gratuitous use of std::mem::replace. (#1005) Either these calls to `replace` are unnecessary, or I'm going to learn something I really need to know. The only way difference I can see between `replace` and a simple assignment is that `replace` returns ownership of the value to the caller, so the old value is dropped after the new value has been put in place. But if Rust lets us assign to or move from a variable, that means that no other alias can observe that happening --- which I think means that the drop can't possibly care whether it occurs before or after the move. --- examples/src/bin/teapot.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/src/bin/teapot.rs b/examples/src/bin/teapot.rs index d6d49fd7..5ccf9da4 100644 --- a/examples/src/bin/teapot.rs +++ b/examples/src/bin/teapot.rs @@ -155,8 +155,8 @@ fn main() { Err(err) => panic!("{:?}", err) }; - std::mem::replace(&mut swapchain, new_swapchain); - std::mem::replace(&mut images, new_images); + swapchain = new_swapchain; + images = new_images; let new_depth_buffer = vulkano::image::attachment::AttachmentImage::transient(device.clone(), dimensions, vulkano::format::D16Unorm).unwrap(); std::mem::replace(&mut depth_buffer, new_depth_buffer);