[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:
Jim Blandy 2024-04-10 00:53:10 -07:00 committed by GitHub
parent 82dead09e4
commit f8deb0317f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 22 additions and 32 deletions

View File

@ -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()
}
}

View File

@ -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;
}

View File

@ -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);
}
}
}

View File

@ -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>(