diff --git a/crates/bevy_animation/src/lib.rs b/crates/bevy_animation/src/lib.rs index f634d13259159..3ff786930ded7 100644 --- a/crates/bevy_animation/src/lib.rs +++ b/crates/bevy_animation/src/lib.rs @@ -123,9 +123,11 @@ impl VariableCurve { // An Ok(keyframe_index) result means an exact result was found by binary search // An Err result means the keyframe was not found, and the index is the keyframe // PERF: finding the current keyframe can be optimised - let search_result = self - .keyframe_timestamps - .binary_search_by(|probe| probe.partial_cmp(&seek_time).unwrap()); + let search_result = self.keyframe_timestamps.binary_search_by(|probe| { + probe + .partial_cmp(&seek_time) + .expect("provided floats can't be compared") + }); // Subtract one for zero indexing! let last_keyframe = self.keyframe_timestamps.len() - 1; @@ -1187,7 +1189,9 @@ impl AnimationTargetId { for name in names { blake3.update(name.as_bytes()); } - let hash = blake3.finalize().as_bytes()[0..16].try_into().unwrap(); + let hash = blake3.finalize().as_bytes()[0..16] + .try_into() + .expect("failed to convert name into hash"); Self(*uuid::Builder::from_sha1_bytes(hash).as_uuid()) } diff --git a/crates/bevy_app/src/plugin_group.rs b/crates/bevy_app/src/plugin_group.rs index b41a78f067a1a..a03ca8040dd6f 100644 --- a/crates/bevy_app/src/plugin_group.rs +++ b/crates/bevy_app/src/plugin_group.rs @@ -140,7 +140,9 @@ impl PluginGroupBuilder { for plugin_id in order { self.upsert_plugin_entry_state( plugin_id, - plugins.remove(&plugin_id).unwrap(), + plugins + .remove(&plugin_id) + .expect("plugin with provided id not found in group"), self.order.len(), ); diff --git a/crates/bevy_app/src/sub_app.rs b/crates/bevy_app/src/sub_app.rs index b6974cc60f7e0..cd614714576d9 100644 --- a/crates/bevy_app/src/sub_app.rs +++ b/crates/bevy_app/src/sub_app.rs @@ -249,7 +249,9 @@ impl SubApp { schedules.insert(Schedule::new(label)); } - let schedule = schedules.get_mut(label).unwrap(); + let schedule = schedules + .get_mut(label) + .expect("could not get mutable reference to the schedule"); f(schedule); self diff --git a/crates/bevy_asset/src/assets.rs b/crates/bevy_asset/src/assets.rs index b162f3f21b9ea..f39ae43125c07 100644 --- a/crates/bevy_asset/src/assets.rs +++ b/crates/bevy_asset/src/assets.rs @@ -330,7 +330,8 @@ impl Assets { pub fn insert(&mut self, id: impl Into>, asset: A) { match id.into() { AssetId::Index { index, .. } => { - self.insert_with_index(index, asset).unwrap(); + self.insert_with_index(index, asset) + .expect("invalid generation error when inserting asset by id"); } AssetId::Uuid { uuid } => { self.insert_with_uuid(uuid, asset); diff --git a/crates/bevy_winit/src/accessibility.rs b/crates/bevy_winit/src/accessibility.rs index 1764f9cbaa828..db9470328b005 100644 --- a/crates/bevy_winit/src/accessibility.rs +++ b/crates/bevy_winit/src/accessibility.rs @@ -39,7 +39,7 @@ pub struct WinitActionHandler(pub Arc>>); impl ActionHandler for WinitActionHandler { fn do_action(&mut self, request: ActionRequest) { - let mut requests = self.0.lock().unwrap(); + let mut requests = self.0.lock().expect("ActionHandler lock is poisoned"); requests.push_back(request); } } @@ -91,7 +91,7 @@ fn poll_receivers( mut actions: EventWriter, ) { for (_id, handler) in handlers.iter() { - let mut handler = handler.lock().unwrap(); + let mut handler = handler.lock().expect("ActionHandler lock is poisoned"); while let Some(event) = handler.pop_front() { actions.send(ActionRequestWrapper(event)); } diff --git a/crates/bevy_winit/src/lib.rs b/crates/bevy_winit/src/lib.rs index 69008613259d7..6773699662694 100644 --- a/crates/bevy_winit/src/lib.rs +++ b/crates/bevy_winit/src/lib.rs @@ -274,7 +274,7 @@ pub fn winit_runner(mut app: App) -> AppExit { let event_loop = app .world_mut() .remove_non_send_resource::>() - .unwrap(); + .expect("no event loop for user events found in the provided app"); app.world_mut() .insert_non_send_resource(event_loop.create_proxy()); diff --git a/crates/bevy_winit/src/winit_windows.rs b/crates/bevy_winit/src/winit_windows.rs index ecea140f73fea..589b70416d6b7 100644 --- a/crates/bevy_winit/src/winit_windows.rs +++ b/crates/bevy_winit/src/winit_windows.rs @@ -208,7 +208,9 @@ impl WinitWindows { winit_window_builder = winit_window_builder.with_append(true); } - let winit_window = winit_window_builder.build(event_loop).unwrap(); + let winit_window = winit_window_builder + .build(event_loop) + .expect("unable to create winit window"); let name = window.title.clone(); prepare_accessibility_for_window( &winit_window, @@ -281,52 +283,46 @@ pub fn get_fitting_videomode( width: u32, height: u32, ) -> winit::monitor::VideoMode { - let mut modes = monitor.video_modes().collect::>(); - - fn abs_diff(a: u32, b: u32) -> u32 { - if a > b { - return a - b; - } - b - a - } - - modes.sort_by(|a, b| { - use std::cmp::Ordering::*; - match abs_diff(a.size().width, width).cmp(&abs_diff(b.size().width, width)) { - Equal => { - match abs_diff(a.size().height, height).cmp(&abs_diff(b.size().height, height)) { - Equal => b - .refresh_rate_millihertz() - .cmp(&a.refresh_rate_millihertz()), - default => default, - } - } - default => default, - } - }); - - modes.first().unwrap().clone() + monitor + .video_modes() + .min_by(|a, b| { + a.size() + .width + .abs_diff(width) + .cmp(&b.size().width.abs_diff(width)) + .then_with(|| { + a.size() + .height + .abs_diff(height) + .cmp(&b.size().height.abs_diff(height)) + }) + .then_with(|| { + b.refresh_rate_millihertz() + .cmp(&a.refresh_rate_millihertz()) + }) + }) + .expect("no video modes found for monitor") + .clone() } /// Gets the "best" videomode from a monitor. /// /// The heuristic for "best" prioritizes width, height, and refresh rate in that order. pub fn get_best_videomode(monitor: &MonitorHandle) -> winit::monitor::VideoMode { - let mut modes = monitor.video_modes().collect::>(); - modes.sort_by(|a, b| { - use std::cmp::Ordering::*; - match b.size().width.cmp(&a.size().width) { - Equal => match b.size().height.cmp(&a.size().height) { - Equal => b - .refresh_rate_millihertz() - .cmp(&a.refresh_rate_millihertz()), - default => default, - }, - default => default, - } - }); - - modes.first().unwrap().clone() + monitor + .video_modes() + .min_by(|a, b| { + b.size() + .width + .cmp(&a.size().width) + .then_with(|| b.size().height.cmp(&a.size().height)) + .then_with(|| { + b.refresh_rate_millihertz() + .cmp(&a.refresh_rate_millihertz()) + }) + }) + .expect("no video modes found for monitor") + .clone() } pub(crate) fn attempt_grab(winit_window: &winit::window::Window, grab_mode: CursorGrabMode) {