From 0c586294ea2f0a909e773e5196f413609673c017 Mon Sep 17 00:00:00 2001 From: aiongg Date: Sat, 14 Nov 2026 00:35:31 +0000 Subject: [PATCH] Lints: fix clippy and rustdoc findings in ui-contract, i18n, heif, mesh, video, audio, doc and the doc links --- crates/audio/tests/codecs/opus/oracle.rs | 4 +-- crates/doc/tests/icc.rs | 3 +-- crates/heif/src/lib.rs | 4 +-- crates/i18n/src/bidi.rs | 6 ++--- crates/i18n/src/lib.rs | 4 ++- crates/mesh/src/tests/gltf.rs | 2 ++ crates/pdf/src/cos/document/objects.rs | 2 +- crates/ui-contract/src/contract/body/hooks.rs | 6 ++++- crates/ui-contract/src/contract/cx/parts.rs | 3 ++- crates/ui-contract/src/contract/items/drag.rs | 5 +++- .../ui-contract/src/contract/items/hooks.rs | 22 +++++++-------- .../ui-contract/src/contract/items/members.rs | 5 +++- .../ui-contract/src/contract/items/press.rs | 4 +++ crates/ui-contract/src/contract/label/step.rs | 5 +++- crates/ui-contract/src/contract/level.rs | 6 ++--- crates/ui-contract/src/contract/mount.rs | 9 ++++--- .../src/contract/overlay/placement.rs | 4 +++ crates/ui-contract/src/contract/run.rs | 8 ++++++ crates/ui-contract/src/contract/run/typed.rs | 27 +++++++++++++------ crates/ui-contract/src/primitives/kit.rs | 6 ++--- crates/ui-contract/src/primitives/sensing.rs | 1 + .../src/primitives/text_adapter.rs | 2 +- .../ui-contract/src/runtime/egui/fixture.rs | 1 + .../ui-contract/src/runtime/egui/injected.rs | 4 +-- .../ui-contract/src/runtime/layout_memory.rs | 1 + crates/ui-contract/src/runtime/pass_state.rs | 1 + .../src/testing/host_key_trials.rs | 6 +++-- crates/ui-contract/src/testing/snapshot.rs | 2 +- crates/vectorcraft-format/src/container.rs | 4 +-- crates/video/src/prores/decode.rs | 3 ++- crates/web-host/src/lib.rs | 2 +- 31 files changed, 105 insertions(+), 57 deletions(-) diff --git a/crates/audio/tests/codecs/opus/oracle.rs b/crates/audio/tests/codecs/opus/oracle.rs index 1ff1f74b6..f6cf9b92a 100644 --- a/crates/audio/tests/codecs/opus/oracle.rs +++ b/crates/audio/tests/codecs/opus/oracle.rs @@ -50,8 +50,8 @@ fn run(case: &Case, rate: u32) -> (f64, f64, Vec) { let layout = match case.channels { 1 => "mono", 2 => "stereo", - 6 => "5.1", - _ => unreachable!(), + // The cases have 1, 2 or 6 channels. + _ => "5.1", }; let mut cmd = Command::new(&ff); cmd.args(["-hide_banner", "-loglevel", "error", "-y", "-f", "f32le", "-ar", "48000", "-ch_layout", layout, "-i"]).arg(&raw); diff --git a/crates/doc/tests/icc.rs b/crates/doc/tests/icc.rs index 1e707bf19..c647120b4 100644 --- a/crates/doc/tests/icc.rs +++ b/crates/doc/tests/icc.rs @@ -96,8 +96,7 @@ fn excessive_window_and_size_less_expansion_are_limits() { let z = frame(&payload); // Producer frames omit their content size; output admission must work without that hint. assert_eq!(z[4] & 0xc0, 0); - let mut limits = Limits::default(); - limits.max_entry = 1024; + let limits = Limits { max_entry: 1024, ..Limits::default() }; assert!(matches!(pcraft_icc_profile(&zip(&[store("manifest.json", m.as_bytes()), store(&path, &z)]), &limits), Err(Error::LimitExceeded(_)))); let mut large_window = z.clone(); assert_eq!(large_window[4] & 0x20, 0); diff --git a/crates/heif/src/lib.rs b/crates/heif/src/lib.rs index 3438b4109..4b7a751cc 100644 --- a/crates/heif/src/lib.rs +++ b/crates/heif/src/lib.rs @@ -2,8 +2,8 @@ //! //! `heic-rs`, a pure-Rust HEIF container and HEVC still-picture decoder, reads the container and //! reconstructs the coded pictures (bit-exact against libde265 on iPhone photos); this crate turns -//! them into RGB itself ([`ycc`]) so the colours match libheif: it honours the HEVC VUI's range -//! and matrix ([`vui`]) where heic-rs assumes BT.709 limited range, and upsamples chroma like +//! them into RGB itself (`ycc`) so the colours match libheif: it honours the HEVC VUI's range +//! and matrix (`vui`) where heic-rs assumes BT.709 limited range, and upsamples chroma like //! libheif. Single pictures and grid-tiled photos, 8- to 16-bit, monochrome, alpha auxiliary //! images, ICC, EXIF and XMP. The API is plain data ([`Info`], [`Decoded`], [`Error`]) so the //! crate knows nothing about any app; each app's codec layer adapts it behind its own optional diff --git a/crates/i18n/src/bidi.rs b/crates/i18n/src/bidi.rs index 1bc282106..035867ebd 100644 --- a/crates/i18n/src/bidi.rs +++ b/crates/i18n/src/bidi.rs @@ -16,7 +16,7 @@ pub(super) const RLM: char = '\u{200F}'; pub(super) const ALM: char = '\u{061C}'; /// `value` as a first-strong isolate (FSI…PDI): it takes the direction of its first strong -/// letter and can't reorder the text around it. What [`fmt`] does to each value in text with a +/// letter and can't reorder the text around it. What [`crate::fmt`] does to each value in text with a /// right-to-left letter. pub fn isolate(value: &str) -> String { wrap(FSI, value) @@ -24,13 +24,13 @@ pub fn isolate(value: &str) -> String { /// `value` as a left-to-right isolate (LRI…PDI), for numbers, paths, file sizes, timecodes and /// codes, which read left to right in every language. In an RTL first-strong isolate, the -/// segments of `/home/مستخدم/file.txt` would run right to left. [`fmt`] takes the isolate off +/// segments of `/home/مستخدم/file.txt` would run right to left. [`crate::fmt`] takes the isolate off /// again in text with no right-to-left letter. pub fn ltr(value: &str) -> String { wrap(LRI, value) } -/// `text` without isolate marks (LRI, RLI, FSI, PDI): a [`fmt`] or [`I18n::trn`] result made fit +/// `text` without isolate marks (LRI, RLI, FSI, PDI): a [`crate::fmt`] or [`crate::I18n::trn`] result made fit /// for a file name, a log or a comparison. pub fn strip_isolates(text: &str) -> String { text.chars().filter(|c| !matches!(*c, LRI | RLI | FSI | PDI)).collect() diff --git a/crates/i18n/src/lib.rs b/crates/i18n/src/lib.rs index 94ae0abdb..60e796179 100644 --- a/crates/i18n/src/lib.rs +++ b/crates/i18n/src/lib.rs @@ -29,7 +29,9 @@ mod bidi; mod negotiation; use bidi::{FSI, has_bidi_control, has_rtl, is_one_isolate, unwrap_isolate, wrap}; -use negotiation::{bare, candidates, is_region, marked, plural_rules, posix_env_tags}; +#[cfg(all(unix, not(any(target_vendor = "apple", target_os = "android"))))] +use negotiation::posix_env_tags; +use negotiation::{bare, candidates, is_region, marked, plural_rules}; pub use bidi::{isolate, ltr, strip_isolates}; diff --git a/crates/mesh/src/tests/gltf.rs b/crates/mesh/src/tests/gltf.rs index 9b5e08b8d..cdbca1ebb 100644 --- a/crates/mesh/src/tests/gltf.rs +++ b/crates/mesh/src/tests/gltf.rs @@ -217,6 +217,8 @@ fn texture_and_sampler_inventory_includes_unreferenced_entries() { invalid.texture_variants[0].image = invalid.images.len(); assert!(matches!(invalid.validate(), Err(Error::Malformed(_)))); } + +#[test] fn glb_container_checks() { let glb = quad(); let (json, bin) = split_glb(&glb).unwrap(); diff --git a/crates/pdf/src/cos/document/objects.rs b/crates/pdf/src/cos/document/objects.rs index 2b8df8eb1..9082694dd 100644 --- a/crates/pdf/src/cos/document/objects.rs +++ b/crates/pdf/src/cos/document/objects.rs @@ -316,7 +316,7 @@ impl Document { } /// Follow a reference if `o` is one; otherwise return `o` itself. An object can be nothing but - /// a reference to another, which is followed too, up to [`MAX_REFERENCE_HOPS`] of them. + /// a reference to another, which is followed too, up to 32 of them. pub fn resolve(&self, o: &Object) -> Arc { let Object::Ref(r) = o else { return Arc::new(o.clone()) }; let mut held = self.get(*r); diff --git a/crates/ui-contract/src/contract/body/hooks.rs b/crates/ui-contract/src/contract/body/hooks.rs index 5fd69c75e..d550ce2e1 100644 --- a/crates/ui-contract/src/contract/body/hooks.rs +++ b/crates/ui-contract/src/contract/body/hooks.rs @@ -168,7 +168,7 @@ impl ShapeHooks for BodyHooks<'_> { Mount::Viewport { .. } if viewports::available(&ctx) => true, Mount::Layer(_) | Mount::Viewport { .. } => { let placement = overlay_of(props).map_or_else(Placement::default, |overlay| { - let screen = crate::contract::overlay::screen_for(&ctx, &env, overlay); + let screen = crate::contract::overlay::screen_for(&ctx, env, overlay); shown_placement(&ctx, id, save.as_ref(), overlay, screen, env.tokens.space.inset.screen) }); // A layer the user sized takes that size, at its saved position or where its anchor places it. @@ -674,6 +674,10 @@ impl ShapeHooks for BodyHooks<'_> { } } + #[expect( + clippy::cognitive_complexity, + reason = "the body step of the pass: its sub-steps share locals and run in one order, so a split would pass them all through" + )] fn content(&mut self, comp: &mut C, ui: &mut Ui, env: &Env, cx: &mut Cx<'_, C>, values: &AppValues) { let props = Arc::clone(&self.props); let (id, ctx, rect) = (cx.core.id, cx.core.ctx.clone(), cx.core.rect); diff --git a/crates/ui-contract/src/contract/cx/parts.rs b/crates/ui-contract/src/contract/cx/parts.rs index f295489f4..e57ff50e1 100644 --- a/crates/ui-contract/src/contract/cx/parts.rs +++ b/crates/ui-contract/src/contract/cx/parts.rs @@ -40,9 +40,10 @@ pub(crate) struct Decls { impl Decls { fn push(&mut self, decl: PartDecl) -> (&mut PartDecl, &mut PartExtras) { + let at = self.parts.len(); self.parts.push(decl); self.extras.push(PartExtras::default()); - (self.parts.last_mut().expect("just pushed"), self.extras.last_mut().expect("just pushed")) + (&mut self.parts[at], &mut self.extras[at]) } /// The sensing core's declarations, in declaration order. diff --git a/crates/ui-contract/src/contract/items/drag.rs b/crates/ui-contract/src/contract/items/drag.rs index e65d592e3..5203fba6f 100644 --- a/crates/ui-contract/src/contract/items/drag.rs +++ b/crates/ui-contract/src/contract/items/drag.rs @@ -82,6 +82,9 @@ pub struct SweepApply { show_only: bool, } +/// A move of a collection's own items as they stand before the drop, and as the drop leaves them. +type MovePair = (ReorderMove, ReorderMove); + impl SweepApply { /// A plain column: Alt is ignored. pub fn new() -> Self { @@ -472,7 +475,7 @@ impl ItemsHooks<'_, '_, C> { /// The move a drop of the collection's own `payload` at `landed` makes, before and after; `None` when it would /// leave every item where it is. - fn own_move(&self, payload: &ListDrag, landed: Landed, groups: bool) -> Option<(ReorderMove, ReorderMove)> { + fn own_move(&self, payload: &ListDrag, landed: Landed, groups: bool) -> Option> { // The moved items in display order, as they stand in the source now. let at: Vec = payload.keys.iter().filter_map(|key| self.index_of(key)).collect::>().into_iter().collect(); diff --git a/crates/ui-contract/src/contract/items/hooks.rs b/crates/ui-contract/src/contract/items/hooks.rs index 09626b281..a9eb8a859 100644 --- a/crates/ui-contract/src/contract/items/hooks.rs +++ b/crates/ui-contract/src/contract/items/hooks.rs @@ -611,12 +611,8 @@ impl ShapeHooks for ItemsHooks<'_, '_, C> { Some((row_ui, installed)) } }; - { - let measure_ui = match (&row_ui, &members_ui) { - (Some((row_ui, _)), _) => row_ui, - (None, Some((members_ui, _))) => members_ui, - (None, None) => unreachable!("a row is a run or a member"), - }; + // A row is a run or a member, so one of the two is there. + if let Some((measure_ui, _)) = row_ui.as_ref().or(members_ui.as_ref()) { if layout.is_auto(at) && !self.measured_for_reveal.contains(&at) { let measured = item.measure_in(measure_ui, Proposal::Width(row.width())).y; #[cfg(feature = "testing")] @@ -842,7 +838,7 @@ impl ItemsHooks<'_, '_, C> { self.renaming.draft = draft; if let Some(editor) = editor { if !self.renaming.focused { - focus::request_now(&ctx, focus::FocusTarget::Id(editor.response.id)); + focus::request_now(ctx, focus::FocusTarget::Id(editor.response.id)); self.renaming.focused = true; } let gesture = self.renaming.gesture; @@ -851,15 +847,15 @@ impl ItemsHooks<'_, '_, C> { let end = editor.events.iter().rev().find(|event| matches!(event, EditEvent::Commit { .. } | EditEvent::Cancel { .. })).cloned(); let edited = !editor.events.is_empty(); if end.is_some() { - self.refocus = focus::is_focused(&ctx, editor.response.id); + self.refocus = focus::is_focused(ctx, editor.response.id); } // The editor claims Escape for the whole rename, as a text part with a draft does: Escape does not leave the // row. One the editor leaves untaken (it holds no draft yet) cancels the rename. - keys::hold_escape(&ctx, editor.response.id); - let escaped = !edited && focus::is_focused(&ctx, editor.response.id) && { - let mut intents = keys::intents_of(&ctx, Some(editor.response.id), rtl); + keys::hold_escape(ctx, editor.response.id); + let escaped = !edited && focus::is_focused(ctx, editor.response.id) && { + let mut intents = keys::intents_of(ctx, Some(editor.response.id), rtl); let left = intents.take(Intent::Cancel); - keys::settle(&ctx, Some(editor.response.id), &intents); + keys::settle(ctx, Some(editor.response.id), &intents); left }; match end { @@ -896,7 +892,7 @@ impl ItemsHooks<'_, '_, C> { let next = if forward { (at + 1..len).find(renamable) } else { (0..at).rev().find(renamable) }; self.refocus = next.is_none(); if let Some(next) = next { - request::request_rename(&ctx, id, &self.source.key(next)); + request::request_rename(ctx, id, &self.source.key(next)); } } } diff --git a/crates/ui-contract/src/contract/items/members.rs b/crates/ui-contract/src/contract/items/members.rs index cae003704..cf7433882 100644 --- a/crates/ui-contract/src/contract/items/members.rs +++ b/crates/ui-contract/src/contract/items/members.rs @@ -12,6 +12,9 @@ use crate::style::Flags; use craft_behavior::Sense; use egui::{Context, Id, Rect, Ui}; +/// A member with its id, whether it is enabled, its sense and what its run prepared. +type Prepared = (Member, Id, bool, Sense, run::MemberPrep); + /// A visible item of a members collection, built by the row loop and shown once every member has joined the arena. pub(super) struct Member { pub at: usize, @@ -45,7 +48,7 @@ impl<'r, C: Collection> ItemsHooks<'_, 'r, C> { let enabled = cx.core.resolved.enabled; let parent = access::fold::owner_of(ctx, id).unwrap_or(id); let hover = sensing::read_outcome(ctx, ArenaId::new(id)).hover.map(|hit| hit.owner); - let mut prepared: Vec<(Member, Id, bool, Sense, run::MemberPrep>)> = members + let mut prepared: Vec>> = members .into_iter() .map(|member| { let Member { at, key, mut item, row, clip, flags, position, renaming, openers, shown } = member; diff --git a/crates/ui-contract/src/contract/items/press.rs b/crates/ui-contract/src/contract/items/press.rs index f46ffc9b9..79ddf7268 100644 --- a/crates/ui-contract/src/contract/items/press.rs +++ b/crates/ui-contract/src/contract/items/press.rs @@ -42,6 +42,10 @@ impl ItemsHooks<'_, '_, C> { } /// A press on a row selects it; a double press activates it; a right press asks for its menu. + #[expect( + clippy::cognitive_complexity, + reason = "one match over the press kinds (select, activate, menu), each arm short; splitting it only moves the match" + )] pub(super) fn press_step(&mut self, comp: &C, cx: &mut Cx<'_, C>, props: &CollectionProps, layout: &C::ItemLayout, at: Placement) { let Placement { rect, offset, rtl } = at; let ctx = cx.core.ctx.clone(); diff --git a/crates/ui-contract/src/contract/label/step.rs b/crates/ui-contract/src/contract/label/step.rs index 0fc11f381..fa1e7d55d 100644 --- a/crates/ui-contract/src/contract/label/step.rs +++ b/crates/ui-contract/src/contract/label/step.rs @@ -62,11 +62,14 @@ fn field_label(env: &Env, input: &LabelIn<'_>, id: Id, rect: Rect) -> FieldLabel if described.is_empty() { label } else { label.detail(described.join(". ")) } } +/// Draws trailing content in the rect the label step gives it. +pub(crate) type ShowTrailing<'a> = Box; + /// Content the leaf label step shows after the label's text, inside the label (`BodyCx::labelled_with`): its size /// and how to show it in the rect the step gives it. pub(crate) struct Trailing<'a> { pub size: Vec2, - pub show: Box, + pub show: ShowTrailing<'a>, } /// What the label step needs of one leaf child it labels (`PaintUi::labelled`, `BodyCx::labelled`). diff --git a/crates/ui-contract/src/contract/level.rs b/crates/ui-contract/src/contract/level.rs index c2d0656f5..72495f864 100644 --- a/crates/ui-contract/src/contract/level.rs +++ b/crates/ui-contract/src/contract/level.rs @@ -322,10 +322,10 @@ fn snake(name: &str) -> Vec { let starts = c.is_uppercase() && index > 0 && (chars[index - 1].is_lowercase() || chars[index - 1].is_ascii_digit() || chars.get(index + 1).is_some_and(|next| next.is_lowercase())); - if starts || words.is_empty() { - words.push(String::new()); + match words.last_mut() { + Some(word) if !starts => word.extend(c.to_lowercase()), + _ => words.push(c.to_lowercase().collect()), } - words.last_mut().expect("a word").extend(c.to_lowercase()); } words } diff --git a/crates/ui-contract/src/contract/mount.rs b/crates/ui-contract/src/contract/mount.rs index 2b4fa9ad5..44a74515f 100644 --- a/crates/ui-contract/src/contract/mount.rs +++ b/crates/ui-contract/src/contract/mount.rs @@ -71,10 +71,11 @@ pub(super) fn host(props: &ContainerProps, at: &HostCx<'_>, open: bool, title: & } } }; - if (open || mounted.exiting) && opens_dialog(&props.mount) { - if let Some(shell) = at.env.get::().0 { - shell.note_dialog(); - } + if (open || mounted.exiting) + && opens_dialog(&props.mount) + && let Some(shell) = at.env.get::().0 + { + shell.note_dialog(); } mounted } diff --git a/crates/ui-contract/src/contract/overlay/placement.rs b/crates/ui-contract/src/contract/overlay/placement.rs index 9c3224b39..bc2ac5740 100644 --- a/crates/ui-contract/src/contract/overlay/placement.rs +++ b/crates/ui-contract/src/contract/overlay/placement.rs @@ -134,6 +134,10 @@ fn resolved_anchor(ctx: &Context, overlay: &Overlay, resolved: Rect, bounds: Rec /// The room a layer's body is measured in before the layer is placed: `content_room` for the anchor as the host /// resolves it in this pass, inside the screen rect the layer opened in `env` keeps inside. /// `id` is the layer, whose memory holds the pointer where it opened. `own` and `own_to_screen` are the owner's rect and its layer's map to screen space. +#[expect( + clippy::too_many_arguments, + reason = "the measuring room reads the pass facts the caller holds as separate values; a struct would only restate them" +)] pub(crate) fn measuring_room( ctx: &Context, env: &Env, diff --git a/crates/ui-contract/src/contract/run.rs b/crates/ui-contract/src/contract/run.rs index eaa71e805..53c9833b3 100644 --- a/crates/ui-contract/src/contract/run.rs +++ b/crates/ui-contract/src/contract/run.rs @@ -845,6 +845,10 @@ fn create_node(ctx: &Context, ui: &Ui, id: Id, member: bool, role: Role) -> bool } /// Steps 6 to 16 of the pass, run in the `Ui` the host gives. +#[expect( + clippy::cognitive_complexity, + reason = "steps 6 to 16 in their fixed order; each step is already its own function and the rest is the order" +)] fn run_in_host(p: &mut Pass<'_, '_, '_>, ui: &mut Ui, host_at: Option, host_env: Option<&Env>) { let ctx = p.p.core_ref().ctx.clone(); let (id, rtl) = (p.resolved.id, p.env.direction.is_rtl()); @@ -1274,6 +1278,10 @@ fn measured(t: &mut dyn Erased, input: &MeasureIn<'_>, style: &dyn StyleView, re } /// The pipeline: steps 1 to 17 for one component, whatever its type and shape. +#[expect( + clippy::cognitive_complexity, + reason = "steps 1 to 17 in their fixed order; each step is already its own function and the rest is the order" +)] pub(super) fn run(t: &mut dyn Erased, ui: &mut Ui, at: ShowAt, mut tip: Option>) { let ctx = ui.ctx().clone(); let facts = t.facts(); diff --git a/crates/ui-contract/src/contract/run/typed.rs b/crates/ui-contract/src/contract/run/typed.rs index 5ab1cd851..225431bd3 100644 --- a/crates/ui-contract/src/contract/run/typed.rs +++ b/crates/ui-contract/src/contract/run/typed.rs @@ -31,7 +31,14 @@ enum Held<'c, C> { Lent(&'c mut C), } +/// The style step 2 stored for the later steps of the run. +#[expect(clippy::expect_used, reason = "step 2 stores the style before any step that reads it")] +fn step_style(style: &Option>) -> &S { + style.as_deref().expect("step 2 ran") +} + impl Held<'_, C> { + #[expect(clippy::expect_used, reason = "`Owned` holds the component from `new` until `finish`, the only call that empties it")] fn get(&mut self) -> &mut C { match self { Held::Owned(comp) => comp.as_mut().expect("the component is held until `finish`"), @@ -39,6 +46,7 @@ impl Held<'_, C> { } } + #[expect(clippy::expect_used, reason = "`Owned` holds the component from `new` until `finish`, the only call that empties it")] fn get_ref(&self) -> &C { match self { Held::Owned(comp) => comp.as_ref().expect("the component is held until `finish`"), @@ -46,6 +54,7 @@ impl Held<'_, C> { } } + #[expect(clippy::expect_used, clippy::unreachable, reason = "`finish` runs once per show, and only on the component a show owns")] fn take(&mut self) -> C { match self { Held::Owned(comp) => comp.take().expect("`finish` runs once"), @@ -123,22 +132,23 @@ impl Erased for Typed<'_, '_, C> { } fn measure_content(&mut self, input: &MeasureIn<'_>, resolved: &Resolved<'_>) -> (Vec2, Inputs) { - let style = self.style.as_deref().expect("step 2 ran"); + let style = step_style(&self.style); steps::measure_content(self.comp.get(), input, style, resolved, self.shown.as_deref()) } fn measured_extent(&mut self, at: &Measuring<'_, '_>, stage: &mut MemoryStage) -> Vec2 { - let style = self.style.as_deref().expect("step 2 ran"); + let style = step_style(&self.style); let (extent, shown) = measured_extent(self.comp.get(), &mut *self.hooks, at, stage, style, self.shown.take()); self.shown = shown; extent } fn pass_extent(&mut self, at: &Measuring<'_, '_>) -> Vec2 { - let style = self.style.as_deref().expect("step 2 ran"); + let style = step_style(&self.style); self.hooks.pass_extent(self.comp.get(), at, style, self.shown.clone()) } + #[expect(clippy::expect_used, reason = "`Erased::style` produced the style this pipeline now hands back, so its type is `C::Style`")] fn with_cx<'a>(&mut self, core: CxCore<'a>, style: &'a dyn StyleView, rest: &mut dyn FnMut(&mut dyn ErasedPass<'a>) -> bool) { let style = style.as_any().downcast_ref::().expect("the pipeline holds the style `Erased::style` gave"); let events = std::mem::take(&mut self.cancelled); @@ -459,6 +469,7 @@ impl<'a, C: Component> ErasedPass<'a> for TypedPass<'_, 'a, C> { } } +#[expect(clippy::expect_used, reason = "`super::run` runs every step, and the last one sets the output")] fn run(comp: C, ui: &mut Ui, at: ShowAt, tip: Option>, hooks: &mut dyn ShapeHooks) -> C::Output { let mut typed = Typed::new(Held::Owned(Some(comp)), hooks); super::run(&mut typed, ui, at, tip); @@ -533,7 +544,7 @@ fn unshown(comp: &mut C, ui: &Ui) -> Option { } let props = props.clone(); let facts = TypeFacts::of::(); - let source = comp.common(Internal::new()).id.clone(); + let source = comp.common(Internal::new()).id; let id = steps::id(ui, &source, false, false, facts.style_key, facts.name); let output = ::unshown(steps::inert_response(ui, id))?; let sizing = ui.is_sizing_pass(); @@ -606,8 +617,8 @@ pub(crate) fn paint_face(ui: &mut Ui, env: &Env, source: &super::FaceSo let ctx = ui.ctx().clone(); let common = std::mem::take(face.common_mut(Internal::new())); debug_assert!(common.tooltip.is_none(), "a face instance carries no tooltip; use `PartBuilder::tooltip`"); - let step1 = steps::env(&ctx, &env, &common, steps::variants::(common.variant)); - let scx = steps::style_cx(&ctx, &env, &step1); + let step1 = steps::env(&ctx, env, &common, steps::variants::(common.variant)); + let scx = steps::style_cx(&ctx, env, &step1); let scx = source.ink.map_or(scx, |ink| scx.hosted(ink, source.muted)); let style = steps::style::(&ctx, &scx, face.style_key()); let id = face_id(source.id, part); @@ -639,12 +650,12 @@ pub(crate) fn paint_face(ui: &mut Ui, env: &Env, source: &super::FaceSo cx.core.state = state; cx.core.stated = true; cx.core.ink = steps::surface_ink(StyleView::surface(&*style), &state, env.ink); - steps::paint_surface(ui, &env, &cx.core, &*style); + steps::paint_surface(ui, env, &cx.core, &*style); { let results = HashMap::new(); let mut pui = PaintUi { ui: &mut *ui, - env: &env, + env: env, ink: cx.core.ink, // A face of an inactive part paints its data as `draw_part` does for the host. data: if source.result.inactive { crate::primitives::DataMode::Inactive } else { crate::primitives::DataMode::of(&state) }, diff --git a/crates/ui-contract/src/primitives/kit.rs b/crates/ui-contract/src/primitives/kit.rs index e3c9c9638..6052e6f72 100644 --- a/crates/ui-contract/src/primitives/kit.rs +++ b/crates/ui-contract/src/primitives/kit.rs @@ -167,13 +167,13 @@ pub fn fill_polygon(points: &[Pos2], color: Color32, feather: f32) -> Mesh { // An opaque inner and a clear outer vertex per point, half the feather each side of the edge (egui's // `fill_closed_path`), with the normals of egui's `Path::add_line_loop`. let edge_normal = |i: usize| (ring[(i + 1) % n] - ring[i]).normalized().rot90(); - for i in 0..n { + for (i, &point) in ring.iter().enumerate() { let (before, after) = (edge_normal((i + n - 1) % n), edge_normal(i)); let normal = (before + after) * 0.5; let length_sq = normal.length_sq(); let normal = if length_sq > f32::EPSILON { normal / length_sq } else { after }; - mesh.colored_vertex(ring[i] - normal * (0.5 * feather), color); - mesh.colored_vertex(ring[i] + normal * (0.5 * feather), Color32::TRANSPARENT); + mesh.colored_vertex(point - normal * (0.5 * feather), color); + mesh.colored_vertex(point + normal * (0.5 * feather), Color32::TRANSPARENT); } for i in 0..n as u32 { let before = (i + n as u32 - 1) % n as u32; diff --git a/crates/ui-contract/src/primitives/sensing.rs b/crates/ui-contract/src/primitives/sensing.rs index 9221b6330..4ef240097 100644 --- a/crates/ui-contract/src/primitives/sensing.rs +++ b/crates/ui-contract/src/primitives/sensing.rs @@ -608,6 +608,7 @@ pub(crate) struct MemberResult { pub activated: bool, } +#[expect(clippy::unreachable, reason = "`sense_members` returns one result per spec")] pub(crate) fn sense_member(ui: &Ui, arena: ArenaId, spec: MemberSpec<'_>) -> MemberResult { let mut results = sense_members(ui, arena, std::slice::from_ref(&spec)); results.pop().unwrap_or_else(|| unreachable!("one result per member")) diff --git a/crates/ui-contract/src/primitives/text_adapter.rs b/crates/ui-contract/src/primitives/text_adapter.rs index 5e9c290c3..d3a4773df 100644 --- a/crates/ui-contract/src/primitives/text_adapter.rs +++ b/crates/ui-contract/src/primitives/text_adapter.rs @@ -429,6 +429,6 @@ pub(crate) fn run(state: &mut TextState, mut input: AdapterIn<'_>) -> AdapterOut state.focused = shown.focused || input.held; let full = display; let layout = TextLayout::new(shown.galley, false, full); - let baseline = (!layout.full.is_empty()).then(|| shown.galley_pos.y + layout.first_baseline); + let baseline = (!layout.full.is_empty()).then_some(shown.galley_pos.y + layout.first_baseline); AdapterOut { layout, focused: shown.focused, baseline } } diff --git a/crates/ui-contract/src/runtime/egui/fixture.rs b/crates/ui-contract/src/runtime/egui/fixture.rs index 83415d4b6..d5f6309b7 100644 --- a/crates/ui-contract/src/runtime/egui/fixture.rs +++ b/crates/ui-contract/src/runtime/egui/fixture.rs @@ -188,6 +188,7 @@ impl ImeResets { /// Runs one pass of `viewport` at `time` seconds with `events` and `files`, on a window of `native_pixels_per_point` /// (egui's default when `None`). A viewport other than the root is a child window of the root, which stays live. +#[expect(clippy::too_many_arguments, reason = "the arguments are the facts of one frame, and every caller passes them all")] pub(crate) fn run_frame( ctx: &Context, time: f64, diff --git a/crates/ui-contract/src/runtime/egui/injected.rs b/crates/ui-contract/src/runtime/egui/injected.rs index 0dc5ef637..50d682663 100644 --- a/crates/ui-contract/src/runtime/egui/injected.rs +++ b/crates/ui-contract/src/runtime/egui/injected.rs @@ -159,8 +159,9 @@ impl Request { let announce = (self.held.mods != mods).then(|| modifiers_changed(mods)); let events: Frame = announce.into_iter().chain(events).collect(); self.held.apply(&events); + let at = self.steps.len(); self.steps.push(events.into()); - self.steps.last_mut().expect("just pushed") + &mut self.steps[at] } /// A move to `at` unless the pointer is there, with `mods` announced. @@ -339,7 +340,6 @@ pub(crate) fn input_hook(ctx: &Context, input: &mut egui::RawInput) -> bool { let held = injected.held.entry(viewport).or_default(); let before = held.clone(); held.apply(&step.events); - let lane = injected.lanes.get_mut(&viewport).expect("the lane of the popped step"); lane.flight = Some(Flight { step, pass: pass_nr, focus: focused, until, before }); return !lane.queue.is_empty(); } diff --git a/crates/ui-contract/src/runtime/layout_memory.rs b/crates/ui-contract/src/runtime/layout_memory.rs index 3557cf67e..f8e4dc873 100644 --- a/crates/ui-contract/src/runtime/layout_memory.rs +++ b/crates/ui-contract/src/runtime/layout_memory.rs @@ -1261,6 +1261,7 @@ pub(crate) mod guard { /// A service of type `S` is touched. #[cfg(feature = "testing")] + #[expect(clippy::panic, reason = "the guard exists to stop a measuring run that reads a service outside the recorded paths")] pub(crate) fn touch() { if !crate::runtime::egui::fixture::driving() || MEASURING.with(std::cell::Cell::get) == 0 || EMITTING.with(std::cell::Cell::get) > 0 { return; diff --git a/crates/ui-contract/src/runtime/pass_state.rs b/crates/ui-contract/src/runtime/pass_state.rs index 1812a2c3e..5a2ca726a 100644 --- a/crates/ui-contract/src/runtime/pass_state.rs +++ b/crates/ui-contract/src/runtime/pass_state.rs @@ -183,6 +183,7 @@ pub(crate) fn with(ctx: &Context, f: impl FnOnce(&mut S) -> R) let _release = Release(ctx); HELD.with(|held| { let held = held.borrow(); + #[expect(clippy::expect_used, reason = "`hold` has just moved the context's state into this thread")] let held = held.iter().find(|held| held.ctx == *ctx).expect("the state was just taken"); f(&mut S::cell(&held.state).borrow_mut()) }) diff --git a/crates/ui-contract/src/testing/host_key_trials.rs b/crates/ui-contract/src/testing/host_key_trials.rs index 1560e1b39..2e48fe165 100644 --- a/crates/ui-contract/src/testing/host_key_trials.rs +++ b/crates/ui-contract/src/testing/host_key_trials.rs @@ -266,8 +266,10 @@ fn tab_from_nothing(before: Before, shift: bool) -> (Option, bool) { }; let mut frames = Frames::new(); frames.idle(2, &mut show); - if matches!(before, Before::FocusedUnstopped) { - fixture::host_focus(&frames.ctx, unstopped.get().expect("the widget was shown")); + if matches!(before, Before::FocusedUnstopped) + && let Some(id) = unstopped.get() + { + fixture::host_focus(&frames.ctx, id); frames.idle(2, &mut show); } assert_eq!(egui_focused(&frames.ctx), unstopped.get().filter(|_| matches!(before, Before::FocusedUnstopped))); diff --git a/crates/ui-contract/src/testing/snapshot.rs b/crates/ui-contract/src/testing/snapshot.rs index 202803eec..4e7b7ea23 100644 --- a/crates/ui-contract/src/testing/snapshot.rs +++ b/crates/ui-contract/src/testing/snapshot.rs @@ -38,7 +38,7 @@ impl Renderer { /// # Errors /// When wgpu fails to render or read back the image. pub fn render(&mut self, ctx: &Context, mut paint: FullOutput) -> Result { - self.textures.extend(paint.textures_delta.set.iter().map(|(id, _)| *id)); + self.textures.extend(paint.textures_delta.set.keys().copied()); for id in &paint.textures_delta.free { self.textures.remove(id); } diff --git a/crates/vectorcraft-format/src/container.rs b/crates/vectorcraft-format/src/container.rs index 2f81e7bd8..7a26068c6 100644 --- a/crates/vectorcraft-format/src/container.rs +++ b/crates/vectorcraft-format/src/container.rs @@ -19,7 +19,7 @@ pub fn entry(tail: &[u8], [offset, len]: [u64; 2]) -> Option<&[u8]> { /// once. Entries whose different ranges overlap copy the shared bytes once each, and are refused /// once their copies pass that size, as VectorCraft's reader refuses them. Unlike /// [`Image::bytes`], `Entries` puts no limit on one entry: VectorCraft opens an uncompressed file -/// whose entry is larger than [`MAX_ENTRY`]. +/// whose entry is larger than [`crate::MAX_ENTRY`]. #[derive(Debug, Clone)] pub struct Entries<'a> { tail: &'a [u8], @@ -240,7 +240,7 @@ pub struct Tail<'a> { } impl<'a> Tail<'a> { - /// An empty tail for a file of `version`, which is the file's own `version`; [`File::tail`] + /// An empty tail for a file of `version`, which is the file's own `version`; [`crate::File::tail`] /// takes it from the file. pub fn new(version: u32) -> Self { Self { parts: vec![], len: 0, after: version >= TAIL_SINCE } diff --git a/crates/video/src/prores/decode.rs b/crates/video/src/prores/decode.rs index b3ab03bfe..f29981220 100644 --- a/crates/video/src/prores/decode.rs +++ b/crates/video/src/prores/decode.rs @@ -584,7 +584,6 @@ mod alpha_decode_tests { use crate::prores::bits::{Sink, Writer}; use crate::prores::encode::encode_alpha; - #[test] #[test] fn custom_limits_preserve_large_4444_geometry_before_allocating() { let hdr = FrameHeader { @@ -622,6 +621,8 @@ mod alpha_decode_tests { let too_few_pixels = DecodeLimits { max_pixels: 8192 * 8192 - 1, ..soundcraft }; assert!(matches!(decode_frame_with_limits(&data, &DecodeOptions::default(), &too_few_pixels), Err(Error::Unsupported("frame size")))); } + + #[test] fn alpha_decoder_requires_complete_bounded_runs() { let mut out = [0u16; 1]; assert!(decode_alpha(&[], AlphaType::Bits16, &mut out).is_err()); diff --git a/crates/web-host/src/lib.rs b/crates/web-host/src/lib.rs index 72d2f022a..90e2aa070 100644 --- a/crates/web-host/src/lib.rs +++ b/crates/web-host/src/lib.rs @@ -9,7 +9,7 @@ //! | `ready` | app → host | `version`, `appVersion?`, `file?` (`true`: it reads a `File`/`Blob` in slices) | //! | `host` | host → app | `version`, `handoff?` (`true`: the host routes hand-offs) | //! | `open` | host → app | `name`, and `bytes` or `file` + `size` | -//! | `attach-pdf` | host → app | `name`, `bytes`, `page` (from 1), `insertion` ([x,y,z]), `width`, `height` in drawing units | +//! | `attach-pdf` | host → app | `name`, `bytes`, `page` (from 1), `insertion` (`[x, y, z]`), `width`, `height` in drawing units | //! | `save` | app → host | `name`, `bytes`, `id?`, `saveAs?` | //! | `saved` | host → app | `id` | //! | `dirty` | app → host | `dirty` |