mirror of
https://github.com/gfx-rs/wgpu.git
synced 2024-11-22 06:44:14 +00:00
[core] Use expect
instead of "if let else panic". (#5513)
Use `Option::expect` to check the result from `Arc::into_inner`, rather than `if let Some ... else panic!`.
This commit is contained in:
parent
82dead09e4
commit
f8deb0317f
@ -286,11 +286,9 @@ impl<A: HalApi> CommandBuffer<A> {
|
||||
}
|
||||
|
||||
pub(crate) fn from_arc_into_baked(self: Arc<Self>) -> BakedCommands<A> {
|
||||
if let Some(mut command_buffer) = Arc::into_inner(self) {
|
||||
command_buffer.extract_baked_commands()
|
||||
} else {
|
||||
panic!("CommandBuffer cannot be destroyed because is still in use");
|
||||
}
|
||||
let mut command_buffer = Arc::into_inner(self)
|
||||
.expect("CommandBuffer cannot be destroyed because is still in use");
|
||||
command_buffer.extract_baked_commands()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1210,13 +1210,10 @@ impl Global {
|
||||
));
|
||||
}
|
||||
if !cmdbuf.is_finished() {
|
||||
if let Some(cmdbuf) = Arc::into_inner(cmdbuf) {
|
||||
device.destroy_command_buffer(cmdbuf);
|
||||
} else {
|
||||
panic!(
|
||||
"Command buffer cannot be destroyed because is still in use"
|
||||
);
|
||||
}
|
||||
let cmdbuf = Arc::into_inner(cmdbuf).expect(
|
||||
"Command buffer cannot be destroyed because is still in use",
|
||||
);
|
||||
device.destroy_command_buffer(cmdbuf);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -155,11 +155,9 @@ impl Drop for Global {
|
||||
// destroy surfaces
|
||||
for element in surfaces_locked.map.drain(..) {
|
||||
if let Element::Occupied(arc_surface, _) = element {
|
||||
if let Some(surface) = Arc::into_inner(arc_surface) {
|
||||
self.instance.destroy_surface(surface);
|
||||
} else {
|
||||
panic!("Surface cannot be destroyed because is still in use");
|
||||
}
|
||||
let surface = Arc::into_inner(arc_surface)
|
||||
.expect("Surface cannot be destroyed because is still in use");
|
||||
self.instance.destroy_surface(surface);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -667,22 +667,19 @@ impl Global {
|
||||
}
|
||||
|
||||
let surface = self.surfaces.unregister(id);
|
||||
if let Some(surface) = Arc::into_inner(surface.unwrap()) {
|
||||
if let Some(present) = surface.presentation.lock().take() {
|
||||
#[cfg(vulkan)]
|
||||
unconfigure::<hal::api::Vulkan>(self, &surface.raw, &present);
|
||||
#[cfg(metal)]
|
||||
unconfigure::<hal::api::Metal>(self, &surface.raw, &present);
|
||||
#[cfg(dx12)]
|
||||
unconfigure::<hal::api::Dx12>(self, &surface.raw, &present);
|
||||
#[cfg(gles)]
|
||||
unconfigure::<hal::api::Gles>(self, &surface.raw, &present);
|
||||
}
|
||||
|
||||
self.instance.destroy_surface(surface);
|
||||
} else {
|
||||
panic!("Surface cannot be destroyed because is still in use");
|
||||
let surface = Arc::into_inner(surface.unwrap())
|
||||
.expect("Surface cannot be destroyed because is still in use");
|
||||
if let Some(present) = surface.presentation.lock().take() {
|
||||
#[cfg(vulkan)]
|
||||
unconfigure::<hal::api::Vulkan>(self, &surface.raw, &present);
|
||||
#[cfg(metal)]
|
||||
unconfigure::<hal::api::Metal>(self, &surface.raw, &present);
|
||||
#[cfg(dx12)]
|
||||
unconfigure::<hal::api::Dx12>(self, &surface.raw, &present);
|
||||
#[cfg(gles)]
|
||||
unconfigure::<hal::api::Gles>(self, &surface.raw, &present);
|
||||
}
|
||||
self.instance.destroy_surface(surface);
|
||||
}
|
||||
|
||||
fn enumerate<A: HalApi>(
|
||||
|
Loading…
Reference in New Issue
Block a user