Skip to content

Commit

Permalink
resolve clippy::unwrap_used in re_viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
brody4hire committed Jan 22, 2025
1 parent 1c51788 commit e0d4ff3
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 24 deletions.
36 changes: 20 additions & 16 deletions crates/viewer/re_viewer/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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::<re_renderer::RenderContext>()
.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()
Expand All @@ -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::<re_renderer::RenderContext>()
.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);
Expand Down
6 changes: 3 additions & 3 deletions crates/viewer/re_viewer/src/app_blueprint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}

Expand All @@ -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(),
Expand Down
5 changes: 4 additions & 1 deletion crates/viewer/re_viewer/src/background_tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ impl BackgroundTasks {
self.promises
.remove(name.as_ref())
.and_then(|promise| match promise.try_take() {
Ok(any) => Some(*any.downcast::<T>().unwrap()),
Ok(any) => Some(
*any.downcast::<T>()
.unwrap_or_else(|err| panic!("downcast failure: {err:?}")),
),
Err(promise) => {
self.promises.insert(name.as_ref().to_owned(), promise);
None
Expand Down
5 changes: 1 addition & 4 deletions crates/viewer/re_viewer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -243,7 +240,7 @@ pub fn wake_up_ui_thread_on_each_msg<T: Send + 'static>(
}
re_log::trace!("Shutting down ui_waker thread");
})
.unwrap();
.expect("Failed to spawn UI waker thread");
new_rx
}

Expand Down

0 comments on commit e0d4ff3

Please sign in to comment.