refactor: satisfy clippy::never_loop

This commit is contained in:
Erich Gubler 2024-05-16 14:37:25 -04:00
parent 707e91966f
commit b9e787e667
6 changed files with 131 additions and 126 deletions

View File

@ -678,7 +678,7 @@ impl super::Validator {
} }
{ {
let used_push_constants = module let mut used_push_constants = module
.global_variables .global_variables
.iter() .iter()
.filter(|&(_, var)| var.space == crate::AddressSpace::PushConstant) .filter(|&(_, var)| var.space == crate::AddressSpace::PushConstant)
@ -686,8 +686,7 @@ impl super::Validator {
.filter(|&handle| !info[handle].is_empty()); .filter(|&handle| !info[handle].is_empty());
// Check if there is more than one push constant, and error if so. // Check if there is more than one push constant, and error if so.
// Use a loop for when returning multiple errors is supported. // Use a loop for when returning multiple errors is supported.
#[allow(clippy::never_loop)] if let Some(handle) = used_push_constants.nth(1) {
for handle in used_push_constants.skip(1) {
return Err(EntryPointError::MoreThanOnePushConstantUsed return Err(EntryPointError::MoreThanOnePushConstantUsed
.with_span_handle(handle, &module.global_variables)); .with_span_handle(handle, &module.global_variables));
} }

View File

@ -153,20 +153,20 @@ impl Global {
let fid = hub.buffers.prepare(id_in); let fid = hub.buffers.prepare(id_in);
let mut to_destroy: ArrayVec<resource::Buffer<A>, 2> = ArrayVec::new(); let mut to_destroy: ArrayVec<resource::Buffer<A>, 2> = ArrayVec::new();
let error = loop { let error = 'error: {
let device = match hub.devices.get(device_id) { let device = match hub.devices.get(device_id) {
Ok(device) => device, Ok(device) => device,
Err(_) => { Err(_) => {
break DeviceError::Invalid.into(); break 'error DeviceError::Invalid.into();
} }
}; };
if !device.is_valid() { if !device.is_valid() {
break DeviceError::Lost.into(); break 'error DeviceError::Lost.into();
} }
if desc.usage.is_empty() { if desc.usage.is_empty() {
// Per spec, `usage` must not be zero. // Per spec, `usage` must not be zero.
break CreateBufferError::InvalidUsage(desc.usage); break 'error CreateBufferError::InvalidUsage(desc.usage);
} }
#[cfg(feature = "trace")] #[cfg(feature = "trace")]
@ -182,7 +182,7 @@ impl Global {
let buffer = match device.create_buffer(desc, false) { let buffer = match device.create_buffer(desc, false) {
Ok(buffer) => buffer, Ok(buffer) => buffer,
Err(e) => { Err(e) => {
break e; break 'error e;
} }
}; };
@ -206,7 +206,7 @@ impl Global {
Ok(ptr) => ptr, Ok(ptr) => ptr,
Err(e) => { Err(e) => {
to_destroy.push(buffer); to_destroy.push(buffer);
break e.into(); break 'error e.into();
} }
} }
}; };
@ -230,7 +230,7 @@ impl Global {
Ok(stage) => Arc::new(stage), Ok(stage) => Arc::new(stage),
Err(e) => { Err(e) => {
to_destroy.push(buffer); to_destroy.push(buffer);
break e; break 'error e;
} }
}; };
@ -240,7 +240,7 @@ impl Global {
Ok(mapping) => mapping, Ok(mapping) => mapping,
Err(e) => { Err(e) => {
to_destroy.push(buffer); to_destroy.push(buffer);
break CreateBufferError::Device(e.into()); break 'error CreateBufferError::Device(e.into());
} }
}; };
@ -556,13 +556,13 @@ impl Global {
let fid = hub.textures.prepare(id_in); let fid = hub.textures.prepare(id_in);
let error = loop { let error = 'error: {
let device = match hub.devices.get(device_id) { let device = match hub.devices.get(device_id) {
Ok(device) => device, Ok(device) => device,
Err(_) => break DeviceError::Invalid.into(), Err(_) => break 'error DeviceError::Invalid.into(),
}; };
if !device.is_valid() { if !device.is_valid() {
break DeviceError::Lost.into(); break 'error DeviceError::Lost.into();
} }
#[cfg(feature = "trace")] #[cfg(feature = "trace")]
if let Some(ref mut trace) = *device.trace.lock() { if let Some(ref mut trace) = *device.trace.lock() {
@ -571,7 +571,7 @@ impl Global {
let texture = match device.create_texture(&device.adapter, desc) { let texture = match device.create_texture(&device.adapter, desc) {
Ok(texture) => texture, Ok(texture) => texture,
Err(error) => break error, Err(error) => break 'error error,
}; };
let (id, resource) = fid.assign(Arc::new(texture)); let (id, resource) = fid.assign(Arc::new(texture));
@ -610,13 +610,13 @@ impl Global {
let fid = hub.textures.prepare(id_in); let fid = hub.textures.prepare(id_in);
let error = loop { let error = 'error: {
let device = match hub.devices.get(device_id) { let device = match hub.devices.get(device_id) {
Ok(device) => device, Ok(device) => device,
Err(_) => break DeviceError::Invalid.into(), Err(_) => break 'error DeviceError::Invalid.into(),
}; };
if !device.is_valid() { if !device.is_valid() {
break DeviceError::Lost.into(); break 'error DeviceError::Lost.into();
} }
// NB: Any change done through the raw texture handle will not be // NB: Any change done through the raw texture handle will not be
@ -631,7 +631,7 @@ impl Global {
.map_err(|error| resource::CreateTextureError::MissingFeatures(desc.format, error)) .map_err(|error| resource::CreateTextureError::MissingFeatures(desc.format, error))
{ {
Ok(features) => features, Ok(features) => features,
Err(error) => break error, Err(error) => break 'error error,
}; };
let mut texture = device.create_texture_from_hal( let mut texture = device.create_texture_from_hal(
@ -685,13 +685,13 @@ impl Global {
let hub = A::hub(self); let hub = A::hub(self);
let fid = hub.buffers.prepare(id_in); let fid = hub.buffers.prepare(id_in);
let error = loop { let error = 'error: {
let device = match hub.devices.get(device_id) { let device = match hub.devices.get(device_id) {
Ok(device) => device, Ok(device) => device,
Err(_) => break DeviceError::Invalid.into(), Err(_) => break 'error DeviceError::Invalid.into(),
}; };
if !device.is_valid() { if !device.is_valid() {
break DeviceError::Lost.into(); break 'error DeviceError::Lost.into();
} }
// NB: Any change done through the raw buffer handle will not be // NB: Any change done through the raw buffer handle will not be
@ -796,16 +796,16 @@ impl Global {
let fid = hub.texture_views.prepare(id_in); let fid = hub.texture_views.prepare(id_in);
let error = loop { let error = 'error: {
let texture = match hub.textures.get(texture_id) { let texture = match hub.textures.get(texture_id) {
Ok(texture) => texture, Ok(texture) => texture,
Err(_) => break resource::CreateTextureViewError::InvalidTexture, Err(_) => break 'error resource::CreateTextureViewError::InvalidTexture,
}; };
let device = &texture.device; let device = &texture.device;
{ {
let snatch_guard = device.snatchable_lock.read(); let snatch_guard = device.snatchable_lock.read();
if texture.is_destroyed(&snatch_guard) { if texture.is_destroyed(&snatch_guard) {
break resource::CreateTextureViewError::InvalidTexture; break 'error resource::CreateTextureViewError::InvalidTexture;
} }
} }
#[cfg(feature = "trace")] #[cfg(feature = "trace")]
@ -819,7 +819,7 @@ impl Global {
let view = match unsafe { device.create_texture_view(&texture, desc) } { let view = match unsafe { device.create_texture_view(&texture, desc) } {
Ok(view) => view, Ok(view) => view,
Err(e) => break e, Err(e) => break 'error e,
}; };
let (id, resource) = fid.assign(Arc::new(view)); let (id, resource) = fid.assign(Arc::new(view));
@ -885,13 +885,13 @@ impl Global {
let hub = A::hub(self); let hub = A::hub(self);
let fid = hub.samplers.prepare(id_in); let fid = hub.samplers.prepare(id_in);
let error = loop { let error = 'error: {
let device = match hub.devices.get(device_id) { let device = match hub.devices.get(device_id) {
Ok(device) => device, Ok(device) => device,
Err(_) => break DeviceError::Invalid.into(), Err(_) => break 'error DeviceError::Invalid.into(),
}; };
if !device.is_valid() { if !device.is_valid() {
break DeviceError::Lost.into(); break 'error DeviceError::Lost.into();
} }
#[cfg(feature = "trace")] #[cfg(feature = "trace")]
@ -901,7 +901,7 @@ impl Global {
let sampler = match device.create_sampler(desc) { let sampler = match device.create_sampler(desc) {
Ok(sampler) => sampler, Ok(sampler) => sampler,
Err(e) => break e, Err(e) => break 'error e,
}; };
let (id, resource) = fid.assign(Arc::new(sampler)); let (id, resource) = fid.assign(Arc::new(sampler));
@ -949,13 +949,13 @@ impl Global {
let hub = A::hub(self); let hub = A::hub(self);
let fid = hub.bind_group_layouts.prepare(id_in); let fid = hub.bind_group_layouts.prepare(id_in);
let error = loop { let error = 'error: {
let device = match hub.devices.get(device_id) { let device = match hub.devices.get(device_id) {
Ok(device) => device, Ok(device) => device,
Err(_) => break DeviceError::Invalid.into(), Err(_) => break 'error DeviceError::Invalid.into(),
}; };
if !device.is_valid() { if !device.is_valid() {
break DeviceError::Lost.into(); break 'error DeviceError::Lost.into();
} }
#[cfg(feature = "trace")] #[cfg(feature = "trace")]
@ -965,7 +965,7 @@ impl Global {
let entry_map = match bgl::EntryMap::from_entries(&device.limits, &desc.entries) { let entry_map = match bgl::EntryMap::from_entries(&device.limits, &desc.entries) {
Ok(map) => map, Ok(map) => map,
Err(e) => break e, Err(e) => break 'error e,
}; };
// Currently we make a distinction between fid.assign and fid.assign_existing. This distinction is incorrect, // Currently we make a distinction between fid.assign and fid.assign_existing. This distinction is incorrect,
@ -994,7 +994,7 @@ impl Global {
let layout = match bgl_result { let layout = match bgl_result {
Ok(layout) => layout, Ok(layout) => layout,
Err(e) => break e, Err(e) => break 'error e,
}; };
// If the ID was not assigned, and we survived the above check, // If the ID was not assigned, and we survived the above check,
@ -1048,13 +1048,13 @@ impl Global {
let hub = A::hub(self); let hub = A::hub(self);
let fid = hub.pipeline_layouts.prepare(id_in); let fid = hub.pipeline_layouts.prepare(id_in);
let error = loop { let error = 'error: {
let device = match hub.devices.get(device_id) { let device = match hub.devices.get(device_id) {
Ok(device) => device, Ok(device) => device,
Err(_) => break DeviceError::Invalid.into(), Err(_) => break 'error DeviceError::Invalid.into(),
}; };
if !device.is_valid() { if !device.is_valid() {
break DeviceError::Lost.into(); break 'error DeviceError::Lost.into();
} }
#[cfg(feature = "trace")] #[cfg(feature = "trace")]
@ -1064,7 +1064,7 @@ impl Global {
let layout = match device.create_pipeline_layout(desc, &hub.bind_group_layouts) { let layout = match device.create_pipeline_layout(desc, &hub.bind_group_layouts) {
Ok(layout) => layout, Ok(layout) => layout,
Err(e) => break e, Err(e) => break 'error e,
}; };
let (id, _) = fid.assign(Arc::new(layout)); let (id, _) = fid.assign(Arc::new(layout));
@ -1106,13 +1106,13 @@ impl Global {
let hub = A::hub(self); let hub = A::hub(self);
let fid = hub.bind_groups.prepare(id_in); let fid = hub.bind_groups.prepare(id_in);
let error = loop { let error = 'error: {
let device = match hub.devices.get(device_id) { let device = match hub.devices.get(device_id) {
Ok(device) => device, Ok(device) => device,
Err(_) => break DeviceError::Invalid.into(), Err(_) => break 'error DeviceError::Invalid.into(),
}; };
if !device.is_valid() { if !device.is_valid() {
break DeviceError::Lost.into(); break 'error DeviceError::Lost.into();
} }
#[cfg(feature = "trace")] #[cfg(feature = "trace")]
@ -1122,16 +1122,16 @@ impl Global {
let bind_group_layout = match hub.bind_group_layouts.get(desc.layout) { let bind_group_layout = match hub.bind_group_layouts.get(desc.layout) {
Ok(layout) => layout, Ok(layout) => layout,
Err(..) => break binding_model::CreateBindGroupError::InvalidLayout, Err(..) => break 'error binding_model::CreateBindGroupError::InvalidLayout,
}; };
if bind_group_layout.device.as_info().id() != device.as_info().id() { if bind_group_layout.device.as_info().id() != device.as_info().id() {
break DeviceError::WrongDevice.into(); break 'error DeviceError::WrongDevice.into();
} }
let bind_group = match device.create_bind_group(&bind_group_layout, desc, hub) { let bind_group = match device.create_bind_group(&bind_group_layout, desc, hub) {
Ok(bind_group) => bind_group, Ok(bind_group) => bind_group,
Err(e) => break e, Err(e) => break 'error e,
}; };
let (id, resource) = fid.assign(Arc::new(bind_group)); let (id, resource) = fid.assign(Arc::new(bind_group));
@ -1203,13 +1203,13 @@ impl Global {
let hub = A::hub(self); let hub = A::hub(self);
let fid = hub.shader_modules.prepare(id_in); let fid = hub.shader_modules.prepare(id_in);
let error = loop { let error = 'error: {
let device = match hub.devices.get(device_id) { let device = match hub.devices.get(device_id) {
Ok(device) => device, Ok(device) => device,
Err(_) => break DeviceError::Invalid.into(), Err(_) => break 'error DeviceError::Invalid.into(),
}; };
if !device.is_valid() { if !device.is_valid() {
break DeviceError::Lost.into(); break 'error DeviceError::Lost.into();
} }
#[cfg(feature = "trace")] #[cfg(feature = "trace")]
@ -1246,7 +1246,7 @@ impl Global {
let shader = match device.create_shader_module(desc, source) { let shader = match device.create_shader_module(desc, source) {
Ok(shader) => shader, Ok(shader) => shader,
Err(e) => break e, Err(e) => break 'error e,
}; };
let (id, _) = fid.assign(Arc::new(shader)); let (id, _) = fid.assign(Arc::new(shader));
@ -1281,13 +1281,13 @@ impl Global {
let hub = A::hub(self); let hub = A::hub(self);
let fid = hub.shader_modules.prepare(id_in); let fid = hub.shader_modules.prepare(id_in);
let error = loop { let error = 'error: {
let device = match hub.devices.get(device_id) { let device = match hub.devices.get(device_id) {
Ok(device) => device, Ok(device) => device,
Err(_) => break DeviceError::Invalid.into(), Err(_) => break 'error DeviceError::Invalid.into(),
}; };
if !device.is_valid() { if !device.is_valid() {
break DeviceError::Lost.into(); break 'error DeviceError::Lost.into();
} }
#[cfg(feature = "trace")] #[cfg(feature = "trace")]
@ -1304,7 +1304,7 @@ impl Global {
let shader = match unsafe { device.create_shader_module_spirv(desc, &source) } { let shader = match unsafe { device.create_shader_module_spirv(desc, &source) } {
Ok(shader) => shader, Ok(shader) => shader,
Err(e) => break e, Err(e) => break 'error e,
}; };
let (id, _) = fid.assign(Arc::new(shader)); let (id, _) = fid.assign(Arc::new(shader));
api_log!("Device::create_shader_module_spirv -> {id:?}"); api_log!("Device::create_shader_module_spirv -> {id:?}");
@ -1342,23 +1342,23 @@ impl Global {
.command_buffers .command_buffers
.prepare(id_in.map(|id| id.into_command_buffer_id())); .prepare(id_in.map(|id| id.into_command_buffer_id()));
let error = loop { let error = 'error: {
let device = match hub.devices.get(device_id) { let device = match hub.devices.get(device_id) {
Ok(device) => device, Ok(device) => device,
Err(_) => break DeviceError::Invalid, Err(_) => break 'error DeviceError::Invalid,
}; };
if !device.is_valid() { if !device.is_valid() {
break DeviceError::Lost; break 'error DeviceError::Lost;
} }
let Some(queue) = device.get_queue() else { let Some(queue) = device.get_queue() else {
break DeviceError::InvalidQueueId; break 'error DeviceError::InvalidQueueId;
}; };
let encoder = match device let encoder = match device
.command_allocator .command_allocator
.acquire_encoder(device.raw(), queue.raw.as_ref().unwrap()) .acquire_encoder(device.raw(), queue.raw.as_ref().unwrap())
{ {
Ok(raw) => raw, Ok(raw) => raw,
Err(_) => break DeviceError::OutOfMemory, Err(_) => break 'error DeviceError::OutOfMemory,
}; };
let command_buffer = command::CommandBuffer::new( let command_buffer = command::CommandBuffer::new(
encoder, encoder,
@ -1433,13 +1433,13 @@ impl Global {
let fid = hub.render_bundles.prepare(id_in); let fid = hub.render_bundles.prepare(id_in);
let error = loop { let error = 'error: {
let device = match hub.devices.get(bundle_encoder.parent()) { let device = match hub.devices.get(bundle_encoder.parent()) {
Ok(device) => device, Ok(device) => device,
Err(_) => break command::RenderBundleError::INVALID_DEVICE, Err(_) => break 'error command::RenderBundleError::INVALID_DEVICE,
}; };
if !device.is_valid() { if !device.is_valid() {
break command::RenderBundleError::INVALID_DEVICE; break 'error command::RenderBundleError::INVALID_DEVICE;
} }
#[cfg(feature = "trace")] #[cfg(feature = "trace")]
@ -1458,7 +1458,7 @@ impl Global {
let render_bundle = match bundle_encoder.finish(desc, &device, hub) { let render_bundle = match bundle_encoder.finish(desc, &device, hub) {
Ok(bundle) => bundle, Ok(bundle) => bundle,
Err(e) => break e, Err(e) => break 'error e,
}; };
let (id, resource) = fid.assign(Arc::new(render_bundle)); let (id, resource) = fid.assign(Arc::new(render_bundle));
@ -1502,13 +1502,13 @@ impl Global {
let hub = A::hub(self); let hub = A::hub(self);
let fid = hub.query_sets.prepare(id_in); let fid = hub.query_sets.prepare(id_in);
let error = loop { let error = 'error: {
let device = match hub.devices.get(device_id) { let device = match hub.devices.get(device_id) {
Ok(device) => device, Ok(device) => device,
Err(_) => break DeviceError::Invalid.into(), Err(_) => break 'error DeviceError::Invalid.into(),
}; };
if !device.is_valid() { if !device.is_valid() {
break DeviceError::Lost.into(); break 'error DeviceError::Lost.into();
} }
#[cfg(feature = "trace")] #[cfg(feature = "trace")]
@ -1521,7 +1521,7 @@ impl Global {
let query_set = match device.create_query_set(desc) { let query_set = match device.create_query_set(desc) {
Ok(query_set) => query_set, Ok(query_set) => query_set,
Err(err) => break err, Err(err) => break 'error err,
}; };
let (id, resource) = fid.assign(Arc::new(query_set)); let (id, resource) = fid.assign(Arc::new(query_set));
@ -1579,13 +1579,13 @@ impl Global {
let implicit_context = implicit_pipeline_ids.map(|ipi| ipi.prepare(hub)); let implicit_context = implicit_pipeline_ids.map(|ipi| ipi.prepare(hub));
let implicit_error_context = implicit_context.clone(); let implicit_error_context = implicit_context.clone();
let error = loop { let error = 'error: {
let device = match hub.devices.get(device_id) { let device = match hub.devices.get(device_id) {
Ok(device) => device, Ok(device) => device,
Err(_) => break DeviceError::Invalid.into(), Err(_) => break 'error DeviceError::Invalid.into(),
}; };
if !device.is_valid() { if !device.is_valid() {
break DeviceError::Lost.into(); break 'error DeviceError::Lost.into();
} }
#[cfg(feature = "trace")] #[cfg(feature = "trace")]
if let Some(ref mut trace) = *device.trace.lock() { if let Some(ref mut trace) = *device.trace.lock() {
@ -1599,7 +1599,7 @@ impl Global {
let pipeline = let pipeline =
match device.create_render_pipeline(&device.adapter, desc, implicit_context, hub) { match device.create_render_pipeline(&device.adapter, desc, implicit_context, hub) {
Ok(pair) => pair, Ok(pair) => pair,
Err(e) => break e, Err(e) => break 'error e,
}; };
let (id, resource) = fid.assign(Arc::new(pipeline)); let (id, resource) = fid.assign(Arc::new(pipeline));
@ -1651,14 +1651,16 @@ impl Global {
) { ) {
let hub = A::hub(self); let hub = A::hub(self);
let error = loop { let error = 'error: {
let pipeline = match hub.render_pipelines.get(pipeline_id) { let pipeline = match hub.render_pipelines.get(pipeline_id) {
Ok(pipeline) => pipeline, Ok(pipeline) => pipeline,
Err(_) => break binding_model::GetBindGroupLayoutError::InvalidPipeline, Err(_) => break 'error binding_model::GetBindGroupLayoutError::InvalidPipeline,
}; };
let id = match pipeline.layout.bind_group_layouts.get(index as usize) { let id = match pipeline.layout.bind_group_layouts.get(index as usize) {
Some(bg) => hub.bind_group_layouts.prepare(id_in).assign_existing(bg), Some(bg) => hub.bind_group_layouts.prepare(id_in).assign_existing(bg),
None => break binding_model::GetBindGroupLayoutError::InvalidGroupIndex(index), None => {
break 'error binding_model::GetBindGroupLayoutError::InvalidGroupIndex(index)
}
}; };
return (id, None); return (id, None);
}; };
@ -1713,13 +1715,13 @@ impl Global {
let implicit_context = implicit_pipeline_ids.map(|ipi| ipi.prepare(hub)); let implicit_context = implicit_pipeline_ids.map(|ipi| ipi.prepare(hub));
let implicit_error_context = implicit_context.clone(); let implicit_error_context = implicit_context.clone();
let error = loop { let error = 'error: {
let device = match hub.devices.get(device_id) { let device = match hub.devices.get(device_id) {
Ok(device) => device, Ok(device) => device,
Err(_) => break DeviceError::Invalid.into(), Err(_) => break 'error DeviceError::Invalid.into(),
}; };
if !device.is_valid() { if !device.is_valid() {
break DeviceError::Lost.into(); break 'error DeviceError::Lost.into();
} }
#[cfg(feature = "trace")] #[cfg(feature = "trace")]
@ -1732,7 +1734,7 @@ impl Global {
} }
let pipeline = match device.create_compute_pipeline(desc, implicit_context, hub) { let pipeline = match device.create_compute_pipeline(desc, implicit_context, hub) {
Ok(pair) => pair, Ok(pair) => pair,
Err(e) => break e, Err(e) => break 'error e,
}; };
let (id, resource) = fid.assign(Arc::new(pipeline)); let (id, resource) = fid.assign(Arc::new(pipeline));
@ -1780,15 +1782,17 @@ impl Global {
) { ) {
let hub = A::hub(self); let hub = A::hub(self);
let error = loop { let error = 'error: {
let pipeline = match hub.compute_pipelines.get(pipeline_id) { let pipeline = match hub.compute_pipelines.get(pipeline_id) {
Ok(pipeline) => pipeline, Ok(pipeline) => pipeline,
Err(_) => break binding_model::GetBindGroupLayoutError::InvalidPipeline, Err(_) => break 'error binding_model::GetBindGroupLayoutError::InvalidPipeline,
}; };
let id = match pipeline.layout.bind_group_layouts.get(index as usize) { let id = match pipeline.layout.bind_group_layouts.get(index as usize) {
Some(bg) => hub.bind_group_layouts.prepare(id_in).assign_existing(bg), Some(bg) => hub.bind_group_layouts.prepare(id_in).assign_existing(bg),
None => break binding_model::GetBindGroupLayoutError::InvalidGroupIndex(index), None => {
break 'error binding_model::GetBindGroupLayoutError::InvalidGroupIndex(index)
}
}; };
return (id, None); return (id, None);
@ -1912,7 +1916,7 @@ impl Global {
} }
if !caps.present_modes.contains(&config.present_mode) { if !caps.present_modes.contains(&config.present_mode) {
let new_mode = 'b: loop { let new_mode = 'error: {
// Automatic present mode checks. // Automatic present mode checks.
// //
// The "Automatic" modes are never supported by the backends. // The "Automatic" modes are never supported by the backends.
@ -1936,7 +1940,7 @@ impl Global {
for &fallback in fallbacks { for &fallback in fallbacks {
if caps.present_modes.contains(&fallback) { if caps.present_modes.contains(&fallback) {
break 'b fallback; break 'error fallback;
} }
} }
@ -1959,7 +1963,7 @@ impl Global {
.composite_alpha_modes .composite_alpha_modes
.contains(&config.composite_alpha_mode) .contains(&config.composite_alpha_mode)
{ {
let new_alpha_mode = 'alpha: loop { let new_alpha_mode = 'alpha: {
// Automatic alpha mode checks. // Automatic alpha mode checks.
let fallbacks = match config.composite_alpha_mode { let fallbacks = match config.composite_alpha_mode {
wgt::CompositeAlphaMode::Auto => &[ wgt::CompositeAlphaMode::Auto => &[
@ -2004,7 +2008,7 @@ impl Global {
log::debug!("configuring surface with {:?}", config); log::debug!("configuring surface with {:?}", config);
let error = 'outer: loop { let error = 'error: {
// User callbacks must not be called while we are holding locks. // User callbacks must not be called while we are holding locks.
let user_callbacks; let user_callbacks;
{ {
@ -2014,10 +2018,10 @@ impl Global {
let device = match device_guard.get(device_id) { let device = match device_guard.get(device_id) {
Ok(device) => device, Ok(device) => device,
Err(_) => break DeviceError::Invalid.into(), Err(_) => break 'error DeviceError::Invalid.into(),
}; };
if !device.is_valid() { if !device.is_valid() {
break DeviceError::Lost.into(); break 'error DeviceError::Lost.into();
} }
#[cfg(feature = "trace")] #[cfg(feature = "trace")]
@ -2027,7 +2031,7 @@ impl Global {
let surface = match surface_guard.get(surface_id) { let surface = match surface_guard.get(surface_id) {
Ok(surface) => surface, Ok(surface) => surface,
Err(_) => break E::InvalidSurface, Err(_) => break 'error E::InvalidSurface,
}; };
let caps = unsafe { let caps = unsafe {
@ -2035,7 +2039,7 @@ impl Global {
let adapter = &device.adapter; let adapter = &device.adapter;
match adapter.raw.adapter.surface_capabilities(suf.unwrap()) { match adapter.raw.adapter.surface_capabilities(suf.unwrap()) {
Some(caps) => caps, Some(caps) => caps,
None => break E::UnsupportedQueueFamily, None => break 'error E::UnsupportedQueueFamily,
} }
}; };
@ -2045,13 +2049,13 @@ impl Global {
continue; continue;
} }
if !caps.formats.contains(&config.format) { if !caps.formats.contains(&config.format) {
break 'outer E::UnsupportedFormat { break 'error E::UnsupportedFormat {
requested: config.format, requested: config.format,
available: caps.formats, available: caps.formats,
}; };
} }
if config.format.remove_srgb_suffix() != format.remove_srgb_suffix() { if config.format.remove_srgb_suffix() != format.remove_srgb_suffix() {
break 'outer E::InvalidViewFormat(*format, config.format); break 'error E::InvalidViewFormat(*format, config.format);
} }
hal_view_formats.push(*format); hal_view_formats.push(*format);
} }
@ -2060,7 +2064,7 @@ impl Global {
if let Err(missing_flag) = if let Err(missing_flag) =
device.require_downlevel_flags(wgt::DownlevelFlags::SURFACE_VIEW_FORMATS) device.require_downlevel_flags(wgt::DownlevelFlags::SURFACE_VIEW_FORMATS)
{ {
break 'outer E::MissingDownlevelFlags(missing_flag); break 'error E::MissingDownlevelFlags(missing_flag);
} }
} }
@ -2087,7 +2091,7 @@ impl Global {
&caps, &caps,
device.limits.max_texture_dimension_2d, device.limits.max_texture_dimension_2d,
) { ) {
break error; break 'error error;
} }
// Wait for all work to finish before configuring the surface. // Wait for all work to finish before configuring the surface.
@ -2098,14 +2102,14 @@ impl Global {
user_callbacks = closures; user_callbacks = closures;
} }
Err(e) => { Err(e) => {
break e.into(); break 'error e.into();
} }
} }
// All textures must be destroyed before the surface can be re-configured. // All textures must be destroyed before the surface can be re-configured.
if let Some(present) = surface.presentation.lock().take() { if let Some(present) = surface.presentation.lock().take() {
if present.acquired_texture.is_some() { if present.acquired_texture.is_some() {
break E::PreviousOutputExists; break 'error E::PreviousOutputExists;
} }
} }
@ -2122,7 +2126,7 @@ impl Global {
} { } {
Ok(()) => (), Ok(()) => (),
Err(error) => { Err(error) => {
break match error { break 'error match error {
hal::SurfaceError::Outdated | hal::SurfaceError::Lost => { hal::SurfaceError::Outdated | hal::SurfaceError::Lost => {
E::InvalidSurface E::InvalidSurface
} }

View File

@ -1174,26 +1174,26 @@ impl<A: HalApi> Device<A> {
}; };
// https://gpuweb.github.io/gpuweb/#abstract-opdef-renderable-texture-view // https://gpuweb.github.io/gpuweb/#abstract-opdef-renderable-texture-view
let render_extent = 'b: loop { let render_extent = 'error: {
if !texture if !texture
.desc .desc
.usage .usage
.contains(wgt::TextureUsages::RENDER_ATTACHMENT) .contains(wgt::TextureUsages::RENDER_ATTACHMENT)
{ {
break 'b Err(TextureViewNotRenderableReason::Usage(texture.desc.usage)); break 'error Err(TextureViewNotRenderableReason::Usage(texture.desc.usage));
} }
if !(resolved_dimension == TextureViewDimension::D2 if !(resolved_dimension == TextureViewDimension::D2
|| (self.features.contains(wgt::Features::MULTIVIEW) || (self.features.contains(wgt::Features::MULTIVIEW)
&& resolved_dimension == TextureViewDimension::D2Array)) && resolved_dimension == TextureViewDimension::D2Array))
{ {
break 'b Err(TextureViewNotRenderableReason::Dimension( break 'error Err(TextureViewNotRenderableReason::Dimension(
resolved_dimension, resolved_dimension,
)); ));
} }
if resolved_mip_level_count != 1 { if resolved_mip_level_count != 1 {
break 'b Err(TextureViewNotRenderableReason::MipLevelCount( break 'error Err(TextureViewNotRenderableReason::MipLevelCount(
resolved_mip_level_count, resolved_mip_level_count,
)); ));
} }
@ -1201,18 +1201,18 @@ impl<A: HalApi> Device<A> {
if resolved_array_layer_count != 1 if resolved_array_layer_count != 1
&& !(self.features.contains(wgt::Features::MULTIVIEW)) && !(self.features.contains(wgt::Features::MULTIVIEW))
{ {
break 'b Err(TextureViewNotRenderableReason::ArrayLayerCount( break 'error Err(TextureViewNotRenderableReason::ArrayLayerCount(
resolved_array_layer_count, resolved_array_layer_count,
)); ));
} }
if aspects != hal::FormatAspects::from(texture.desc.format) { if aspects != hal::FormatAspects::from(texture.desc.format) {
break 'b Err(TextureViewNotRenderableReason::Aspects(aspects)); break 'error Err(TextureViewNotRenderableReason::Aspects(aspects));
} }
break 'b Ok(texture Ok(texture
.desc .desc
.compute_render_extent(desc.range.base_mip_level)); .compute_render_extent(desc.range.base_mip_level))
}; };
// filter the usages based on the other criteria // filter the usages based on the other criteria
@ -2948,9 +2948,11 @@ impl<A: HalApi> Device<A> {
for (i, cs) in color_targets.iter().enumerate() { for (i, cs) in color_targets.iter().enumerate() {
if let Some(cs) = cs.as_ref() { if let Some(cs) = cs.as_ref() {
target_specified = true; target_specified = true;
let error = loop { let error = 'error: {
if cs.write_mask.contains_invalid_bits() { if cs.write_mask.contains_invalid_bits() {
break Some(pipeline::ColorStateError::InvalidWriteMask(cs.write_mask)); break 'error Some(pipeline::ColorStateError::InvalidWriteMask(
cs.write_mask,
));
} }
let format_features = self.describe_format_features(adapter, cs.format)?; let format_features = self.describe_format_features(adapter, cs.format)?;
@ -2958,7 +2960,9 @@ impl<A: HalApi> Device<A> {
.allowed_usages .allowed_usages
.contains(wgt::TextureUsages::RENDER_ATTACHMENT) .contains(wgt::TextureUsages::RENDER_ATTACHMENT)
{ {
break Some(pipeline::ColorStateError::FormatNotRenderable(cs.format)); break 'error Some(pipeline::ColorStateError::FormatNotRenderable(
cs.format,
));
} }
let blendable = format_features.flags.contains(Tfff::BLENDABLE); let blendable = format_features.flags.contains(Tfff::BLENDABLE);
let filterable = format_features.flags.contains(Tfff::FILTERABLE); let filterable = format_features.flags.contains(Tfff::FILTERABLE);
@ -2970,10 +2974,12 @@ impl<A: HalApi> Device<A> {
// [`Features::TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES`] to elude // [`Features::TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES`] to elude
// this limitation // this limitation
if cs.blend.is_some() && (!blendable || (!filterable && !adapter_specific)) { if cs.blend.is_some() && (!blendable || (!filterable && !adapter_specific)) {
break Some(pipeline::ColorStateError::FormatNotBlendable(cs.format)); break 'error Some(pipeline::ColorStateError::FormatNotBlendable(
cs.format,
));
} }
if !hal::FormatAspects::from(cs.format).contains(hal::FormatAspects::COLOR) { if !hal::FormatAspects::from(cs.format).contains(hal::FormatAspects::COLOR) {
break Some(pipeline::ColorStateError::FormatNotColor(cs.format)); break 'error Some(pipeline::ColorStateError::FormatNotColor(cs.format));
} }
if desc.multisample.count > 1 if desc.multisample.count > 1
@ -2981,7 +2987,7 @@ impl<A: HalApi> Device<A> {
.flags .flags
.sample_count_supported(desc.multisample.count) .sample_count_supported(desc.multisample.count)
{ {
break Some(pipeline::ColorStateError::InvalidSampleCount( break 'error Some(pipeline::ColorStateError::InvalidSampleCount(
desc.multisample.count, desc.multisample.count,
cs.format, cs.format,
cs.format cs.format
@ -3015,7 +3021,7 @@ impl<A: HalApi> Device<A> {
} }
} }
break None; break 'error None;
}; };
if let Some(e) = error { if let Some(e) = error {
return Err(pipeline::CreateRenderPipelineError::ColorState(i as u8, e)); return Err(pipeline::CreateRenderPipelineError::ColorState(i as u8, e));
@ -3035,23 +3041,23 @@ impl<A: HalApi> Device<A> {
if let Some(ds) = depth_stencil_state { if let Some(ds) = depth_stencil_state {
target_specified = true; target_specified = true;
let error = loop { let error = 'error: {
let format_features = self.describe_format_features(adapter, ds.format)?; let format_features = self.describe_format_features(adapter, ds.format)?;
if !format_features if !format_features
.allowed_usages .allowed_usages
.contains(wgt::TextureUsages::RENDER_ATTACHMENT) .contains(wgt::TextureUsages::RENDER_ATTACHMENT)
{ {
break Some(pipeline::DepthStencilStateError::FormatNotRenderable( break 'error Some(pipeline::DepthStencilStateError::FormatNotRenderable(
ds.format, ds.format,
)); ));
} }
let aspect = hal::FormatAspects::from(ds.format); let aspect = hal::FormatAspects::from(ds.format);
if ds.is_depth_enabled() && !aspect.contains(hal::FormatAspects::DEPTH) { if ds.is_depth_enabled() && !aspect.contains(hal::FormatAspects::DEPTH) {
break Some(pipeline::DepthStencilStateError::FormatNotDepth(ds.format)); break 'error Some(pipeline::DepthStencilStateError::FormatNotDepth(ds.format));
} }
if ds.stencil.is_enabled() && !aspect.contains(hal::FormatAspects::STENCIL) { if ds.stencil.is_enabled() && !aspect.contains(hal::FormatAspects::STENCIL) {
break Some(pipeline::DepthStencilStateError::FormatNotStencil( break 'error Some(pipeline::DepthStencilStateError::FormatNotStencil(
ds.format, ds.format,
)); ));
} }
@ -3060,7 +3066,7 @@ impl<A: HalApi> Device<A> {
.flags .flags
.sample_count_supported(desc.multisample.count) .sample_count_supported(desc.multisample.count)
{ {
break Some(pipeline::DepthStencilStateError::InvalidSampleCount( break 'error Some(pipeline::DepthStencilStateError::InvalidSampleCount(
desc.multisample.count, desc.multisample.count,
ds.format, ds.format,
ds.format ds.format
@ -3074,7 +3080,7 @@ impl<A: HalApi> Device<A> {
)); ));
} }
break None; break 'error None;
}; };
if let Some(e) = error { if let Some(e) = error {
return Err(pipeline::CreateRenderPipelineError::DepthStencilState(e)); return Err(pipeline::CreateRenderPipelineError::DepthStencilState(e));

View File

@ -1099,15 +1099,15 @@ impl Global {
let device_fid = hub.devices.prepare(device_id_in); let device_fid = hub.devices.prepare(device_id_in);
let queue_fid = hub.queues.prepare(queue_id_in); let queue_fid = hub.queues.prepare(queue_id_in);
let error = loop { let error = 'error: {
let adapter = match hub.adapters.get(adapter_id) { let adapter = match hub.adapters.get(adapter_id) {
Ok(adapter) => adapter, Ok(adapter) => adapter,
Err(_) => break RequestDeviceError::InvalidAdapter, Err(_) => break 'error RequestDeviceError::InvalidAdapter,
}; };
let (device, mut queue) = let (device, mut queue) =
match adapter.create_device_and_queue(desc, self.instance.flags, trace_path) { match adapter.create_device_and_queue(desc, self.instance.flags, trace_path) {
Ok((device, queue)) => (device, queue), Ok((device, queue)) => (device, queue),
Err(e) => break e, Err(e) => break 'error e,
}; };
let (device_id, _) = device_fid.assign(Arc::new(device)); let (device_id, _) = device_fid.assign(Arc::new(device));
resource_log!("Created Device {:?}", device_id); resource_log!("Created Device {:?}", device_id);
@ -1147,10 +1147,10 @@ impl Global {
let devices_fid = hub.devices.prepare(device_id_in); let devices_fid = hub.devices.prepare(device_id_in);
let queues_fid = hub.queues.prepare(queue_id_in); let queues_fid = hub.queues.prepare(queue_id_in);
let error = loop { let error = 'error: {
let adapter = match hub.adapters.get(adapter_id) { let adapter = match hub.adapters.get(adapter_id) {
Ok(adapter) => adapter, Ok(adapter) => adapter,
Err(_) => break RequestDeviceError::InvalidAdapter, Err(_) => break 'error RequestDeviceError::InvalidAdapter,
}; };
let (device, mut queue) = match adapter.create_device_and_queue_from_hal( let (device, mut queue) = match adapter.create_device_and_queue_from_hal(
hal_device, hal_device,
@ -1159,7 +1159,7 @@ impl Global {
trace_path, trace_path,
) { ) {
Ok(device) => device, Ok(device) => device,
Err(e) => break e, Err(e) => break 'error e,
}; };
let (device_id, _) = devices_fid.assign(Arc::new(device)); let (device_id, _) = devices_fid.assign(Arc::new(device));
resource_log!("Created Device {:?}", device_id); resource_log!("Created Device {:?}", device_id);

View File

@ -20,8 +20,6 @@
#![allow( #![allow(
// It is much clearer to assert negative conditions with eq! false // It is much clearer to assert negative conditions with eq! false
clippy::bool_assert_comparison, clippy::bool_assert_comparison,
// We use loops for getting early-out of scope without closures.
clippy::never_loop,
// We don't use syntax sugar where it's not necessary. // We don't use syntax sugar where it's not necessary.
clippy::match_like_matches_macro, clippy::match_like_matches_macro,
// Redundant matching is more explicit. // Redundant matching is more explicit.

View File

@ -209,8 +209,6 @@
clippy::arc_with_non_send_sync, clippy::arc_with_non_send_sync,
// for `if_then_panic` until it reaches stable // for `if_then_panic` until it reaches stable
unknown_lints, unknown_lints,
// We use loops for getting early-out of scope without closures.
clippy::never_loop,
// We don't use syntax sugar where it's not necessary. // We don't use syntax sugar where it's not necessary.
clippy::match_like_matches_macro, clippy::match_like_matches_macro,
// Redundant matching is more explicit. // Redundant matching is more explicit.