From 46c20810ba110fe72a78989202d196619de4b51d Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Mon, 25 May 2026 10:59:03 +0200 Subject: [PATCH] Remove `impl Into` arguments (#8194) * Closes https://github.com/emilk/egui/issues/8179 --- crates/egui_demo_lib/src/demo/demo_app_windows.rs | 2 +- crates/egui_demo_lib/src/demo/drag_and_drop.rs | 2 +- crates/egui_demo_lib/src/demo/scene.rs | 2 +- crates/egui_glow/examples/pure_glow.rs | 11 +++-------- crates/egui_kittest/src/config.rs | 2 +- crates/egui_kittest/src/lib.rs | 6 +----- crates/egui_kittest/src/snapshot.rs | 5 +++-- crates/epaint/src/stroke.rs | 12 ++++++------ tests/test_viewports/src/main.rs | 2 +- 9 files changed, 18 insertions(+), 26 deletions(-) diff --git a/crates/egui_demo_lib/src/demo/demo_app_windows.rs b/crates/egui_demo_lib/src/demo/demo_app_windows.rs index 7e82d6026..8e59e0933 100644 --- a/crates/egui_demo_lib/src/demo/demo_app_windows.rs +++ b/crates/egui_demo_lib/src/demo/demo_app_windows.rs @@ -418,7 +418,7 @@ mod tests { if name == "Bézier Curve" { // The Bézier Curve demo needs a threshold of 2.1 to pass on linux: - options = options.threshold(OsThreshold::new(0.0).linux(2.1)); + options = options.threshold(OsThreshold::new(0.0_f32).linux(2.1)); } results.add(harness.try_snapshot_options(format!("demos/{name}"), &options)); diff --git a/crates/egui_demo_lib/src/demo/drag_and_drop.rs b/crates/egui_demo_lib/src/demo/drag_and_drop.rs index a891acaae..f1e44b823 100644 --- a/crates/egui_demo_lib/src/demo/drag_and_drop.rs +++ b/crates/egui_demo_lib/src/demo/drag_and_drop.rs @@ -16,7 +16,7 @@ impl Default for DragAndDropDemo { vec!["Item H", "Item I", "Item J", "Item K"], ] .into_iter() - .map(|v| v.into_iter().map(ToString::to_string).collect()) + .map(|v| v.into_iter().map(str::to_owned).collect()) .collect(), } } diff --git a/crates/egui_demo_lib/src/demo/scene.rs b/crates/egui_demo_lib/src/demo/scene.rs index a9791eeb9..0cafba0d2 100644 --- a/crates/egui_demo_lib/src/demo/scene.rs +++ b/crates/egui_demo_lib/src/demo/scene.rs @@ -45,7 +45,7 @@ impl crate::View for SceneDemo { }); ui.separator(); - ui.label(format!("Scene rect: {:#?}", &mut self.scene_rect)); + ui.label(format!("Scene rect: {:#?}", self.scene_rect)); ui.separator(); diff --git a/crates/egui_glow/examples/pure_glow.rs b/crates/egui_glow/examples/pure_glow.rs index 6848d2044..c8ce705c8 100644 --- a/crates/egui_glow/examples/pure_glow.rs +++ b/crates/egui_glow/examples/pure_glow.rs @@ -59,7 +59,7 @@ impl GlutinWindowContext { ) .expect("failed to create gl_config"); let gl_display = gl_config.display(); - log::debug!("found gl_config: {:?}", &gl_config); + log::debug!("found gl_config: {gl_config:?}"); let raw_window_handle = window.as_ref().map(|w| { w.window_handle() @@ -77,9 +77,7 @@ impl GlutinWindowContext { gl_display .create_context(&gl_config, &context_attributes) .unwrap_or_else(|_| { - log::debug!("failed to create gl_context with attributes: {:?}. retrying with fallback context attributes: {:?}", - &context_attributes, - &fallback_context_attributes); + log::debug!("failed to create gl_context with attributes: {context_attributes:?}. retrying with fallback context attributes: {fallback_context_attributes:?}"); gl_config .display() .create_context(&gl_config, &fallback_context_attributes) @@ -106,10 +104,7 @@ impl GlutinWindowContext { width, height, ); - log::debug!( - "creating surface with attributes: {:?}", - &surface_attributes - ); + log::debug!("creating surface with attributes: {surface_attributes:?}"); let gl_surface = unsafe { gl_display .create_window_surface(&gl_config, &surface_attributes) diff --git a/crates/egui_kittest/src/config.rs b/crates/egui_kittest/src/config.rs index a1859f232..a94075973 100644 --- a/crates/egui_kittest/src/config.rs +++ b/crates/egui_kittest/src/config.rs @@ -77,7 +77,7 @@ fn load_config() -> Config { match std::fs::read_to_string(&config_path) { Ok(config_str) => match toml::from_str(&config_str) { Ok(config) => config, - Err(e) => panic!("Failed to parse {}: {e}", &config_path.display()), + Err(e) => panic!("Failed to parse {}: {e}", config_path.display()), }, Err(err) => { panic!("Failed to read {}: {}", config_path.display(), err); diff --git a/crates/egui_kittest/src/lib.rs b/crates/egui_kittest/src/lib.rs index 2b7c4f8f3..4192a103c 100644 --- a/crates/egui_kittest/src/lib.rs +++ b/crates/egui_kittest/src/lib.rs @@ -279,11 +279,7 @@ impl<'a, State> Harness<'a, State> { /// Calculate the rect that includes all popups and tooltips. fn compute_total_rect_with_popups(&self) -> Option { // Start with the standard response rect - let mut used = if let Some(response) = self.response.as_ref() { - response.rect - } else { - return None; - }; + let mut used = self.response.as_ref()?.rect; // Add all visible areas from other orders (popups, tooltips, etc.) self.ctx.memory(|mem| { diff --git a/crates/egui_kittest/src/snapshot.rs b/crates/egui_kittest/src/snapshot.rs index adbe32399..703ebe3f2 100644 --- a/crates/egui_kittest/src/snapshot.rs +++ b/crates/egui_kittest/src/snapshot.rs @@ -173,8 +173,9 @@ impl SnapshotOptions { /// The default is `0.6` (which is enough for most egui tests to pass across different /// wgpu backends). #[inline] - pub fn threshold(mut self, threshold: impl Into) -> Self { - self.threshold = threshold.into(); + pub fn threshold(mut self, threshold: impl Into>) -> Self { + let threshold = threshold.into().threshold(); + self.threshold = threshold; self } diff --git a/crates/epaint/src/stroke.rs b/crates/epaint/src/stroke.rs index 4adb1f309..1b072e4bf 100644 --- a/crates/epaint/src/stroke.rs +++ b/crates/epaint/src/stroke.rs @@ -22,9 +22,9 @@ impl Stroke { }; #[inline] - pub fn new(width: impl Into, color: impl Into) -> Self { + pub fn new(width: f32, color: impl Into) -> Self { Self { - width: width.into(), + width, color: color.into(), } } @@ -136,9 +136,9 @@ impl PathStroke { }; #[inline] - pub fn new(width: impl Into, color: impl Into) -> Self { + pub fn new(width: f32, color: impl Into) -> Self { Self { - width: width.into(), + width, color: ColorMode::Solid(color.into()), kind: StrokeKind::Middle, } @@ -149,11 +149,11 @@ impl PathStroke { /// The bounding box passed to the callback will have a margin of [`TessellationOptions::feathering_size_in_pixels`](`crate::tessellator::TessellationOptions::feathering_size_in_pixels`) #[inline] pub fn new_uv( - width: impl Into, + width: f32, callback: impl Fn(Rect, Pos2) -> Color32 + Send + Sync + 'static, ) -> Self { Self { - width: width.into(), + width, color: ColorMode::UV(Arc::new(callback)), kind: StrokeKind::Middle, } diff --git a/tests/test_viewports/src/main.rs b/tests/test_viewports/src/main.rs index 755aaca44..62d357fa8 100644 --- a/tests/test_viewports/src/main.rs +++ b/tests/test_viewports/src/main.rs @@ -334,7 +334,7 @@ fn drag_and_drop_test(ui: &mut egui::Ui) { assert!(col < COLS, "The coll should be less than: {COLS}"); let value: String = value.into(); - let id = Id::new(format!("%{}% {}", self.counter, &value)); + let id = Id::new(format!("%{}% {}", self.counter, value)); self.data.insert(id, value); let viewport_data = self.containers_data.entry(container).or_insert_with(|| { let mut res = Vec::new();