From e0d4ff38ab589197a61cc032a52f3893e2c727c6 Mon Sep 17 00:00:00 2001 From: "@brody4hire - C. Jonathan Brody" Date: Wed, 22 Jan 2025 13:05:06 -0500 Subject: [PATCH] resolve clippy::unwrap_used in re_viewer --- crates/viewer/re_viewer/src/app.rs | 36 ++++++++++--------- crates/viewer/re_viewer/src/app_blueprint.rs | 6 ++-- .../viewer/re_viewer/src/background_tasks.rs | 5 ++- crates/viewer/re_viewer/src/lib.rs | 5 +-- 4 files changed, 28 insertions(+), 24 deletions(-) diff --git a/crates/viewer/re_viewer/src/app.rs b/crates/viewer/re_viewer/src/app.rs index e8b8013ae8f81..33b63b7aa65a1 100644 --- a/crates/viewer/re_viewer/src/app.rs +++ b/crates/viewer/re_viewer/src/app.rs @@ -1150,11 +1150,11 @@ impl App { self.egui_debug_panel_ui(ui); - // TODO(andreas): store the re_renderer somewhere else. - let egui_renderer = { - let render_state = frame.wgpu_render_state().unwrap(); - &mut render_state.renderer.write() - }; + let egui_renderer = &mut frame + .wgpu_render_state() + .expect("Failed to get frame render state") + .renderer + .write(); if let Some(render_ctx) = egui_renderer .callback_resources @@ -1836,7 +1836,7 @@ impl eframe::App for App { } // Temporarily take the `StoreHub` out of the Viewer so it doesn't interfere with mutability - let mut store_hub = self.store_hub.take().unwrap(); + let mut store_hub = self.store_hub.take().expect("Failed to take store hub"); #[cfg(not(target_arch = "wasm32"))] if let Some(resolution_in_points) = self.startup_options.resolution_in_points.take() { @@ -1884,14 +1884,16 @@ impl eframe::App for App { let gpu_resource_stats = { re_tracing::profile_scope!("gpu_resource_stats"); - let egui_renderer = { - let render_state = frame.wgpu_render_state().unwrap(); - &mut render_state.renderer.read() - }; + let egui_renderer = frame + .wgpu_render_state() + .expect("Failed to get frame render state") + .renderer + .read(); + let render_ctx = egui_renderer .callback_resources .get::() - .unwrap(); + .expect("Failed to get render context"); // Query statistics before begin_frame as this might be more accurate if there's resources that we recreate every frame. render_ctx.gpu_resources.statistics() @@ -1910,14 +1912,16 @@ impl eframe::App for App { self.purge_memory_if_needed(&mut store_hub); { - let egui_renderer = { - let render_state = frame.wgpu_render_state().unwrap(); - &mut render_state.renderer.read() - }; + let egui_renderer = frame + .wgpu_render_state() + .expect("Failed to get frame render state") + .renderer + .read(); + let render_ctx = egui_renderer .callback_resources .get::() - .unwrap(); + .expect("Failed to get render context"); // We haven't called `begin_frame` at this point, so pretend we did and add one to the active frame index. let renderer_active_frame_idx = render_ctx.active_frame_idx().wrapping_add(1); diff --git a/crates/viewer/re_viewer/src/app_blueprint.rs b/crates/viewer/re_viewer/src/app_blueprint.rs index 83114f2d96c03..0be8a59be189a 100644 --- a/crates/viewer/re_viewer/src/app_blueprint.rs +++ b/crates/viewer/re_viewer/src/app_blueprint.rs @@ -197,11 +197,11 @@ pub fn setup_welcome_screen_blueprint(welcome_screen_blueprint: &mut EntityDb) { let chunk = Chunk::builder(entity_path) .with_component_batches(RowId::new(), timepoint, [&value as &dyn ComponentBatch]) .build() - .unwrap(); // Can only fail if we have the wrong number of instances for the component, and we don't + .expect("Failed to build chunk - incorrect number of instances for the component (internal error)"); welcome_screen_blueprint .add_chunk(&Arc::new(chunk)) - .unwrap(); // Can only fail if we have the wrong number of instances for the component, and we don't + .expect("Failed to add new chunk for welcome screen - internal error"); } } @@ -222,7 +222,7 @@ impl AppBlueprint<'_> { let chunk = Chunk::builder(entity_path) .with_component_batches(RowId::new(), timepoint, [&value as &dyn ComponentBatch]) .build() - .unwrap(); // Can only fail if we have the wrong number of instances for the component, and we don't + .expect("Failed to build chunk - incorrect number of instances for the component (internal error)"); command_sender.send_system(SystemCommand::UpdateBlueprint( store_ctx.blueprint.store_id().clone(), diff --git a/crates/viewer/re_viewer/src/background_tasks.rs b/crates/viewer/re_viewer/src/background_tasks.rs index 223aade7b8e2f..498a405b32852 100644 --- a/crates/viewer/re_viewer/src/background_tasks.rs +++ b/crates/viewer/re_viewer/src/background_tasks.rs @@ -60,7 +60,10 @@ impl BackgroundTasks { self.promises .remove(name.as_ref()) .and_then(|promise| match promise.try_take() { - Ok(any) => Some(*any.downcast::().unwrap()), + Ok(any) => Some( + *any.downcast::() + .unwrap_or_else(|err| panic!("downcast failure: {err:?}")), + ), Err(promise) => { self.promises.insert(name.as_ref().to_owned(), promise); None diff --git a/crates/viewer/re_viewer/src/lib.rs b/crates/viewer/re_viewer/src/lib.rs index 85d5e1baa9ff6..c1802d1e46b88 100644 --- a/crates/viewer/re_viewer/src/lib.rs +++ b/crates/viewer/re_viewer/src/lib.rs @@ -3,9 +3,6 @@ //! This crate contains all the GUI code for the Rerun Viewer, //! including all 2D and 3D visualization code. -// TODO(#6330): remove unwrap() -#![allow(clippy::unwrap_used)] - mod app; mod app_blueprint; mod app_state; @@ -243,7 +240,7 @@ pub fn wake_up_ui_thread_on_each_msg( } re_log::trace!("Shutting down ui_waker thread"); }) - .unwrap(); + .expect("Failed to spawn UI waker thread"); new_rx }