From 1ae0d678ba9390a16faf707c2b3ff2dc7cfe3818 Mon Sep 17 00:00:00 2001 From: Martin Ball Date: Fri, 20 Nov 2026 00:48:46 +0000 Subject: [PATCH] Workspace clippy: unused imports, auto-deref, an unused clipboard helper, a chord-match type, field facts grouped, trial asserts, device tests under cfg(test) --- crates/gpu/src/lib.rs | 3 ++- crates/platform/src/open.rs | 2 +- crates/ui-contract/src/contract/items.rs | 2 -- .../ui-contract/src/contract/items/measure.rs | 2 +- crates/ui-contract/src/contract/text.rs | 17 ++++++++--------- crates/ui-contract/src/layout/body.rs | 4 ++-- .../ui-contract/src/runtime/commands/board.rs | 10 +++------- .../ui-contract/src/runtime/egui/clipboard.rs | 7 ------- crates/ui-contract/src/runtime/motion.rs | 2 +- crates/ui-contract/src/testing/icon_trials.rs | 14 +++++++------- 10 files changed, 25 insertions(+), 38 deletions(-) diff --git a/crates/gpu/src/lib.rs b/crates/gpu/src/lib.rs index fd0e86e9a..480adee35 100644 --- a/crates/gpu/src/lib.rs +++ b/crates/gpu/src/lib.rs @@ -23,7 +23,8 @@ mod registry; #[cfg(test)] mod tests; -#[cfg(all(test, feature = "startup"))] +#[cfg(test)] +#[cfg(feature = "startup")] mod device_tests; pub use caps::DeviceCaps; diff --git a/crates/platform/src/open.rs b/crates/platform/src/open.rs index b0e71f912..d49575baf 100644 --- a/crates/platform/src/open.rs +++ b/crates/platform/src/open.rs @@ -218,7 +218,7 @@ impl FileIntake { pub fn take(&self) -> Vec { #[cfg(any(test, all(target_os = "macos", feature = "apple-events")))] { - let mine: Vec> = DRAINS.with(|drains| { + let mine: Vec<_> = DRAINS.with(|drains| { drains .borrow() .iter() diff --git a/crates/ui-contract/src/contract/items.rs b/crates/ui-contract/src/contract/items.rs index 2c23d0b30..bae80f142 100644 --- a/crates/ui-contract/src/contract/items.rs +++ b/crates/ui-contract/src/contract/items.rs @@ -47,7 +47,6 @@ pub fn show_item(ui: &mut Ui, rect: Rect, item: C, at: crate::runtime::access where C: super::Component + super::Props + super::Show, { - use super::Show as _; with_item_facts(ui, at, |ui, id| super::Props::id(item, id).show_at(ui, rect)) } @@ -56,7 +55,6 @@ pub fn show_item_in_flow(ui: &mut Ui, item: C, at: crate::runtime::access::Se where C: super::Component + super::Props + super::Show, { - use super::Show as _; with_item_facts(ui, at, |ui, id| super::Props::id(item, id).show(ui)) } diff --git a/crates/ui-contract/src/contract/items/measure.rs b/crates/ui-contract/src/contract/items/measure.rs index 52227aa23..3b85a4639 100644 --- a/crates/ui-contract/src/contract/items/measure.rs +++ b/crates/ui-contract/src/contract/items/measure.rs @@ -6,7 +6,7 @@ use super::{header, rows}; use crate::contract::body::EnvFacts; use crate::contract::collection::RowState; use crate::contract::run::{Measuring, ShowAt}; -use crate::contract::{Collection, Internal, ItemCx, Props, Show as _, Sizing}; +use crate::contract::{Collection, Internal, ItemCx, Props, Show as _}; use crate::runtime::access::SetPosition; use crate::runtime::env::{Env, EnvView, ItemFacts}; use crate::runtime::layout_memory; diff --git a/crates/ui-contract/src/contract/text.rs b/crates/ui-contract/src/contract/text.rs index 315d8e9d3..0d7923a65 100644 --- a/crates/ui-contract/src/contract/text.rs +++ b/crates/ui-contract/src/contract/text.rs @@ -307,17 +307,16 @@ fn serve_access(cx: &mut Cx<'_, C>, state: &mut TextState, widget: } } -/// The text facts AccessKit reads this pass, built only while AccessKit runs. -fn facts( - cx: &Cx<'_, C>, - state: &mut TextState, - widget: egui::Id, - out: &adapter::AdapterOut, - rect: Rect, +/// What a field says about itself to AccessKit besides its text. +struct FieldFacts { masked: bool, read_only: bool, enabled: bool, -) { +} + +/// The text facts AccessKit reads this pass, built only while AccessKit runs. +fn facts(cx: &Cx<'_, C>, state: &mut TextState, widget: egui::Id, out: &adapter::AdapterOut, rect: Rect, field: FieldFacts) { + let FieldFacts { masked, read_only, enabled } = field; if !text_access::exposed(&cx.core.ctx, widget) { state.rows = None; return; @@ -514,7 +513,7 @@ pub(crate) fn run( if let Some(baseline) = out.baseline { cx.core.paint.borrow_mut().baseline.get_or_insert(baseline); } - facts(cx, &mut state, widget, &out, decl.rect, decl.options.mask, read_only, enabled); + facts(cx, &mut state, widget, &out, decl.rect, FieldFacts { masked: decl.options.mask, read_only, enabled }); cx.core.text_invalid = state.invalid; cx.core.text_unparsed = decl.options.unparsed.clone().filter(|_| state.invalid); cx.core.escape_to_list = state.completions.open || list_open; diff --git a/crates/ui-contract/src/layout/body.rs b/crates/ui-contract/src/layout/body.rs index 7cf93eb38..f03c0ba36 100644 --- a/crates/ui-contract/src/layout/body.rs +++ b/crates/ui-contract/src/layout/body.rs @@ -658,7 +658,7 @@ fn run_shrinking(ui: &mut Ui, id: Id, mut body: impl FnMut(&mut Ui) -> R) -> vec![0; levelled.len()] }; let width_at = |leaf: &Reported, level: usize| leaf.levels.get(level).copied().unwrap_or_default(); - let held: f32 = levelled.iter().zip(&levels).map(|(leaf, level)| width_at(*leaf, *level)).sum(); + let held: f32 = levelled.iter().zip(&levels).map(|(leaf, level)| width_at(leaf, *level)).sum(); let widths = if room.is_finite() { shrink_or_drop(&units, &whole, &first, (fixed + held, gap), room, order, drops) } else { @@ -675,7 +675,7 @@ fn run_shrinking(ui: &mut Ui, id: Id, mut body: impl FnMut(&mut Ui) -> R) -> } for (leaf, level) in levelled.iter().zip(levels) { // The level travels as the record's height (`level_of`). - let measured = layout_memory::Measured::new(Vec2::new(room, 0.0), Vec2::new(width_at(*leaf, level), level as f32)); + let measured = layout_memory::Measured::new(Vec2::new(room, 0.0), Vec2::new(width_at(leaf, level), level as f32)); layout_memory::emit_shrink(&ctx, shrink_key(id, leaf.leaf), measured, false); } again diff --git a/crates/ui-contract/src/runtime/commands/board.rs b/crates/ui-contract/src/runtime/commands/board.rs index b8f71b1e5..69ac26653 100644 --- a/crates/ui-contract/src/runtime/commands/board.rs +++ b/crates/ui-contract/src/runtime/commands/board.rs @@ -267,6 +267,8 @@ struct View { edits: Option<(EditSet, EditSet)>, gens: ViewGens, } +/// A press's double-press matcher, its time, and whether a binding's command accepts the press where it lands. +type ChordMatch<'a> = (&'a mut Matcher, f64, &'a dyn Fn(&CommandRef) -> bool); /// What a resolution read besides the board's own generation and the gate. #[derive(Default)] @@ -822,13 +824,7 @@ impl KeyScopes { /// held scope's keys stay with the text while typing; a typing scope's keys are the text component's own. /// With a matcher, a binding of a command `accept` refuses (disabled where the press lands) is passed over for the /// press's next binding. - fn press( - &self, - layout: &Layout, - input: &KeyInput, - typing: bool, - matcher: Option<(&mut Matcher, f64, &dyn Fn(&CommandRef) -> bool)>, - ) -> Option { + fn press(&self, layout: &Layout, input: &KeyInput, typing: bool, matcher: Option>) -> Option { let (panel, outer) = self.scopes.split_first().map_or((None, &[][..]), |(panel, outer)| (Some(*panel), outer)); let held: &[&'static str] = if typing { &[] } else { &self.held }; let contexts: Vec<&str> = self.typing.iter().chain(held).copied().collect(); diff --git a/crates/ui-contract/src/runtime/egui/clipboard.rs b/crates/ui-contract/src/runtime/egui/clipboard.rs index 4387af0d7..0fc61b78e 100644 --- a/crates/ui-contract/src/runtime/egui/clipboard.rs +++ b/crates/ui-contract/src/runtime/egui/clipboard.rs @@ -160,13 +160,6 @@ pub(crate) fn copy_text(ctx: &Context, text: String) { }); } -/// Puts `image` on the installed clipboard. -pub(crate) fn copy_image(ctx: &Context, image: ColorImage) { - with(ctx, |clipboard| { - let _ = clipboard.write_image(&clipboard_image(&image)); - }); -} - /// Asks the platform for the clipboard text, which arrives as a paste event. pub(crate) fn request_paste(ctx: &Context) { ctx.send_viewport_cmd(egui::ViewportCommand::RequestPaste); diff --git a/crates/ui-contract/src/runtime/motion.rs b/crates/ui-contract/src/runtime/motion.rs index 61ce8c970..208380e33 100644 --- a/crates/ui-contract/src/runtime/motion.rs +++ b/crates/ui-contract/src/runtime/motion.rs @@ -635,7 +635,7 @@ pub(crate) fn key_id(key: &impl Hash) -> Id { use std::hash::Hasher as _; let mut hasher = std::collections::hash_map::DefaultHasher::new(); key.hash(&mut hasher); - Id::new(hasher.finish()) + Id::unique(hasher.finish()) } /// The types that reach the motion service. diff --git a/crates/ui-contract/src/testing/icon_trials.rs b/crates/ui-contract/src/testing/icon_trials.rs index cac8c0af2..2358f8e20 100644 --- a/crates/ui-contract/src/testing/icon_trials.rs +++ b/crates/ui-contract/src/testing/icon_trials.rs @@ -133,18 +133,16 @@ fn an_accent_part_paints_in_the_accent_ink_a_fixed_part_as_drawn_and_both_take_t let disabled = paint(LAYERED_NAME, DataMode::Dimmed, ink); let enabled_in_the_disabled_colour = paint(LAYERED_NAME, DataMode::Full, off); - let [(ink_layer, ink_tint), (accent_layer, accent_tint), (fixed_layer, fixed_tint)] = enabled[..] else { - panic!("an app icon paints its ink, accent and fixed layers, got {enabled:?}") - }; + assert_eq!(enabled.len(), 3, "an app icon paints its ink, accent and fixed layers, got {enabled:?}"); + let [(ink_layer, ink_tint), (accent_layer, accent_tint), (fixed_layer, fixed_tint)] = enabled[..] else { return }; assert_eq!(ink_tint, ink, "the plain parts read in the icon's colour"); assert_eq!(accent_tint, rgba_color(tokens.color.accent.solid), "the accent parts read in the accent ink"); assert_ne!(accent_tint, ink_tint); assert_eq!(fixed_tint, Color32::WHITE, "the fixed parts keep the colours they are drawn in"); assert!(ink_layer != accent_layer && accent_layer != fixed_layer && ink_layer != fixed_layer, "each layer is its own texture"); - let [(off_ink, a), (off_accent, b), (off_fixed, c)] = disabled[..] else { - panic!("a disabled app icon paints the same three layers, got {disabled:?}") - }; + assert_eq!(disabled.len(), 3, "a disabled app icon paints the same three layers, got {disabled:?}"); + let [(off_ink, a), (off_accent, b), (off_fixed, c)] = disabled[..] else { return }; assert_eq!([a, b, c], [ink; 3], "every layer takes the one ink when the component is disabled"); assert_eq!((off_ink, off_accent), (ink_layer, accent_layer), "the ink and accent layers are the same drawings, tinted"); assert_ne!(off_fixed, fixed_layer, "a disabled fixed part is drawn as a silhouette, not in its own colours"); @@ -153,7 +151,9 @@ fn an_accent_part_paints_in_the_accent_ink_a_fixed_part_as_drawn_and_both_take_t assert_eq!(tints, [off, rgba_color(tokens.color.accent.solid), Color32::WHITE], "an enabled icon in the disabled colour keeps its layers"); // What each layer holds: the class split is the SVG engine's, so a sheet it ignored would give every layer the whole drawing. - let Some(layered) = icon(LAYERED_NAME) else { panic!("the layered icon resolves") }; + let layered = icon(LAYERED_NAME); + assert!(layered.is_some(), "the layered icon resolves"); + let Some(layered) = layered else { return }; let (body, nib, cap) = ((9, 12), (16, 12), (3, 12)); let [plain, accent, fixed] = [Layer::Ink, Layer::Accent, Layer::Fixed].map(|layer| layered.layer(24.0, 1.0, layer)); assert!(texel(&plain, body.0, body.1).a() > 0 && texel(&plain, nib.0, nib.1).a() == 0, "the ink layer holds the plain body only");