From 3024c39eaf439e6ad0b35ae395ba26003948cdd9 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Fri, 8 Aug 2025 09:57:53 +0200 Subject: [PATCH] Enable and fix some more clippy lints (#7426) One can never have too many lints --- Cargo.toml | 16 +++++++++++++- crates/ecolor/src/hsva.rs | 2 +- crates/eframe/src/epi.rs | 19 ++++++++-------- crates/eframe/src/native/glow_integration.rs | 12 ++++++---- crates/eframe/src/native/run.rs | 6 ++--- crates/eframe/src/native/wgpu_integration.rs | 21 ++++++++---------- crates/egui-wgpu/src/renderer.rs | 2 +- crates/egui-wgpu/src/winit.rs | 2 +- crates/egui-winit/src/lib.rs | 4 ++-- crates/egui/src/containers/popup.rs | 2 +- crates/egui/src/containers/scroll_area.rs | 4 ++-- crates/egui/src/containers/window.rs | 2 +- crates/egui/src/context.rs | 2 +- crates/egui/src/data/output.rs | 2 +- crates/egui/src/interaction.rs | 2 +- crates/egui/src/layout.rs | 4 ++-- crates/egui/src/memory/mod.rs | 22 ++++++++----------- crates/egui/src/menu.rs | 5 ++--- crates/egui/src/style.rs | 2 +- crates/egui/src/widgets/button.rs | 2 +- crates/egui/src/widgets/label.rs | 2 +- crates/egui/src/widgets/slider.rs | 4 ++-- .../egui_demo_app/src/apps/fractal_clock.rs | 2 +- crates/egui_demo_app/src/apps/image_viewer.rs | 2 +- crates/egui_demo_app/src/main.rs | 2 +- .../src/demo/misc_demo_window.rs | 4 ++-- crates/egui_demo_lib/src/demo/paint_bezier.rs | 2 +- .../src/easy_mark/easy_mark_editor.rs | 2 +- .../src/easy_mark/easy_mark_viewer.rs | 2 +- crates/egui_extras/src/datepicker/popup.rs | 2 +- crates/egui_glow/src/painter.rs | 2 +- crates/egui_kittest/src/snapshot.rs | 19 +++++++++++----- crates/egui_kittest/tests/menu.rs | 2 +- crates/egui_kittest/tests/tests.rs | 2 +- crates/emath/src/align.rs | 2 +- crates/emath/src/rect.rs | 4 ++-- crates/emath/src/smart_aim.rs | 2 +- crates/emath/src/ts_transform.rs | 2 +- examples/puffin_profiler/src/main.rs | 2 +- examples/screenshot/src/main.rs | 2 +- xtask/src/utils.rs | 2 +- 41 files changed, 107 insertions(+), 91 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b6b6b262..67ee191b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -159,8 +159,8 @@ disallowed_types = "warn" # See clippy.toml doc_link_with_quotes = "warn" doc_markdown = "warn" empty_enum = "warn" -empty_line_after_outer_attr = "warn" empty_enum_variants_with_brackets = "warn" +empty_line_after_outer_attr = "warn" enum_glob_use = "warn" equatable_if_let = "warn" exit = "warn" @@ -180,6 +180,7 @@ if_let_mutex = "warn" implicit_clone = "warn" implied_bounds_in_impls = "warn" imprecise_flops = "warn" +inconsistent_struct_constructor = "warn" index_refutable_slice = "warn" inefficient_to_string = "warn" infinite_loop = "warn" @@ -295,8 +296,21 @@ verbose_file_reads = "warn" wildcard_dependencies = "warn" zero_sized_map_values = "warn" +# Enable these when we update MSRV: +# doc_comment_double_space_linebreaks = "warn" +# elidable_lifetime_names = "warn" +# ignore_without_reason = "warn" +# manual_midpoint = "warn" +# non_std_lazy_statics = "warn" +# precedence_bits = "warn" +# return_and_then = "warn" +# single_option_map = "warn" +# unnecessary_debug_formatting = "warn" +# unnecessary_semicolon = "warn" + # TODO(emilk): maybe enable more of these lints? +comparison_chain = "allow" should_panic_without_expect = "allow" too_many_lines = "allow" unwrap_used = "allow" # TODO(emilk): We really wanna warn on this one diff --git a/crates/ecolor/src/hsva.rs b/crates/ecolor/src/hsva.rs index 97aed1b5..06adb121 100644 --- a/crates/ecolor/src/hsva.rs +++ b/crates/ecolor/src/hsva.rs @@ -234,7 +234,7 @@ pub fn rgb_from_hsv((h, s, v): (f32, f32, f32)) -> [f32; 3] { } #[test] -#[ignore] // a bit expensive +#[ignore = "too expensive"] fn test_hsv_roundtrip() { for r in 0..=255 { for g in 0..=255 { diff --git a/crates/eframe/src/epi.rs b/crates/eframe/src/epi.rs index 3e602327..4b5e69d1 100644 --- a/crates/eframe/src/epi.rs +++ b/crates/eframe/src/epi.rs @@ -893,16 +893,15 @@ pub trait Storage { #[cfg(feature = "ron")] pub fn get_value(storage: &dyn Storage, key: &str) -> Option { profiling::function_scope!(key); - storage - .get_string(key) - .and_then(|value| match ron::from_str(&value) { - Ok(value) => Some(value), - Err(err) => { - // This happens on when we break the format, e.g. when updating egui. - log::debug!("Failed to decode RON: {err}"); - None - } - }) + let value = storage.get_string(key)?; + match ron::from_str(&value) { + Ok(value) => Some(value), + Err(err) => { + // This happens on when we break the format, e.g. when updating egui. + log::debug!("Failed to decode RON: {err}"); + None + } + } } /// Serialize the given value as [RON](https://github.com/ron-rs/ron) and store with the given key. diff --git a/crates/eframe/src/native/glow_integration.rs b/crates/eframe/src/native/glow_integration.rs index 66130884..4a1df9e1 100644 --- a/crates/eframe/src/native/glow_integration.rs +++ b/crates/eframe/src/native/glow_integration.rs @@ -336,10 +336,10 @@ impl<'app> GlowWinitApp<'app> { } Ok(self.running.insert(GlowWinitRunning { - glutin, - painter, integration, app, + glutin, + painter, })) } } @@ -362,8 +362,12 @@ impl WinitApp for GlowWinitApp<'_> { fn window_id_from_viewport_id(&self, id: ViewportId) -> Option { self.running - .as_ref() - .and_then(|r| r.glutin.borrow().window_from_viewport.get(&id).copied()) + .as_ref()? + .glutin + .borrow() + .window_from_viewport + .get(&id) + .copied() } fn save(&mut self) { diff --git a/crates/eframe/src/native/run.rs b/crates/eframe/src/native/run.rs index 9c31aefe..d21731bd 100644 --- a/crates/eframe/src/native/run.rs +++ b/crates/eframe/src/native/run.rs @@ -145,7 +145,7 @@ impl WinitAppWrapper { log::error!("Exiting because of error: {err}"); exit = true; self.return_result = Err(err); - }; + } if save { log::debug!("Received an EventResult::Save - saving app state"); @@ -176,7 +176,7 @@ impl WinitAppWrapper { .retain(|window_id, repaint_time| { if now < *repaint_time { return true; // not yet ready - }; + } event_loop.set_control_flow(ControlFlow::Poll); @@ -192,7 +192,7 @@ impl WinitAppWrapper { let next_repaint_time = self.windows_next_repaint_times.values().min().copied(); if let Some(next_repaint_time) = next_repaint_time { event_loop.set_control_flow(ControlFlow::WaitUntil(next_repaint_time)); - }; + } } } diff --git a/crates/eframe/src/native/wgpu_integration.rs b/crates/eframe/src/native/wgpu_integration.rs index 0bf4fb5c..1d06e672 100644 --- a/crates/eframe/src/native/wgpu_integration.rs +++ b/crates/eframe/src/native/wgpu_integration.rs @@ -333,10 +333,8 @@ impl WinitApp for WgpuWinitApp<'_> { .as_ref() .and_then(|r| { let shared = r.shared.borrow(); - shared - .viewport_from_window - .get(&window_id) - .and_then(|id| shared.viewports.get(id).map(|v| v.window.clone())) + let id = shared.viewport_from_window.get(&window_id)?; + shared.viewports.get(id).map(|v| v.window.clone()) }) .flatten() } @@ -821,17 +819,16 @@ impl WgpuWinitRunning<'_> { } _ => {} - }; + } let event_response = viewport_id .and_then(|viewport_id| { - shared.viewports.get_mut(&viewport_id).and_then(|viewport| { - Some(integration.on_window_event( - viewport.window.as_deref()?, - viewport.egui_winit.as_mut()?, - event, - )) - }) + let viewport = shared.viewports.get_mut(&viewport_id)?; + Some(integration.on_window_event( + viewport.window.as_deref()?, + viewport.egui_winit.as_mut()?, + event, + )) }) .unwrap_or_default(); diff --git a/crates/egui-wgpu/src/renderer.rs b/crates/egui-wgpu/src/renderer.rs index 012613ae..a626c8ef 100644 --- a/crates/egui-wgpu/src/renderer.rs +++ b/crates/egui-wgpu/src/renderer.rs @@ -873,7 +873,7 @@ impl Renderer { callbacks.push(c.0.as_ref()); } else { log::warn!("Unknown paint callback: expected `egui_wgpu::Callback`"); - }; + } acc } } diff --git a/crates/egui-wgpu/src/winit.rs b/crates/egui-wgpu/src/winit.rs index cd02b59d..800d67c3 100644 --- a/crates/egui-wgpu/src/winit.rs +++ b/crates/egui-wgpu/src/winit.rs @@ -328,7 +328,7 @@ impl Painter { }) .create_view(&wgpu::TextureViewDescriptor::default()), ); - }; + } } pub fn on_window_resized( diff --git a/crates/egui-winit/src/lib.rs b/crates/egui-winit/src/lib.rs index 65612b49..688d452c 100644 --- a/crates/egui-winit/src/lib.rs +++ b/crates/egui-winit/src/lib.rs @@ -372,7 +372,7 @@ impl State { winit::event::Ime::Disabled | winit::event::Ime::Preedit(_, None) => { self.ime_event_disable(); } - }; + } EventResponse { repaint: true, @@ -583,7 +583,7 @@ impl State { pos, force: None, }); - }; + } } } } diff --git a/crates/egui/src/containers/popup.rs b/crates/egui/src/containers/popup.rs index 535ffc35..e8c0ac59 100644 --- a/crates/egui/src/containers/popup.rs +++ b/crates/egui/src/containers/popup.rs @@ -458,7 +458,7 @@ impl<'a> Popup<'a> { /// Get the expected size of the popup. pub fn get_expected_size(&self) -> Option { - AreaState::load(&self.ctx, self.id).and_then(|area| area.size) + AreaState::load(&self.ctx, self.id)?.size } /// Calculate the best alignment for the popup, based on the last size and screen rect. diff --git a/crates/egui/src/containers/scroll_area.rs b/crates/egui/src/containers/scroll_area.rs index 45599ac8..dbefe018 100644 --- a/crates/egui/src/containers/scroll_area.rs +++ b/crates/egui/src/containers/scroll_area.rs @@ -1059,7 +1059,7 @@ impl Prepared { delta += delta_update; animation = animation_update; - }; + } if delta != 0.0 { let target_offset = state.offset[d] + delta; @@ -1090,7 +1090,7 @@ impl Prepared { for d in 0..2 { if saved_scroll_target[d].is_some() { state.scroll_target[d] = saved_scroll_target[d].clone(); - }; + } } }); diff --git a/crates/egui/src/containers/window.rs b/crates/egui/src/containers/window.rs index e93b046e..39190d7a 100644 --- a/crates/egui/src/containers/window.rs +++ b/crates/egui/src/containers/window.rs @@ -616,7 +616,7 @@ impl Window<'_> { *where_to_put_header_background, RectShape::filled(title_bar.inner_rect, round, header_color), ); - }; + } if false { ctx.debug_painter().debug_rect( diff --git a/crates/egui/src/context.rs b/crates/egui/src/context.rs index 859835da..a48de514 100644 --- a/crates/egui/src/context.rs +++ b/crates/egui/src/context.rs @@ -1259,7 +1259,7 @@ impl Context { viewport.this_pass.scroll_delta.0 += DISTANCE * Vec2::RIGHT; } _ => return false, - }; + } true }); }); diff --git a/crates/egui/src/data/output.rs b/crates/egui/src/data/output.rs index 76c3de5f..809fae34 100644 --- a/crates/egui/src/data/output.rs +++ b/crates/egui/src/data/output.rs @@ -729,7 +729,7 @@ impl WidgetInfo { description = format!("{state} {description}"); } else { description += if *selected { "selected" } else { "" }; - }; + } } if let Some(label) = label { diff --git a/crates/egui/src/interaction.rs b/crates/egui/src/interaction.rs index 9cd76b3a..d81291a6 100644 --- a/crates/egui/src/interaction.rs +++ b/crates/egui/src/interaction.rs @@ -293,7 +293,7 @@ pub(crate) fn interact( drag_started, dragged, drag_stopped, - contains_pointer, hovered, + contains_pointer, } } diff --git a/crates/egui/src/layout.rs b/crates/egui/src/layout.rs index 601d1e2e..c44c928b 100644 --- a/crates/egui/src/layout.rs +++ b/crates/egui/src/layout.rs @@ -753,7 +753,7 @@ impl Layout { pos2(frame_rect.max.x, f32::NAN), ); } - }; + } } } else { // Make sure we also expand where we consider adding things (the cursor): @@ -779,7 +779,7 @@ impl Layout { Direction::BottomUp => { cursor.max.y = widget_rect.min.y - item_spacing.y; } - }; + } } /// Move to the next row in a wrapping layout. diff --git a/crates/egui/src/memory/mod.rs b/crates/egui/src/memory/mod.rs index 45894f3f..349ebcea 100644 --- a/crates/egui/src/memory/mod.rs +++ b/crates/egui/src/memory/mod.rs @@ -802,15 +802,12 @@ impl Memory { /// Top-most layer at the given position. pub fn layer_id_at(&self, pos: Pos2) -> Option { - self.areas() - .layer_id_at(pos, &self.to_global) - .and_then(|layer_id| { - if self.is_above_modal_layer(layer_id) { - Some(layer_id) - } else { - self.top_modal_layer() - } - }) + let layer_id = self.areas().layer_id_at(pos, &self.to_global)?; + if self.is_above_modal_layer(layer_id) { + Some(layer_id) + } else { + self.top_modal_layer() + } } /// The currently set transform of a layer. @@ -855,7 +852,7 @@ impl Memory { /// Which widget has keyboard focus? pub fn focused(&self) -> Option { - self.focus().and_then(|f| f.focused()) + self.focus()?.focused() } /// Set an event filter for a widget. @@ -1066,9 +1063,8 @@ impl Memory { /// Get the position for this popup. #[deprecated = "Use Popup::position_of_id instead"] pub fn popup_position(&self, id: Id) -> Option { - self.popups - .get(&self.viewport_id) - .and_then(|state| if state.id == id { state.pos } else { None }) + let state = self.popups.get(&self.viewport_id)?; + if state.id == id { state.pos } else { None } } /// Close any currently open popup. diff --git a/crates/egui/src/menu.rs b/crates/egui/src/menu.rs index f245473d..f9744bd5 100644 --- a/crates/egui/src/menu.rs +++ b/crates/egui/src/menu.rs @@ -766,9 +766,8 @@ impl MenuState { } fn submenu(&self, id: Id) -> Option<&Arc>> { - self.sub_menu - .as_ref() - .and_then(|(k, sub)| if id == *k { Some(sub) } else { None }) + let (k, sub) = self.sub_menu.as_ref()?; + if id == *k { Some(sub) } else { None } } /// Open submenu at position, if not already open. diff --git a/crates/egui/src/style.rs b/crates/egui/src/style.rs index 364b3fff..68491d2d 100644 --- a/crates/egui/src/style.rs +++ b/crates/egui/src/style.rs @@ -2136,7 +2136,7 @@ impl Visuals { ui.color_edit_button_srgba(color); } else { *color = None; - }; + } }); ui.end_row(); diff --git a/crates/egui/src/widgets/button.rs b/crates/egui/src/widgets/button.rs index d836c070..fef32da3 100644 --- a/crates/egui/src/widgets/button.rs +++ b/crates/egui/src/widgets/button.rs @@ -325,7 +325,7 @@ impl<'a> Button<'a> { .fill(fill) .stroke(stroke) .corner_radius(corner_radius.unwrap_or(visuals.corner_radius)); - }; + } prepared.paint(ui) } else { diff --git a/crates/egui/src/widgets/label.rs b/crates/egui/src/widgets/label.rs index 1abac788..007a1291 100644 --- a/crates/egui/src/widgets/label.rs +++ b/crates/egui/src/widgets/label.rs @@ -250,7 +250,7 @@ impl Label { } else { layout_job.halign = self.halign.unwrap_or(ui.layout().horizontal_placement()); layout_job.justify = ui.layout().horizontal_justify(); - }; + } let galley = ui.fonts(|fonts| fonts.layout_job(layout_job)); let (rect, mut response) = ui.allocate_exact_size(galley.size(), sense); diff --git a/crates/egui/src/widgets/slider.rs b/crates/egui/src/widgets/slider.rs index 777c2eed..7937e589 100644 --- a/crates/egui/src/widgets/slider.rs +++ b/crates/egui/src/widgets/slider.rs @@ -806,7 +806,7 @@ impl Slider<'_> { SliderOrientation::Vertical => { trailing_rail_rect.min.y = center.y - corner_radius.se as f32; } - }; + } ui.painter().rect_filled( trailing_rail_rect, @@ -936,7 +936,7 @@ impl Slider<'_> { if let Some(fmt) = &self.custom_formatter { dv = dv.custom_formatter(fmt); - }; + } if let Some(parser) = &self.custom_parser { dv = dv.custom_parser(parser); } diff --git a/crates/egui_demo_app/src/apps/fractal_clock.rs b/crates/egui_demo_app/src/apps/fractal_clock.rs index 50d9ae5e..52a7f25b 100644 --- a/crates/egui_demo_app/src/apps/fractal_clock.rs +++ b/crates/egui_demo_app/src/apps/fractal_clock.rs @@ -73,7 +73,7 @@ impl FractalClock { )); } else { ui.label("The fractal_clock clock is not showing the correct time"); - }; + } ui.label(format!("Painted line count: {}", self.line_count)); ui.checkbox(&mut self.paused, "Paused"); diff --git a/crates/egui_demo_app/src/apps/image_viewer.rs b/crates/egui_demo_app/src/apps/image_viewer.rs index 75ff2719..16e380e8 100644 --- a/crates/egui_demo_app/src/apps/image_viewer.rs +++ b/crates/egui_demo_app/src/apps/image_viewer.rs @@ -61,7 +61,7 @@ impl eframe::App for ImageViewer { ctx.forget_image(&self.current_uri); self.uri_edit_text = self.uri_edit_text.trim().to_owned(); self.current_uri = self.uri_edit_text.clone(); - }; + } #[cfg(not(target_arch = "wasm32"))] if ui.button("file…").clicked() { diff --git a/crates/egui_demo_app/src/main.rs b/crates/egui_demo_app/src/main.rs index 099d16f5..48825715 100644 --- a/crates/egui_demo_app/src/main.rs +++ b/crates/egui_demo_app/src/main.rs @@ -91,5 +91,5 @@ fn start_puffin_server() { Err(err) => { log::error!("Failed to start puffin server: {err}"); } - }; + } } diff --git a/crates/egui_demo_lib/src/demo/misc_demo_window.rs b/crates/egui_demo_lib/src/demo/misc_demo_window.rs index 5af27d5e..b5a2402b 100644 --- a/crates/egui_demo_lib/src/demo/misc_demo_window.rs +++ b/crates/egui_demo_lib/src/demo/misc_demo_window.rs @@ -805,7 +805,7 @@ impl TextRotation { if let egui::epaint::Shape::Text(ts) = &mut t { let new = ts.clone().with_angle_and_anchor(self.angle, self.align); *ts = new; - }; + } t }); @@ -814,7 +814,7 @@ impl TextRotation { let align_pt = rect.min + start_pos + self.align.pos_in_rect(&ts.galley.rect).to_vec2(); painter.circle(align_pt, 2.0, Color32::RED, (0.0, Color32::RED)); - }; + } painter.rect( rect, diff --git a/crates/egui_demo_lib/src/demo/paint_bezier.rs b/crates/egui_demo_lib/src/demo/paint_bezier.rs index 7017560a..57def359 100644 --- a/crates/egui_demo_lib/src/demo/paint_bezier.rs +++ b/crates/egui_demo_lib/src/demo/paint_bezier.rs @@ -152,7 +152,7 @@ impl PaintBezier { _ => { unreachable!(); } - }; + } painter.add(PathShape::line(points_in_screen, self.aux_stroke)); painter.extend(control_point_shapes); diff --git a/crates/egui_demo_lib/src/easy_mark/easy_mark_editor.rs b/crates/egui_demo_lib/src/easy_mark/easy_mark_editor.rs index d17385a6..47d0beea 100644 --- a/crates/egui_demo_lib/src/easy_mark/easy_mark_editor.rs +++ b/crates/egui_demo_lib/src/easy_mark/easy_mark_editor.rs @@ -165,7 +165,7 @@ fn shortcuts(ui: &Ui, code: &mut dyn TextBuffer, ccursor_range: &mut CCursorRang if ui.input_mut(|i| i.consume_shortcut(&shortcut)) { any_change = true; toggle_surrounding(code, ccursor_range, surrounding); - }; + } } any_change diff --git a/crates/egui_demo_lib/src/easy_mark/easy_mark_viewer.rs b/crates/egui_demo_lib/src/easy_mark/easy_mark_viewer.rs index 13ff7da0..41d99fb8 100644 --- a/crates/egui_demo_lib/src/easy_mark/easy_mark_viewer.rs +++ b/crates/egui_demo_lib/src/easy_mark/easy_mark_viewer.rs @@ -101,7 +101,7 @@ pub fn item_ui(ui: &mut Ui, item: easy_mark::Item<'_>) { Shape::rect_filled(rect, 1.0, code_bg_color), ); } - }; + } } fn rich_text_from_style(text: &str, style: &easy_mark::Style) -> RichText { diff --git a/crates/egui_extras/src/datepicker/popup.rs b/crates/egui_extras/src/datepicker/popup.rs index c63de3a9..d353307b 100644 --- a/crates/egui_extras/src/datepicker/popup.rs +++ b/crates/egui_extras/src/datepicker/popup.rs @@ -336,7 +336,7 @@ impl DatePickerPopup<'_> { if day.month() != popup_state.month { text_color = text_color.linear_multiply(0.5); - }; + } let button_response = ui.add( Button::new( diff --git a/crates/egui_glow/src/painter.rs b/crates/egui_glow/src/painter.rs index 03372f7a..8409765d 100644 --- a/crates/egui_glow/src/painter.rs +++ b/crates/egui_glow/src/painter.rs @@ -528,7 +528,7 @@ impl Painter { self.upload_texture_srgb(delta.pos, image.size, delta.options, data); } - }; + } } fn upload_texture_srgb( diff --git a/crates/egui_kittest/src/snapshot.rs b/crates/egui_kittest/src/snapshot.rs index c27a1488..6f565166 100644 --- a/crates/egui_kittest/src/snapshot.rs +++ b/crates/egui_kittest/src/snapshot.rs @@ -232,7 +232,8 @@ impl Display for SnapshotError { let diff_path = std::path::absolute(diff_path).unwrap_or(diff_path.clone()); write!( f, - "'{name}' Image did not match snapshot. Diff: {diff}, {diff_path:?}. {HOW_TO_UPDATE_SCREENSHOTS}" + "'{name}' Image did not match snapshot. Diff: {diff}, {}. {HOW_TO_UPDATE_SCREENSHOTS}", + diff_path.display() ) } Self::OpenSnapshot { path, err } => { @@ -240,19 +241,25 @@ impl Display for SnapshotError { match err { ImageError::IoError(io) => match io.kind() { ErrorKind::NotFound => { - write!(f, "Missing snapshot: {path:?}. {HOW_TO_UPDATE_SCREENSHOTS}") + write!( + f, + "Missing snapshot: {}. {HOW_TO_UPDATE_SCREENSHOTS}", + path.display() + ) } err => { write!( f, - "Error reading snapshot: {err:?}\nAt: {path:?}. {HOW_TO_UPDATE_SCREENSHOTS}" + "Error reading snapshot: {err:?}\nAt: {}. {HOW_TO_UPDATE_SCREENSHOTS}", + path.display() ) } }, err => { write!( f, - "Error decoding snapshot: {err:?}\nAt: {path:?}. Make sure git-lfs is setup correctly. Read the instructions here: https://github.com/emilk/egui/blob/main/CONTRIBUTING.md#making-a-pr" + "Error decoding snapshot: {err:?}\nAt: {}. Make sure git-lfs is setup correctly. Read the instructions here: https://github.com/emilk/egui/blob/main/CONTRIBUTING.md#making-a-pr", + path.display() ) } } @@ -269,7 +276,7 @@ impl Display for SnapshotError { } Self::WriteSnapshot { path, err } => { let path = std::path::absolute(path).unwrap_or(path.clone()); - write!(f, "Error writing snapshot: {err:?}\nAt: {path:?}") + write!(f, "Error writing snapshot: {err:?}\nAt: {}", path.display()) } Self::RenderError { err } => { write!(f, "Error rendering image: {err:?}") @@ -363,7 +370,7 @@ fn try_image_snapshot_options_impl( // No need for an explicit `.new` file: std::fs::remove_file(&new_path).ok(); - println!("Updated snapshot: {snapshot_path:?}"); + println!("Updated snapshot: {}", snapshot_path.display()); Ok(()) }; diff --git a/crates/egui_kittest/tests/menu.rs b/crates/egui_kittest/tests/menu.rs index b7d00130..a76001e4 100644 --- a/crates/egui_kittest/tests/menu.rs +++ b/crates/egui_kittest/tests/menu.rs @@ -50,7 +50,7 @@ impl TestMenu { .clicked() { ui.close(); - }; + } }); }); }); diff --git a/crates/egui_kittest/tests/tests.rs b/crates/egui_kittest/tests/tests.rs index 6d66c5f5..8ff6584a 100644 --- a/crates/egui_kittest/tests/tests.rs +++ b/crates/egui_kittest/tests/tests.rs @@ -93,7 +93,7 @@ fn test_scroll_harness() -> Harness<'static, bool> { } if ui.button("Hidden Button").clicked() { *state = true; - }; + } }); }, false, diff --git a/crates/emath/src/align.rs b/crates/emath/src/align.rs index a672c456..9604855e 100644 --- a/crates/emath/src/align.rs +++ b/crates/emath/src/align.rs @@ -134,7 +134,7 @@ impl Align { if size == f32::INFINITY { Rangef::new(f32::NEG_INFINITY, f32::INFINITY) } else { - let left = (min + max) / 2.0 - size / 2.0; + let left = f32::midpoint(min, max) - size / 2.0; Rangef::new(left, left + size) } } diff --git a/crates/emath/src/rect.rs b/crates/emath/src/rect.rs index b9e45c52..7731a5ce 100644 --- a/crates/emath/src/rect.rs +++ b/crates/emath/src/rect.rs @@ -331,8 +331,8 @@ impl Rect { #[inline(always)] pub fn center(&self) -> Pos2 { Pos2 { - x: (self.min.x + self.max.x) / 2.0, - y: (self.min.y + self.max.y) / 2.0, + x: f32::midpoint(self.min.x, self.max.x), + y: f32::midpoint(self.min.y, self.max.y), } } diff --git a/crates/emath/src/smart_aim.rs b/crates/emath/src/smart_aim.rs index e75ae42c..a3181647 100644 --- a/crates/emath/src/smart_aim.rs +++ b/crates/emath/src/smart_aim.rs @@ -43,7 +43,7 @@ pub fn best_in_range_f64(min: f64, max: f64) -> f64 { if min_exponent.floor() != max_exponent.floor() { // pick the geometric center of the two: - let exponent = (min_exponent + max_exponent) / 2.0; + let exponent = f64::midpoint(min_exponent, max_exponent); return 10.0_f64.powi(exponent.round() as i32); } diff --git a/crates/emath/src/ts_transform.rs b/crates/emath/src/ts_transform.rs index 46c7e2a8..515f5ecd 100644 --- a/crates/emath/src/ts_transform.rs +++ b/crates/emath/src/ts_transform.rs @@ -36,8 +36,8 @@ impl TSTransform { /// `(0, 0)`, then translates them. pub fn new(translation: Vec2, scaling: f32) -> Self { Self { - translation, scaling, + translation, } } diff --git a/examples/puffin_profiler/src/main.rs b/examples/puffin_profiler/src/main.rs index 1386e488..942b57a4 100644 --- a/examples/puffin_profiler/src/main.rs +++ b/examples/puffin_profiler/src/main.rs @@ -177,5 +177,5 @@ fn start_puffin_server() { Err(err) => { log::error!("Failed to start puffin server: {err}"); } - }; + } } diff --git a/examples/screenshot/src/main.rs b/examples/screenshot/src/main.rs index 1dd0bbf5..0cff59a9 100644 --- a/examples/screenshot/src/main.rs +++ b/examples/screenshot/src/main.rs @@ -57,7 +57,7 @@ impl eframe::App for MyApp { ctx.set_theme(egui::Theme::Dark); } else { ctx.set_theme(egui::Theme::Light); - }; + } ctx.send_viewport_cmd( egui::ViewportCommand::Screenshot(Default::default()), ); diff --git a/xtask/src/utils.rs b/xtask/src/utils.rs index afefa605..b45295ae 100644 --- a/xtask/src/utils.rs +++ b/xtask/src/utils.rs @@ -32,7 +32,7 @@ pub fn ask_to_run(mut cmd: Command, ask: bool, reason: &str) -> Result<(), DynEr "" | "y" | "yes" => {} "n" | "no" => return Err("Aborting as per your request".into()), a => return Err(format!("Invalid answer `{a}`").into()), - }; + } } else { println!("Running `{cmd:?}` to {reason}."); }