Skip to content

Commit

Permalink
chore: satisfy clippy::unnecessary_map_or (#6710)
Browse files Browse the repository at this point in the history
Started firing in Rust 1.84.
  • Loading branch information
ErichDonGubler authored Dec 16, 2024
1 parent f6fec82 commit 964a8d9
Show file tree
Hide file tree
Showing 11 changed files with 16 additions and 20 deletions.
2 changes: 1 addition & 1 deletion naga/src/back/msl/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5264,7 +5264,7 @@ template <typename A>
AttributeMappingResolved {
ty_name: ty_name.to_string(),
dimension: ty_name.vertex_input_dimension(),
ty_is_int: ty_name.scalar().map_or(false, scalar_is_int),
ty_is_int: ty_name.scalar().is_some_and(scalar_is_int),
name: name.to_string(),
},
);
Expand Down
2 changes: 1 addition & 1 deletion naga/src/front/glsl/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ impl Frontend {
)?
}
TypeInner::Vector { size, scalar } => {
if vector_size.map_or(true, |s| s != size) {
if vector_size != Some(size) {
value = ctx.vector_resize(size, value, expr_meta)?;
}

Expand Down
2 changes: 1 addition & 1 deletion naga/src/front/glsl/parser/declarations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ impl ParsingContext<'_> {
// Consume any leading comma, e.g. this is valid: `float, a=1;`
if self
.peek(frontend)
.map_or(false, |t| t.value == TokenValue::Comma)
.is_some_and(|t| t.value == TokenValue::Comma)
{
self.next(frontend);
}
Expand Down
2 changes: 1 addition & 1 deletion naga/src/front/glsl/parser/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::{

impl ParsingContext<'_> {
pub fn peek_parameter_qualifier(&mut self, frontend: &mut Frontend) -> bool {
self.peek(frontend).map_or(false, |t| match t.value {
self.peek(frontend).is_some_and(|t| match t.value {
TokenValue::In | TokenValue::Out | TokenValue::InOut | TokenValue::Const => true,
_ => false,
})
Expand Down
4 changes: 2 additions & 2 deletions naga/src/front/glsl/parser/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ impl ParsingContext<'_> {
}

pub fn peek_type_qualifier(&mut self, frontend: &mut Frontend) -> bool {
self.peek(frontend).map_or(false, |t| match t.value {
self.peek(frontend).is_some_and(|t| match t.value {
TokenValue::Invariant
| TokenValue::Interpolation(_)
| TokenValue::Sampling(_)
Expand Down Expand Up @@ -379,7 +379,7 @@ impl ParsingContext<'_> {
}

pub fn peek_type_name(&mut self, frontend: &mut Frontend) -> bool {
self.peek(frontend).map_or(false, |t| match t.value {
self.peek(frontend).is_some_and(|t| match t.value {
TokenValue::TypeName(_) | TokenValue::Void => true,
TokenValue::Struct => true,
TokenValue::Identifier(ref ident) => frontend.lookup_type.contains_key(ident),
Expand Down
2 changes: 1 addition & 1 deletion naga/src/front/spv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5371,7 +5371,7 @@ impl<I: Iterator<Item = u32>> Frontend<I> {
let parent_decor = self.future_decor.remove(&id);
let is_storage_buffer = parent_decor
.as_ref()
.map_or(false, |decor| decor.storage_buffer);
.is_some_and(|decor| decor.storage_buffer);

self.layouter.update(module.to_ctx()).unwrap();

Expand Down
4 changes: 2 additions & 2 deletions tests/tests/dispatch_workgroups_indirect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ static RESET_BIND_GROUPS: GpuTestConfiguration = GpuTestConfiguration::new()
ctx.queue.submit(Some(encoder.finish()));

let error = pollster::block_on(ctx.device.pop_error_scope());
assert!(error.map_or(false, |error| {
assert!(error.is_some_and(|error| {
format!("{error}").contains("The current set ComputePipeline with '' label expects a BindGroup to be set at index 0")
}));
});
Expand Down Expand Up @@ -130,7 +130,7 @@ static ZERO_SIZED_BUFFER: GpuTestConfiguration = GpuTestConfiguration::new()
ctx.queue.submit(Some(encoder.finish()));

let error = pollster::block_on(ctx.device.pop_error_scope());
assert!(error.map_or(false, |error| {
assert!(error.is_some_and(|error| {
format!("{error}").contains(
"Indirect buffer uses bytes 0..12 which overruns indirect buffer of size 0",
)
Expand Down
2 changes: 1 addition & 1 deletion wgpu-core/src/device/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2644,7 +2644,7 @@ impl Device {
) -> Result<Arc<binding_model::PipelineLayout>, pipeline::ImplicitLayoutError> {
while derived_group_layouts
.last()
.map_or(false, |map| map.is_empty())
.is_some_and(|map| map.is_empty())
{
derived_group_layouts.pop();
}
Expand Down
2 changes: 1 addition & 1 deletion wgpu-hal/src/gles/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ impl super::CommandEncoder {
if dirty_textures & (1 << texture_index) != 0
|| slot
.sampler_index
.map_or(false, |si| dirty_samplers & (1 << si) != 0)
.is_some_and(|si| dirty_samplers & (1 << si) != 0)
{
let sampler = slot
.sampler_index
Expand Down
10 changes: 4 additions & 6 deletions wgpu-hal/src/vulkan/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1498,15 +1498,15 @@ impl super::Instance {
Some(features) => features.imageless_framebuffer == vk::TRUE,
None => phd_features
.imageless_framebuffer
.map_or(false, |ext| ext.imageless_framebuffer != 0),
.is_some_and(|ext| ext.imageless_framebuffer != 0),
},
image_view_usage: phd_capabilities.device_api_version >= vk::API_VERSION_1_1
|| phd_capabilities.supports_extension(khr::maintenance2::NAME),
timeline_semaphores: match phd_features.timeline_semaphore {
Some(features) => features.timeline_semaphore == vk::TRUE,
None => phd_features
.timeline_semaphore
.map_or(false, |ext| ext.timeline_semaphore != 0),
.is_some_and(|ext| ext.timeline_semaphore != 0),
},
texture_d24: supports_format(
&self.shared.raw,
Expand Down Expand Up @@ -1537,7 +1537,7 @@ impl super::Instance {
Some(ref f) => f.robust_image_access2 != 0,
None => phd_features
.image_robustness
.map_or(false, |ext| ext.robust_image_access != 0),
.is_some_and(|ext| ext.robust_image_access != 0),
},
robust_buffer_access2: phd_features
.robustness2
Expand All @@ -1551,9 +1551,7 @@ impl super::Instance {
.unwrap_or_default(),
zero_initialize_workgroup_memory: phd_features
.zero_initialize_workgroup_memory
.map_or(false, |ext| {
ext.shader_zero_initialize_workgroup_memory == vk::TRUE
}),
.is_some_and(|ext| ext.shader_zero_initialize_workgroup_memory == vk::TRUE),
image_format_list: phd_capabilities.device_api_version >= vk::API_VERSION_1_2
|| phd_capabilities.supports_extension(khr::image_format_list::NAME),
#[cfg(windows)]
Expand Down
4 changes: 1 addition & 3 deletions wgpu/src/util/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,7 @@ pub async fn is_browser_webgpu_supported() -> bool {
let adapter_promise = gpu.request_adapter();
wasm_bindgen_futures::JsFuture::from(adapter_promise)
.await
.map_or(false, |adapter| {
!adapter.is_undefined() && !adapter.is_null()
})
.is_ok_and(|adapter| !adapter.is_undefined() && !adapter.is_null())
}
#[cfg(not(webgpu))]
{
Expand Down

0 comments on commit 964a8d9

Please sign in to comment.