From b2a4cfc26fbef2e773f188df64624093c2320f06 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sun, 29 Nov 2026 15:18:56 +0000 Subject: [PATCH] Clippy: port test code and the cancel response of upstream callers ToolHost::cancel returns the port's ToolHostResponse (must_use); the fill, liquify, raw develop and vanishing point cancels take it as wide_angle and select_mask do, as their tools request no URLs. Port tests: unused Props import, Id::unique for a fixed id, a one-range Vec from once, as_chunks, Result::inspect, and the dropper trial's hover and sample phases as helpers under the complexity cap. Co-Authored-By: Claude Opus 5.5 --- crates/automation/src/server_tests.rs | 5 +- crates/color-ui/tests/it/sampling.rs | 96 ++++++++++++-------- crates/imaging/src/ui/fill/mod.rs | 3 +- crates/imaging/src/ui/liquify/mod.rs | 3 +- crates/imaging/src/ui/raw_develop/mod.rs | 5 +- crates/imaging/src/ui/vanishing_point/mod.rs | 5 +- crates/menu/tests/it/backstage.rs | 2 +- crates/menu/tests/it/ribbon.rs | 2 +- crates/text/tests/it/editor.rs | 2 +- crates/text/tests/it/notes.rs | 2 +- 10 files changed, 72 insertions(+), 53 deletions(-) diff --git a/crates/automation/src/server_tests.rs b/crates/automation/src/server_tests.rs index 833d328548..f8cc69cbb8 100644 --- a/crates/automation/src/server_tests.rs +++ b/crates/automation/src/server_tests.rs @@ -12,10 +12,9 @@ fn a_failed_accept_waits_before_the_next() { let failed = || Err(std::io::Error::other("no file descriptors left")); let waits = Cell::new(0); let incoming = [failed(), Ok(1), failed(), failed(), Ok(2)].into_iter().map(|result| { - result.map(|connection| { - let preceding_failures = if connection == 1 { 1 } else { 3 }; + result.inspect(|connection| { + let preceding_failures = if *connection == 1 { 1 } else { 3 }; assert_eq!(waits.get(), preceding_failures, "every failure waits before the next accept"); - connection }) }); let connections: Vec<_> = accepted(incoming, || waits.set(waits.get() + 1)).collect(); diff --git a/crates/color-ui/tests/it/sampling.rs b/crates/color-ui/tests/it/sampling.rs index 35bc8ab5e1..e1a674dbd6 100644 --- a/crates/color-ui/tests/it/sampling.rs +++ b/crates/color-ui/tests/it/sampling.rs @@ -135,29 +135,35 @@ impl CaptureSource for Late { const PICKED: Srgba = Srgba { r: 0.25, g: 0.5, b: 0.75, a: 1.0 }; -#[trial] -fn a_pick_dropper_picks_once_and_ends_on_escape_a_secondary_press_or_a_press_off_the_document() { - let make = |mode| { - let reads = Rc::new(Cell::new(0)); - let sampled = Rc::clone(&reads); - let dropper = DropperTool::new(move |at| { - sampled.set(sampled.get() + 1); - (at[0] >= 0.0 && at[1] >= 0.0 && at[0] < f64::from(SIZE[0]) && at[1] < f64::from(SIZE[1])).then_some(PICKED) - }) - .mode(mode); - let rerun = Rc::new(Cell::new(false)); - let discard = Rc::clone(&rerun); - let mut tool = ToolFixture::with_view("Dropper", dropper, sampler_view, move |ui, _| { - if frame::discardable(ui.ctx()) && discard.replace(false) { - frame::discard_pass(ui.ctx(), "rerun a dropper pass"); - } - }); - tool.fixture().room(vec2(800.0, 600.0)).settle(); - (tool, rerun, reads) - }; - let inside = |tool: &ToolFixture>| tool.canvas().rect.min + vec2(100.5, 50.5); +/// A dropper in `mode` over the sampled document, the flag that discards its next pass, and its count of samples read. +fn dropper_rig(mode: DropperMode) -> (ToolFixture>, Rc>, Rc>) { + let reads = Rc::new(Cell::new(0)); + let sampled = Rc::clone(&reads); + let dropper = DropperTool::new(move |at| { + sampled.set(sampled.get() + 1); + (at[0] >= 0.0 && at[1] >= 0.0 && at[0] < f64::from(SIZE[0]) && at[1] < f64::from(SIZE[1])).then_some(PICKED) + }) + .mode(mode); + let rerun = Rc::new(Cell::new(false)); + let discard = Rc::clone(&rerun); + let mut tool = ToolFixture::with_view("Dropper", dropper, sampler_view, move |ui, _| { + if frame::discardable(ui.ctx()) && discard.replace(false) { + frame::discard_pass(ui.ctx(), "rerun a dropper pass"); + } + }); + tool.fixture().room(vec2(800.0, 600.0)).settle(); + (tool, rerun, reads) +} - let (mut tool, rerun, reads) = make(DropperMode::Pick); +/// A point inside the sampled document. +fn inside(tool: &ToolFixture>) -> Pos2 { + tool.canvas().rect.min + vec2(100.5, 50.5) +} + +/// A pick dropper's hover: its loupe stays while the pointer rests and through a rerun, leaves with the pointer, and +/// neither samples again nor picks. +fn a_pick_droppers_hover_keeps_its_loupe_and_never_picks() { + let (mut tool, rerun, reads) = dropper_rig(DropperMode::Pick); let at = inside(&tool); let without_loupe = tool.fixture().texts().to_vec(); tool.move_to(at); @@ -184,6 +190,34 @@ fn a_pick_dropper_picks_once_and_ends_on_escape_a_secondary_press_or_a_press_off let mut dropper = tool.tool_mut(); assert!(dropper.take_at().is_none() && !dropper.ended(), "hover never picks or disarms"); } +} + +/// A sample dropper samples on press, through a drag and once on release, stays armed, and a cancel never ends it. +fn a_sample_dropper_samples_while_pressed_and_stays_armed() { + let (mut tool, rerun, reads) = dropper_rig(DropperMode::Sample); + let at = inside(&tool); + tool.press_at(at); + assert_eq!(tool.tool_mut().take(), Some(PICKED), "sample mode samples on press"); + tool.move_to(at + vec2(60.0, 20.0)); + assert_eq!(tool.tool_mut().take(), Some(PICKED), "sample mode samples during a drag"); + let before_release = reads.get(); + rerun.set(true); + tool.release_at(at + vec2(60.0, 20.0)); + assert_eq!(reads.get(), before_release + 1, "a second pass in one frame does not repeat the release sample"); + assert_eq!(tool.tool_mut().take(), Some(PICKED)); + assert!(!tool.tool().ended(), "sample mode stays armed after release"); + tool.escape(); + { + let mut dropper = tool.tool_mut(); + assert!(dropper.cancelled() && !dropper.ended(), "sample cancellation never becomes a pick ending"); + } +} + +#[trial] +fn a_pick_dropper_picks_once_and_ends_on_escape_a_secondary_press_or_a_press_off_the_document() { + let make = dropper_rig; + a_pick_droppers_hover_keeps_its_loupe_and_never_picks(); + a_sample_dropper_samples_while_pressed_and_stays_armed(); let (mut tool, rerun, reads) = make(DropperMode::Pick); let at = inside(&tool); @@ -262,24 +296,6 @@ fn a_pick_dropper_picks_once_and_ends_on_escape_a_secondary_press_or_a_press_off let mut dropper = tool.tool_mut(); assert!(dropper.ended() && dropper.take().is_some(), "a later click still picks after a discarded pass"); } - - let (mut tool, rerun, reads) = make(DropperMode::Sample); - let at = inside(&tool); - tool.press_at(at); - assert_eq!(tool.tool_mut().take(), Some(PICKED), "sample mode samples on press"); - tool.move_to(at + vec2(60.0, 20.0)); - assert_eq!(tool.tool_mut().take(), Some(PICKED), "sample mode samples during a drag"); - let before_release = reads.get(); - rerun.set(true); - tool.release_at(at + vec2(60.0, 20.0)); - assert_eq!(reads.get(), before_release + 1, "a second pass in one frame does not repeat the release sample"); - assert_eq!(tool.tool_mut().take(), Some(PICKED)); - assert!(!tool.tool().ended(), "sample mode stays armed after release"); - tool.escape(); - { - let mut dropper = tool.tool_mut(); - assert!(dropper.cancelled() && !dropper.ended(), "sample cancellation never becomes a pick ending"); - } } #[trial] diff --git a/crates/imaging/src/ui/fill/mod.rs b/crates/imaging/src/ui/fill/mod.rs index bbcf23b7e5..6a5f23640a 100644 --- a/crates/imaging/src/ui/fill/mod.rs +++ b/crates/imaging/src/ui/fill/mod.rs @@ -841,7 +841,8 @@ impl ContentAwareFillWorkspace { /// passes) only the canvas's own state is dropped. fn cancel_gesture(&mut self, ctx: Option<&Context>, reason: CancelReason) { if let (Some(ctx), Some(id)) = (ctx, self.canvas_id) { - match self.tool { + // These tools request no URLs, so the cancel response has nothing to open. + let _ = match self.tool { FillTool::Hand => ToolHost::new().cancel(ctx, id, &mut self.hand, reason), FillTool::Zoom => ToolHost::new().cancel(ctx, id, &mut self.zoom, reason), FillTool::SamplingBrush | FillTool::Lasso => { diff --git a/crates/imaging/src/ui/liquify/mod.rs b/crates/imaging/src/ui/liquify/mod.rs index 708bee7dc1..6eecfe3170 100644 --- a/crates/imaging/src/ui/liquify/mod.rs +++ b/crates/imaging/src/ui/liquify/mod.rs @@ -698,7 +698,8 @@ impl Edit { let cursor = self.cursor_options; let LiquifyView { canvas, canvas_id, .. } = state; if let (Some(ctx), Some(id)) = (ctx, *canvas_id) { - match self.settings.tool { + // These tools request no URLs, so the cancel response has nothing to open. + let _ = match self.settings.tool { LiquifyTool::Hand => ToolHost::new().cancel(ctx, id, &mut canvas.hand, reason), LiquifyTool::Zoom => ToolHost::new().cancel(ctx, id, &mut canvas.zoom, reason), _ => ToolHost::new().cancel(ctx, id, &mut canvas.tool(&mut self.settings, &cursor), reason), diff --git a/crates/imaging/src/ui/raw_develop/mod.rs b/crates/imaging/src/ui/raw_develop/mod.rs index 1a695e6ef2..c80981713b 100644 --- a/crates/imaging/src/ui/raw_develop/mod.rs +++ b/crates/imaging/src/ui/raw_develop/mod.rs @@ -419,16 +419,17 @@ impl RawDevelopWorkspace { fn end_gesture(&mut self, ctx: &Context, reason: CancelReason) { let Some(canvas) = self.canvas else { return }; let size = [self.size.width, self.size.height]; + // These tools request no URLs, so the cancel response has nothing to open. match self.tool { RawTool::Hand => {} RawTool::Zoom => { if let Some(zoom) = self.zoom_tool.as_mut() { - ToolHost::new().cancel(ctx, canvas, zoom, reason); + let _ = ToolHost::new().cancel(ctx, canvas, zoom, reason); } } RawTool::Sampler => { let mut pass = self.sampler_tool.pass(&self.samplers, size); - ToolHost::new().cancel(ctx, canvas, &mut pass, reason); + let _ = ToolHost::new().cancel(ctx, canvas, &mut pass, reason); } } } diff --git a/crates/imaging/src/ui/vanishing_point/mod.rs b/crates/imaging/src/ui/vanishing_point/mod.rs index 622843c21e..bc034a6d16 100644 --- a/crates/imaging/src/ui/vanishing_point/mod.rs +++ b/crates/imaging/src/ui/vanishing_point/mod.rs @@ -639,12 +639,13 @@ impl VanishingPointWorkspace { /// Cancels the gesture the strip's tool holds with `reason`: the editor puts back what the press found (the /// Hand's and Zoom's drags go through the host). fn cancel_gesture(&mut self, ctx: &egui::Context, state: &VanishingView, reason: CancelReason, out: &mut Vec) { + // The Hand and Zoom request no URLs, so the cancel response has nothing to open. match (self.strip, state.canvas) { (VanishingPointStripTool::Hand, Some(canvas)) => { - ToolHost::new().cancel(ctx, canvas, &mut self.hand, reason); + let _ = ToolHost::new().cancel(ctx, canvas, &mut self.hand, reason); } (VanishingPointStripTool::Zoom, Some(canvas)) => { - ToolHost::new().cancel(ctx, canvas, &mut self.zoom, reason); + let _ = ToolHost::new().cancel(ctx, canvas, &mut self.zoom, reason); } _ => self.editor.cancel(&mut self.session, reason), } diff --git a/crates/menu/tests/it/backstage.rs b/crates/menu/tests/it/backstage.rs index 97e2c7a713..b475b1cea3 100644 --- a/crates/menu/tests/it/backstage.rs +++ b/crates/menu/tests/it/backstage.rs @@ -6,7 +6,7 @@ use std::rc::Rc; use craft_behavior::IconId; use craft_menu::ribbon::{BackLook, BackstageCommands, BackstageEntry, BackstageEvent, BackstageView}; use craft_ui::buttons::Button; -use craft_ui::contract::{Bind, Props as _, Role, Show as _}; +use craft_ui::contract::{Bind, Role, Show as _}; use craft_ui::runtime::commands::CommandSet as _; use craft_ui::runtime::egui::access::NodeKey; use craft_ui::runtime::env::WindowKey; diff --git a/crates/menu/tests/it/ribbon.rs b/crates/menu/tests/it/ribbon.rs index 730f6afdf2..2f68cae957 100644 --- a/crates/menu/tests/it/ribbon.rs +++ b/crates/menu/tests/it/ribbon.rs @@ -566,7 +566,7 @@ fn a_tab_keeps_its_own_group_row_scroll_offset_when_it_is_picked_again() { let discard = rerun.clone(); let forward_name = Rc::new(RefCell::new(Label::Empty)); let name = forward_name.clone(); - let id = Id::new("ribbon.scroll_trial"); + let id = Id::unique("ribbon.scroll_trial"); let mut fixture = Fixture::new(move |ui| { if discard.take() { ui.ctx().request_discard("the ribbon input frame runs twice"); diff --git a/crates/text/tests/it/editor.rs b/crates/text/tests/it/editor.rs index 85b7e945d7..391a250d22 100644 --- a/crates/text/tests/it/editor.rs +++ b/crates/text/tests/it/editor.rs @@ -63,7 +63,7 @@ const LINE: usize = 4; impl Host { fn rows(&self) -> Vec> { - let Some(columns) = self.columns else { return vec![0..self.text.chars().count()] }; + let Some(columns) = self.columns else { return std::iter::once(0..self.text.chars().count()).collect() }; let chars: Vec = self.text.chars().collect(); let mut rows = Vec::new(); let mut start = 0; diff --git a/crates/text/tests/it/notes.rs b/crates/text/tests/it/notes.rs index f9c8af1127..faed3d8d5c 100644 --- a/crates/text/tests/it/notes.rs +++ b/crates/text/tests/it/notes.rs @@ -139,7 +139,7 @@ fn mark_segments(shapes: &[Shape], ink: Color32) -> Vec<[Pos2; 2]> { segments.extend(path.points.windows(2).map(|pair| [pair[0], pair[1]])); } Shape::Mesh(mesh) => { - for triangle in mesh.indices.chunks_exact(3) { + for triangle in mesh.indices.as_chunks::<3>().0 { for (a, b) in [(0, 1), (1, 2), (2, 0)] { let (a, b) = (mesh.vertices[triangle[a] as usize], mesh.vertices[triangle[b] as usize]); if a.color == ink && b.color == ink {