Fix clippy warnings about using if-let over match

The specific lint triggered was
https://rust-lang.github.io/rust-clippy/master/index.html#single_match.
This commit is contained in:
lberrymage 2020-09-25 23:02:51 -08:00
parent 49cf466dc4
commit 41228ef1a4
No known key found for this signature in database
GPG Key ID: CEF3E41247E77E5F
7 changed files with 158 additions and 207 deletions

View File

@ -931,19 +931,16 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
.register_identity(id_in, render_bundle, &mut token);
#[cfg(feature = "trace")]
match device.trace {
Some(ref trace) => {
use crate::device::trace;
let (bundle_guard, _) = hub.render_bundles.read(&mut token);
let bundle = &bundle_guard[id];
let label = desc.label.as_ref().map(|l| l.as_ref());
trace.lock().add(trace::Action::CreateRenderBundle {
id: id.0,
desc: trace::new_render_bundle_encoder_descriptor(label, &bundle.context),
base: BasePass::from_ref(bundle.base.as_ref()),
});
}
None => {}
if let Some(ref trace) = device.trace {
use crate::device::trace;
let (bundle_guard, _) = hub.render_bundles.read(&mut token);
let bundle = &bundle_guard[id];
let label = desc.label.as_ref().map(|l| l.as_ref());
trace.lock().add(trace::Action::CreateRenderBundle {
id: id.0,
desc: trace::new_render_bundle_encoder_descriptor(label, &bundle.context),
base: BasePass::from_ref(bundle.base.as_ref()),
});
}
device

View File

@ -220,13 +220,10 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
let raw = cmd_buf.raw.last_mut().unwrap();
#[cfg(feature = "trace")]
match cmd_buf.commands {
Some(ref mut list) => {
list.push(crate::device::trace::Command::RunComputePass {
base: BasePass::from_ref(base),
});
}
None => {}
if let Some(ref mut list) = cmd_buf.commands {
list.push(crate::device::trace::Command::RunComputePass {
base: BasePass::from_ref(base),
});
}
let (_, mut token) = hub.render_bundles.read(&mut token);

View File

@ -434,15 +434,12 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
let mut raw = device.cmd_allocator.extend(cmd_buf);
#[cfg(feature = "trace")]
match cmd_buf.commands {
Some(ref mut list) => {
list.push(crate::device::trace::Command::RunRenderPass {
base: BasePass::from_ref(base),
target_colors: color_attachments.iter().cloned().collect(),
target_depth_stencil: depth_stencil_attachment.cloned(),
});
}
None => {}
if let Some(ref mut list) = cmd_buf.commands {
list.push(crate::device::trace::Command::RunRenderPass {
base: BasePass::from_ref(base),
target_colors: color_attachments.iter().cloned().collect(),
target_depth_stencil: depth_stencil_attachment.cloned(),
});
}
unsafe {

View File

@ -315,15 +315,14 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
let mut barriers = Vec::new();
#[cfg(feature = "trace")]
match cmd_buf.commands {
Some(ref mut list) => list.push(TraceCommand::CopyBufferToBuffer {
if let Some(ref mut list) = cmd_buf.commands {
list.push(TraceCommand::CopyBufferToBuffer {
src: source,
src_offset: source_offset,
dst: destination,
dst_offset: destination_offset,
size,
}),
None => (),
});
}
let (src_buffer, src_pending) = cmd_buf
@ -416,13 +415,12 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
texture_copy_view_to_hal(destination, copy_size, &*texture_guard)?;
#[cfg(feature = "trace")]
match cmd_buf.commands {
Some(ref mut list) => list.push(TraceCommand::CopyBufferToTexture {
if let Some(ref mut list) = cmd_buf.commands {
list.push(TraceCommand::CopyBufferToTexture {
src: source.clone(),
dst: destination.clone(),
size: *copy_size,
}),
None => (),
});
}
if copy_size.width == 0 || copy_size.height == 0 || copy_size.width == 0 {
@ -535,13 +533,12 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
texture_copy_view_to_hal(source, copy_size, &*texture_guard)?;
#[cfg(feature = "trace")]
match cmd_buf.commands {
Some(ref mut list) => list.push(TraceCommand::CopyTextureToBuffer {
if let Some(ref mut list) = cmd_buf.commands {
list.push(TraceCommand::CopyTextureToBuffer {
src: source.clone(),
dst: destination.clone(),
size: *copy_size,
}),
None => (),
});
}
if copy_size.width == 0 || copy_size.height == 0 || copy_size.width == 0 {
@ -663,13 +660,12 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
}
#[cfg(feature = "trace")]
match cmd_buf.commands {
Some(ref mut list) => list.push(TraceCommand::CopyTextureToTexture {
if let Some(ref mut list) = cmd_buf.commands {
list.push(TraceCommand::CopyTextureToTexture {
src: source.clone(),
dst: destination.clone(),
size: *copy_size,
}),
None => (),
});
}
if copy_size.width == 0 || copy_size.height == 0 || copy_size.width == 0 {

View File

@ -1051,17 +1051,14 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
let id = hub.buffers.register_identity(id_in, buffer, &mut token);
tracing::info!("Created buffer {:?} with {:?}", id, desc);
#[cfg(feature = "trace")]
match device.trace {
Some(ref trace) => {
let mut desc = desc.clone();
let mapped_at_creation = mem::replace(&mut desc.mapped_at_creation, false);
if mapped_at_creation && !desc.usage.contains(wgt::BufferUsage::MAP_WRITE) {
desc.usage |= wgt::BufferUsage::COPY_DST;
}
trace.lock().add(trace::Action::CreateBuffer(id.0, desc))
if let Some(ref trace) = device.trace {
let mut desc = desc.clone();
let mapped_at_creation = mem::replace(&mut desc.mapped_at_creation, false);
if mapped_at_creation && !desc.usage.contains(wgt::BufferUsage::MAP_WRITE) {
desc.usage |= wgt::BufferUsage::COPY_DST;
}
None => (),
};
trace.lock().add(trace::Action::CreateBuffer(id.0, desc));
}
device
.trackers
@ -1119,19 +1116,16 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
//assert!(buffer isn't used by the GPU);
#[cfg(feature = "trace")]
match device.trace {
Some(ref trace) => {
let mut trace = trace.lock();
let data_path = trace.make_binary("bin", data);
trace.add(trace::Action::WriteBuffer {
id: buffer_id,
data: data_path,
range: offset..offset + data.len() as BufferAddress,
queued: false,
});
}
None => (),
};
if let Some(ref trace) = device.trace {
let mut trace = trace.lock();
let data_path = trace.make_binary("bin", data);
trace.add(trace::Action::WriteBuffer {
id: buffer_id,
data: data_path,
range: offset..offset + data.len() as BufferAddress,
queued: false,
});
}
let ptr = map_buffer(
&device.raw,
@ -1279,12 +1273,11 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
let id = hub.textures.register_identity(id_in, texture, &mut token);
#[cfg(feature = "trace")]
match device.trace {
Some(ref trace) => trace
if let Some(ref trace) = device.trace {
trace
.lock()
.add(trace::Action::CreateTexture(id.0, desc.clone())),
None => (),
};
.add(trace::Action::CreateTexture(id.0, desc.clone()));
}
device
.trackers
@ -1443,14 +1436,13 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
let id = hub.texture_views.register_identity(id_in, view, &mut token);
#[cfg(feature = "trace")]
match device.trace {
Some(ref trace) => trace.lock().add(trace::Action::CreateTextureView {
if let Some(ref trace) = device.trace {
trace.lock().add(trace::Action::CreateTextureView {
id: id.0,
parent_id: texture_id,
desc: desc.clone(),
}),
None => (),
};
});
}
device
.trackers
@ -1605,12 +1597,11 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
let id = hub.samplers.register_identity(id_in, sampler, &mut token);
#[cfg(feature = "trace")]
match device.trace {
Some(ref trace) => trace
if let Some(ref trace) = device.trace {
trace
.lock()
.add(trace::Action::CreateSampler(id.0, desc.clone())),
None => (),
};
.add(trace::Action::CreateSampler(id.0, desc.clone()));
}
device
.trackers
@ -1702,12 +1693,11 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
.bind_group_layouts
.register_identity(id_in, layout, &mut token);
#[cfg(feature = "trace")]
match device.trace {
Some(ref trace) => trace
if let Some(ref trace) = device.trace {
trace
.lock()
.add(trace::Action::CreateBindGroupLayout(id.0, desc.clone())),
None => (),
};
.add(trace::Action::CreateBindGroupLayout(id.0, desc.clone()));
}
Ok(id.0)
}
@ -1773,12 +1763,11 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
.pipeline_layouts
.register_identity(id_in, layout, &mut token);
#[cfg(feature = "trace")]
match device.trace {
Some(ref trace) => trace
if let Some(ref trace) = device.trace {
trace
.lock()
.add(trace::Action::CreatePipelineLayout(id.0, desc.clone())),
None => (),
};
.add(trace::Action::CreatePipelineLayout(id.0, desc.clone()));
}
Ok(id.0)
}
@ -1881,12 +1870,11 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
bgl_guard,
);
#[cfg(feature = "trace")]
match device.trace {
Some(ref trace) => trace
if let Some(ref trace) = device.trace {
trace
.lock()
.add(trace::Action::CreateBindGroupLayout(out_id.0, bgl_desc)),
None => (),
};
.add(trace::Action::CreateBindGroupLayout(out_id.0, bgl_desc));
}
out_id.0
}
};
@ -1905,13 +1893,12 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
pipeline_layout_guard,
);
#[cfg(feature = "trace")]
match device.trace {
Some(ref trace) => trace.lock().add(trace::Action::CreatePipelineLayout(
if let Some(ref trace) = device.trace {
trace.lock().add(trace::Action::CreatePipelineLayout(
layout_id.0,
layout_desc,
)),
None => (),
};
));
}
Ok((layout_id.0, derived_bind_group_count))
}
@ -2264,12 +2251,11 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
hub.bind_groups.read(&mut token).0[id].used
);
#[cfg(feature = "trace")]
match device.trace {
Some(ref trace) => trace
if let Some(ref trace) = device.trace {
trace
.lock()
.add(trace::Action::CreateBindGroup(id.0, desc.clone())),
None => (),
};
.add(trace::Action::CreateBindGroup(id.0, desc.clone()));
}
device
.trackers
@ -2410,16 +2396,13 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
.shader_modules
.register_identity(id_in, shader, &mut token);
#[cfg(feature = "trace")]
match device.trace {
Some(ref trace) => {
let mut trace = trace.lock();
let data = trace.make_binary("spv", unsafe {
std::slice::from_raw_parts(spv.as_ptr() as *const u8, spv.len() * 4)
});
trace.add(trace::Action::CreateShaderModule { id: id.0, data });
}
None => {}
};
if let Some(ref trace) = device.trace {
let mut trace = trace.lock();
let data = trace.make_binary("spv", unsafe {
std::slice::from_raw_parts(spv.as_ptr() as *const u8, spv.len() * 4)
});
trace.add(trace::Action::CreateShaderModule { id: id.0, data });
}
Ok(id.0)
}
@ -2443,12 +2426,11 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
if let Some(module) = module {
let device = &device_guard[module.device_id.value];
#[cfg(feature = "trace")]
match device.trace {
Some(ref trace) => trace
if let Some(ref trace) = device.trace {
trace
.lock()
.add(trace::Action::DestroyShaderModule(shader_module_id)),
None => (),
};
.add(trace::Action::DestroyShaderModule(shader_module_id));
}
unsafe {
device.raw.destroy_shader_module(module.raw);
}
@ -3028,16 +3010,15 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
.register_identity(id_in, pipeline, &mut token);
#[cfg(feature = "trace")]
match device.trace {
Some(ref trace) => trace.lock().add(trace::Action::CreateRenderPipeline(
if let Some(ref trace) = device.trace {
trace.lock().add(trace::Action::CreateRenderPipeline(
id.0,
pipeline::RenderPipelineDescriptor {
layout: Some(layout_id),
..desc.clone()
},
)),
None => (),
};
));
}
Ok((id.0, derived_bind_group_count))
}
@ -3250,16 +3231,15 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
.register_identity(id_in, pipeline, &mut token);
#[cfg(feature = "trace")]
match device.trace {
Some(ref trace) => trace.lock().add(trace::Action::CreateComputePipeline(
if let Some(ref trace) = device.trace {
trace.lock().add(trace::Action::CreateComputePipeline(
id.0,
pipeline::ComputePipelineDescriptor {
layout: Some(layout_id),
..desc.clone()
},
)),
None => (),
};
));
}
Ok((id.0, derived_bind_group_count))
}
@ -3440,12 +3420,11 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
}
}
#[cfg(feature = "trace")]
match device.trace {
Some(ref trace) => trace
if let Some(ref trace) = device.trace {
trace
.lock()
.add(Action::CreateSwapChain(sc_id, desc.clone())),
None => (),
};
.add(Action::CreateSwapChain(sc_id, desc.clone()));
}
let swap_chain = swap_chain::SwapChain {
life_guard: LifeGuard::new(),
@ -3697,21 +3676,18 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
needs_flush,
} => {
#[cfg(feature = "trace")]
match device.trace {
Some(ref trace) => {
let mut trace = trace.lock();
let data = trace.make_binary("bin", unsafe {
std::slice::from_raw_parts(ptr.as_ptr(), buffer.size as usize)
});
trace.add(trace::Action::WriteBuffer {
id: buffer_id,
data,
range: 0..buffer.size,
queued: true,
});
}
None => (),
};
if let Some(ref trace) = device.trace {
let mut trace = trace.lock();
let data = trace.make_binary("bin", unsafe {
std::slice::from_raw_parts(ptr.as_ptr(), buffer.size as usize)
});
trace.add(trace::Action::WriteBuffer {
id: buffer_id,
data,
range: 0..buffer.size,
queued: true,
});
}
let _ = ptr;
if needs_flush {
@ -3772,22 +3748,19 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
} => {
if host == HostMap::Write {
#[cfg(feature = "trace")]
match device.trace {
Some(ref trace) => {
let mut trace = trace.lock();
let size = sub_range.size_to(buffer.size);
let data = trace.make_binary("bin", unsafe {
std::slice::from_raw_parts(ptr.as_ptr(), size as usize)
});
trace.add(trace::Action::WriteBuffer {
id: buffer_id,
data,
range: sub_range.offset..sub_range.offset + size,
queued: false,
});
}
None => (),
};
if let Some(ref trace) = device.trace {
let mut trace = trace.lock();
let size = sub_range.size_to(buffer.size);
let data = trace.make_binary("bin", unsafe {
std::slice::from_raw_parts(ptr.as_ptr(), size as usize)
});
trace.add(trace::Action::WriteBuffer {
id: buffer_id,
data,
range: sub_range.offset..sub_range.offset + size,
queued: false,
});
}
let _ = (ptr, sub_range);
}
unmap_buffer(&device.raw, buffer)?;

View File

@ -172,18 +172,15 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
let (buffer_guard, _) = hub.buffers.read(&mut token);
#[cfg(feature = "trace")]
match device.trace {
Some(ref trace) => {
let mut trace = trace.lock();
let data_path = trace.make_binary("bin", data);
trace.add(Action::WriteBuffer {
id: buffer_id,
data: data_path,
range: buffer_offset..buffer_offset + data.len() as wgt::BufferAddress,
queued: true,
});
}
None => {}
if let Some(ref trace) = device.trace {
let mut trace = trace.lock();
let data_path = trace.make_binary("bin", data);
trace.add(Action::WriteBuffer {
id: buffer_id,
data: data_path,
range: buffer_offset..buffer_offset + data.len() as wgt::BufferAddress,
queued: true,
});
}
let data_size = data.len() as wgt::BufferAddress;
@ -280,18 +277,15 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
texture_copy_view_to_hal(destination, size, &*texture_guard)?;
#[cfg(feature = "trace")]
match device.trace {
Some(ref trace) => {
let mut trace = trace.lock();
let data_path = trace.make_binary("bin", data);
trace.add(Action::WriteTexture {
to: destination.clone(),
data: data_path,
layout: data_layout.clone(),
size: *size,
});
}
None => {}
if let Some(ref trace) = device.trace {
let mut trace = trace.lock();
let data_path = trace.make_binary("bin", data);
trace.add(Action::WriteTexture {
to: destination.clone(),
data: data_path,
layout: data_layout.clone(),
size: *size,
});
}
if size.width == 0 || size.height == 0 || size.depth == 0 {
@ -475,13 +469,12 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
.get_mut(cmb_id)
.map_err(|_| QueueSubmitError::InvalidCommandBuffer(cmb_id))?;
#[cfg(feature = "trace")]
match device.trace {
Some(ref trace) => trace.lock().add(Action::Submit(
if let Some(ref trace) = device.trace {
trace.lock().add(Action::Submit(
submit_index,
cmdbuf.commands.take().unwrap(),
)),
None => (),
};
));
}
if let Some((sc_id, fbo)) = cmdbuf.used_swap_chain.take() {
let sc = &mut swap_chain_guard[sc_id.value];

View File

@ -206,13 +206,12 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
};
#[cfg(feature = "trace")]
match device.trace {
Some(ref trace) => trace.lock().add(Action::GetSwapChainTexture {
if let Some(ref trace) = device.trace {
trace.lock().add(Action::GetSwapChainTexture {
id: view_id,
parent_id: swap_chain_id,
}),
None => (),
};
});
}
Ok(SwapChainOutput { status, view_id })
}
@ -238,10 +237,9 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
let device = &mut device_guard[sc.device_id.value];
#[cfg(feature = "trace")]
match device.trace {
Some(ref trace) => trace.lock().add(Action::PresentSwapChain(swap_chain_id)),
None => (),
};
if let Some(ref trace) = device.trace {
trace.lock().add(Action::PresentSwapChain(swap_chain_id));
}
let view_id = sc
.acquired_view_id