From 20287bf3fa157a97119639c51cd6991ba59db033 Mon Sep 17 00:00:00 2001 From: FredApps Date: Thu, 19 Nov 2026 08:15:23 +0100 Subject: [PATCH 1/6] Index inspected elements for focus and labels --- crates/ui-contract/src/runtime/inspect.rs | 28 ++++++++++++++++------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/crates/ui-contract/src/runtime/inspect.rs b/crates/ui-contract/src/runtime/inspect.rs index 18e4138cf..d74c99414 100644 --- a/crates/ui-contract/src/runtime/inspect.rs +++ b/crates/ui-contract/src/runtime/inspect.rs @@ -307,8 +307,13 @@ fn finish(ctx: &Context, open: Open) -> Recorded { .into_iter() .map(|(owner, part, rect)| HitArea { owner, part, rect: from_screen * rect }) .collect(); + // Keep the first occurrence, matching the tree-order lookup when an id appears more than once. + let mut index = std::collections::HashMap::new(); + for (at, element) in elements.iter().enumerate() { + index.entry((element.id, element.part)).or_insert(at); + } for (node, label) in labels { - let facts = elements.iter_mut().find(|element| element.id == node && element.part.is_none()).and_then(|element| element.facts.as_mut()); + let facts = index.get(&(node, None)).and_then(|&at| elements[at].facts.as_mut()); if let Some(facts) = facts { facts.labelled_by.push(label); } @@ -320,20 +325,27 @@ fn finish(ctx: &Context, open: Open) -> Recorded { let key = |hit: &HitArea| (place.get(&hit.owner).copied(), hit.rect.min.y, hit.rect.min.x); key(a).partial_cmp(&key(b)).unwrap_or(std::cmp::Ordering::Equal) }); - for (at, (id, part)) in focus::tab_order(ctx, |id| ids.contains(&id)).into_iter().enumerate() { - let index = match elements.iter().position(|element| element.id == id && element.part == part) { - Some(index) => index, + for (stop, (id, part)) in focus::tab_order(ctx, |id| ids.contains(&id)).into_iter().enumerate() { + let at = match index.get(&(id, part)).copied() { + Some(at) => at, None => { // A part with no node of its own: listed after its component, where its hit area is. - let Some(owner) = elements.iter().position(|element| element.id == id && element.part.is_none()) else { continue }; + let Some(owner) = index.get(&(id, None)).copied() else { continue }; let rect = hits.iter().find(|hit| hit.owner == id && hit.part == part).map_or(elements[owner].rect, |hit| hit.rect); let depth = elements[owner].depth + 1; let element = Element { id, part, component: elements[owner].component, depth, rect, content: rect, facts: None, stop: None }; - elements.insert(owner + 1, element); - owner + 1 + let at = owner + 1; + elements.insert(at, element); + for old in index.values_mut() { + if *old >= at { + *old += 1; + } + } + index.insert((id, part), at); + at } }; - elements[index].stop = Some(at + 1); + elements[at].stop = Some(stop + 1); } Recorded { elements, hits } } From 5b12fdd273bdcc2b404f5aa20b401a6ec320a8d5 Mon Sep 17 00:00:00 2001 From: FredApps Date: Thu, 19 Nov 2026 08:18:03 +0100 Subject: [PATCH 2/6] Skip undeclared parts outside declaration trials --- crates/ui-contract/src/contract/run.rs | 12 ++++-- crates/ui-contract/src/contract/steps.rs | 4 +- .../ui-contract/src/contract/steps/parts.rs | 1 + crates/ui-contract/src/testing/contract.rs | 30 ++++++++++++++ crates/ui-contract/src/testing/suite/shape.rs | 15 ++++++- crates/ui-contract/tests/it/contract/fixes.rs | 39 +++++++++++++++++++ 6 files changed, 96 insertions(+), 5 deletions(-) diff --git a/crates/ui-contract/src/contract/run.rs b/crates/ui-contract/src/contract/run.rs index fa0d9923d..95a70b207 100644 --- a/crates/ui-contract/src/contract/run.rs +++ b/crates/ui-contract/src/contract/run.rs @@ -939,16 +939,22 @@ fn sense_steps(p: &mut Pass<'_, '_, '_>, ui: &mut Ui, host_at: Option, e if !inert && facts.text() { parts.text.commit_now = focus::commit_now(&ctx) == Some(id); } - // A component that declares no parts skips the step; a debug build runs it anyway to check the declaration. let declares_parts = facts.parts || e.declares_parts(); - if !inert && (declares_parts || cfg!(debug_assertions)) { + #[cfg(feature = "testing")] + let checking_parts = !inert && !declares_parts && crate::testing::contract::checking_parts(); + #[cfg(not(feature = "testing"))] + let checking_parts = false; + if !inert && (declares_parts || checking_parts) { let input = MeasureIn { ui: &*ui, env, proposal: Proposal::Ideal, room: p.room }; e.parts(rect, flow, content_rect, &mut parts, &input, rtl); } + #[cfg(feature = "testing")] + if checking_parts && !declares_parts && !steps::declares_none(&parts) { + crate::testing::contract::bad_parts(facts.name); + } if facts.canvas_control && p.trace.recording() { inspect::canvas_control(&ctx, facts.name); } - debug_assert!(declares_parts || steps::declares_none(&parts), "`{}` sets `PARTS = false` and declares a part", facts.name); steps::check_parts(&ctx, facts.name, &parts); let keys = e.keys(); let (holder_widget, text_keys) = text_holder(&ctx, id, &parts, keys, &mut *e.core().memory); diff --git a/crates/ui-contract/src/contract/steps.rs b/crates/ui-contract/src/contract/steps.rs index 3d4f3551e..6c8b9c22c 100644 --- a/crates/ui-contract/src/contract/steps.rs +++ b/crates/ui-contract/src/contract/steps.rs @@ -31,7 +31,9 @@ pub(crate) use id::{claim_id, draft, id, keeping_ids}; pub(crate) use label::scrub_by_label; pub(crate) use measure::{MeasureIn, guard, measure, measure_content, measure_cx, padding, whole}; pub(crate) use paint::{Fade, UnderVeil, fade, next_shape, paint_focus, paint_part_layers, paint_surface, surface_ink, unfade}; -pub(crate) use parts::{PartsStep, check_parts, declares_none}; +#[cfg(feature = "testing")] +pub(crate) use parts::declares_none; +pub(crate) use parts::{PartsStep, check_parts}; pub(crate) use place::place; pub(crate) use report::{ReportIn, report, report_inert, report_parts, validity_of}; #[cfg(feature = "testing")] diff --git a/crates/ui-contract/src/contract/steps/parts.rs b/crates/ui-contract/src/contract/steps/parts.rs index 455ffc0d7..f09043f22 100644 --- a/crates/ui-contract/src/contract/steps/parts.rs +++ b/crates/ui-contract/src/contract/steps/parts.rs @@ -14,6 +14,7 @@ pub(crate) struct PartsStep { } /// Whether step 7 declared no parts, no roving group, no scroll part and no text, editor or selection part. +#[cfg(feature = "testing")] pub(crate) fn declares_none(parts: &PartsStep) -> bool { parts.decls.is_empty() && parts.rovings.is_empty() diff --git a/crates/ui-contract/src/testing/contract.rs b/crates/ui-contract/src/testing/contract.rs index f7c0ae238..d5631f3df 100644 --- a/crates/ui-contract/src/testing/contract.rs +++ b/crates/ui-contract/src/testing/contract.rs @@ -48,3 +48,33 @@ pub fn raw_widget(ui: &mut egui::Ui, rect: egui::Rect) { pub fn allocate(ui: &mut egui::Ui, size: egui::Vec2) { crate::runtime::egui::fixture::allocate_blocker(ui, size); } + +thread_local! { + static PARTS_CHECK: std::cell::RefCell>> = const { std::cell::RefCell::new(None) }; +} + +/// Run a story with the parts declaration check enabled, and return any offending component types. +pub(crate) fn check_parts_declarations(run: impl FnOnce()) -> Vec<&'static str> { + struct Reset; + impl Drop for Reset { + fn drop(&mut self) { + PARTS_CHECK.with(|check| *check.borrow_mut() = None); + } + } + PARTS_CHECK.with(|check| *check.borrow_mut() = Some(Vec::new())); + let _reset = Reset; + run(); + PARTS_CHECK.with(|check| check.borrow_mut().take().unwrap_or_default()) +} + +pub(crate) fn checking_parts() -> bool { + PARTS_CHECK.with(|check| check.borrow().is_some()) +} + +pub(crate) fn bad_parts(component: &'static str) { + PARTS_CHECK.with(|check| { + if let Some(bad) = check.borrow_mut().as_mut() { + bad.push(component); + } + }); +} diff --git a/crates/ui-contract/src/testing/suite/shape.rs b/crates/ui-contract/src/testing/suite/shape.rs index a2d80820b..0117b2474 100644 --- a/crates/ui-contract/src/testing/suite/shape.rs +++ b/crates/ui-contract/src/testing/suite/shape.rs @@ -4,7 +4,20 @@ use super::{ANY, Case, Subject}; use crate::testing::fixture::Fixture; use egui::{Rect, Vec2}; -pub(super) const CASES: &[Case] = &[Case::new("paints-inside", ANY, small_rooms_paint_inside_the_shown_rect)]; +pub(super) const CASES: &[Case] = + &[Case::new("paints-inside", ANY, small_rooms_paint_inside_the_shown_rect), Case::new("parts-declaration", ANY, parts_declaration)]; + +fn parts_declaration(subject: &Subject) -> Result<(), String> { + for story in &subject.stories { + let bad = crate::testing::contract::check_parts_declarations(|| { + Fixture::story(story).frame(Vec::new()); + }); + if !bad.is_empty() { + return Err(format!("{}: components with PARTS = false declared parts: {bad:?}", story.name)); + } + } + Ok(()) +} /// The slack between a painted bound and the shown rect: the rounding of the layout, as the layout cases allow. A /// shape's own slack adds half its stroke width. diff --git a/crates/ui-contract/tests/it/contract/fixes.rs b/crates/ui-contract/tests/it/contract/fixes.rs index fc1da8d47..1084dba64 100644 --- a/crates/ui-contract/tests/it/contract/fixes.rs +++ b/crates/ui-contract/tests/it/contract/fixes.rs @@ -237,3 +237,42 @@ fn the_step_log_is_kept_in_fixture_frames_only() { let id = seen.borrow().id.expect("the probe ran"); assert!(steps(&app.ctx, id).is_empty(), "an app frame records no steps"); } + +/// A component whose declaration says the pipeline need not run its parts hook. +#[derive(Component)] +struct NoParts<'a> { + #[common] + common: Common, + calls: &'a std::cell::Cell, +} + +impl Component for NoParts<'_> { + const ROLE: Role = Role::None; + const PARTS: bool = false; + type Style = PlainStyle; + type Output = Response; + + fn style(_: &StyleCx<'_>, _: NoPartsStyleKey) -> PlainStyle { + PlainStyle::default() + } + + fn parts(&mut self, _: Rect, _: &mut PartsCx<'_, Self>) { + self.calls.set(self.calls.get() + 1); + } + + fn paint(&mut self, _: &mut PaintUi<'_>, _: &Cx<'_, Self>) {} + + fn finish(self, cx: Cx<'_, Self>) -> Response { + cx.response.clone() + } +} + +#[trial] +fn a_component_declaring_no_parts_skips_the_parts_hook() { + let mut frames = Frames::new(); + let calls = std::cell::Cell::new(0); + frames.frame(vec![], |ui| { + NoParts { common: Common::new(), calls: &calls }.show(ui); + }); + assert_eq!(calls.get(), 0, "the parts hook is skipped on ordinary runs"); +} From 0c076f890be0bfd5447563b9fc7a47e040df4077 Mon Sep 17 00:00:00 2001 From: FredApps Date: Thu, 19 Nov 2026 09:19:37 +0100 Subject: [PATCH 3/6] ui-contract: record steps only inside an inspected region --- crates/ui-contract/src/contract/run.rs | 2 +- crates/ui-contract/src/runtime/inspect.rs | 20 ++++++++----------- crates/ui-contract/src/testing/contract.rs | 3 ++- crates/ui-contract/tests/it/contract/fixes.rs | 11 ++++++---- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/crates/ui-contract/src/contract/run.rs b/crates/ui-contract/src/contract/run.rs index 95a70b207..38c39078b 100644 --- a/crates/ui-contract/src/contract/run.rs +++ b/crates/ui-contract/src/contract/run.rs @@ -952,7 +952,7 @@ fn sense_steps(p: &mut Pass<'_, '_, '_>, ui: &mut Ui, host_at: Option, e if checking_parts && !declares_parts && !steps::declares_none(&parts) { crate::testing::contract::bad_parts(facts.name); } - if facts.canvas_control && p.trace.recording() { + if facts.canvas_control && !ui.is_sizing_pass() { inspect::canvas_control(&ctx, facts.name); } steps::check_parts(&ctx, facts.name, &parts); diff --git a/crates/ui-contract/src/runtime/inspect.rs b/crates/ui-contract/src/runtime/inspect.rs index d74c99414..07ae009fd 100644 --- a/crates/ui-contract/src/runtime/inspect.rs +++ b/crates/ui-contract/src/runtime/inspect.rs @@ -1,5 +1,5 @@ -//! Decision records and findings: what each pipeline step did, kept in frames a test fixture drives and inside an -//! inspected region ([`record`]). The region's record is what the debug inspector draws: every component shown in it +//! Decision records and findings. Inspected regions ([`record`]) collect pipeline steps. Fixture frames also collect +//! contract findings. The region's record is what the debug inspector draws: every component shown in it //! with its box and access facts, the hit areas the sensing core registered and the focus stops in Tab order. use crate::runtime::egui::areas; @@ -35,9 +35,9 @@ pub(crate) struct Log { kept: IdMap, } -/// Whether records are kept: in frames a test fixture drives, and inside an inspected region in any build. +/// Whether an explicit inspector region is collecting elements and their pipeline steps. pub(crate) fn recording(ctx: &Context) -> bool { - fixture_frame() || pass_state::with::(ctx, |log| !log.open.is_empty()) + pass_state::with::(ctx, |log| !log.open.is_empty()) } #[cfg(feature = "testing")] @@ -50,16 +50,12 @@ fn fixture_frame() -> bool { /// Starts the step record of `id` for a new show. pub(crate) fn begin(ctx: &Context, id: Id) { - if recording(ctx) { - pass_state::with::(ctx, |log| log.steps.insert(id, Vec::new())); - } + pass_state::with::(ctx, |log| log.steps.insert(id, Vec::new())); } /// Records that `step` ran for `id`. pub(crate) fn step(ctx: &Context, id: Id, step: &'static str) { - if recording(ctx) { - pass_state::with::(ctx, |log| log.steps.entry(id).or_default().push(step)); - } + pass_state::with::(ctx, |log| log.steps.entry(id).or_default().push(step)); } /// The steps the latest show of `id` ran, in order. @@ -70,7 +66,7 @@ pub(crate) fn steps_of(ctx: &Context, id: Id) -> Vec<&'static str> { /// Reports a finding. pub(crate) fn finding(ctx: &Context, finding: Finding) { - if !recording(ctx) { + if !fixture_frame() && !recording(ctx) { return; } pass_state::with::(ctx, |log| { @@ -89,7 +85,7 @@ pub(crate) fn findings(ctx: &Context) -> Vec { /// Records that the canvas control `type_name` showed in this pass, so the canvas-control cases can check that a /// press away from its parts reaches the tool. pub(crate) fn canvas_control(ctx: &Context, type_name: &'static str) { - if !recording(ctx) { + if !fixture_frame() && !recording(ctx) { return; } pass_state::with::(ctx, |log| { diff --git a/crates/ui-contract/src/testing/contract.rs b/crates/ui-contract/src/testing/contract.rs index d5631f3df..ee978c6af 100644 --- a/crates/ui-contract/src/testing/contract.rs +++ b/crates/ui-contract/src/testing/contract.rs @@ -3,7 +3,8 @@ use crate::runtime::inspect::{self, Finding}; use egui::{Context, Id}; -/// The steps the latest show of `id` ran, in order. +/// The steps the latest inspected show of `id` ran, in order. Wrap the show in +/// [`crate::runtime::inspect::record`] to collect its steps. pub fn steps(ctx: &Context, id: Id) -> Vec<&'static str> { inspect::steps_of(ctx, id) } diff --git a/crates/ui-contract/tests/it/contract/fixes.rs b/crates/ui-contract/tests/it/contract/fixes.rs index 1084dba64..cd8338733 100644 --- a/crates/ui-contract/tests/it/contract/fixes.rs +++ b/crates/ui-contract/tests/it/contract/fixes.rs @@ -216,17 +216,20 @@ fn a_style_value_set_in_content_env_changes_a_body_childs_style() { assert!(inside > outside, "the body's child read the body's value: {outside} -> {inside}"); } -/// The step log, a record only trials and the debug inspector read, is kept in frames a test fixture drives; a frame -/// an app drives itself, such as the gallery's, keeps none. +/// A fixture pays for pipeline step records only when the caller inspects a region. #[trial] -fn the_step_log_is_kept_in_fixture_frames_only() { +fn the_step_log_is_kept_only_for_an_inspected_region() { let mut fixture = Frames::new(); let seen = RefCell::new(Seen::default()); fixture.frame(Vec::new(), |ui| { Probe::new(&seen).show(ui); }); let id = seen.borrow().id.expect("the probe ran"); - assert!(!steps(&fixture.ctx, id).is_empty(), "a fixture frame records the probe's steps"); + assert!(steps(&fixture.ctx, id).is_empty(), "an ordinary fixture frame has no step log"); + fixture.frame(Vec::new(), |ui| { + craft_ui::runtime::inspect::record(ui, egui::Id::unique("inspect probe"), |ui| Probe::new(&seen).show(ui)); + }); + assert!(!steps(&fixture.ctx, seen.borrow().id.expect("the inspected probe ran")).is_empty()); let app = Frames::new(); let seen = RefCell::new(Seen::default()); From 50812ec37cb2453a6b1d175ada33c39cad7f726a Mon Sep 17 00:00:00 2001 From: FredApps Date: Thu, 19 Nov 2026 09:58:09 +0100 Subject: [PATCH 4/6] Use the declarations slice for the suite assertion --- crates/ui-contract/src/contract/cx/parts.rs | 4 ---- crates/ui-contract/src/contract/steps/parts.rs | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/crates/ui-contract/src/contract/cx/parts.rs b/crates/ui-contract/src/contract/cx/parts.rs index 61c358b8b..50b702c77 100644 --- a/crates/ui-contract/src/contract/cx/parts.rs +++ b/crates/ui-contract/src/contract/cx/parts.rs @@ -52,10 +52,6 @@ impl Decls { &self.parts } - pub(crate) fn is_empty(&self) -> bool { - self.parts.is_empty() - } - pub(crate) fn iter(&self) -> std::iter::Zip, std::slice::Iter<'_, PartExtras>> { self.parts.iter().zip(&self.extras) } diff --git a/crates/ui-contract/src/contract/steps/parts.rs b/crates/ui-contract/src/contract/steps/parts.rs index f09043f22..4e1dc0e0d 100644 --- a/crates/ui-contract/src/contract/steps/parts.rs +++ b/crates/ui-contract/src/contract/steps/parts.rs @@ -16,7 +16,7 @@ pub(crate) struct PartsStep { /// Whether step 7 declared no parts, no roving group, no scroll part and no text, editor or selection part. #[cfg(feature = "testing")] pub(crate) fn declares_none(parts: &PartsStep) -> bool { - parts.decls.is_empty() + parts.decls.parts().is_empty() && parts.rovings.is_empty() && parts.scrolls.is_empty() && parts.text.decl.is_none() From 448e8d4bfca8ffeed8547f97668b02844ddaa28e Mon Sep 17 00:00:00 2001 From: FredApps Date: Thu, 19 Nov 2026 14:44:36 +0100 Subject: [PATCH 5/6] Test parts declaration guard and inspector focus order --- crates/ui-contract/src/testing/contract.rs | 10 +-- crates/ui-contract/tests/it/contract/fixes.rs | 87 ++++++++++++++++++- 2 files changed, 89 insertions(+), 8 deletions(-) diff --git a/crates/ui-contract/src/testing/contract.rs b/crates/ui-contract/src/testing/contract.rs index ee978c6af..4daf52d18 100644 --- a/crates/ui-contract/src/testing/contract.rs +++ b/crates/ui-contract/src/testing/contract.rs @@ -55,15 +55,15 @@ thread_local! { } /// Run a story with the parts declaration check enabled, and return any offending component types. -pub(crate) fn check_parts_declarations(run: impl FnOnce()) -> Vec<&'static str> { - struct Reset; +pub fn check_parts_declarations(run: impl FnOnce()) -> Vec<&'static str> { + struct Reset(Option>); impl Drop for Reset { fn drop(&mut self) { - PARTS_CHECK.with(|check| *check.borrow_mut() = None); + PARTS_CHECK.with(|check| *check.borrow_mut() = self.0.take()); } } - PARTS_CHECK.with(|check| *check.borrow_mut() = Some(Vec::new())); - let _reset = Reset; + let previous = PARTS_CHECK.with(|check| check.replace(Some(Vec::new()))); + let _reset = Reset(previous); run(); PARTS_CHECK.with(|check| check.borrow_mut().take().unwrap_or_default()) } diff --git a/crates/ui-contract/tests/it/contract/fixes.rs b/crates/ui-contract/tests/it/contract/fixes.rs index cd8338733..dccd6512b 100644 --- a/crates/ui-contract/tests/it/contract/fixes.rs +++ b/crates/ui-contract/tests/it/contract/fixes.rs @@ -247,6 +247,7 @@ struct NoParts<'a> { #[common] common: Common, calls: &'a std::cell::Cell, + declare: bool, } impl Component for NoParts<'_> { @@ -256,11 +257,14 @@ impl Component for NoParts<'_> { type Output = Response; fn style(_: &StyleCx<'_>, _: NoPartsStyleKey) -> PlainStyle { - PlainStyle::default() + PlainStyle::min(Vec2::splat(20.0)) } - fn parts(&mut self, _: Rect, _: &mut PartsCx<'_, Self>) { + fn parts(&mut self, rect: Rect, cx: &mut PartsCx<'_, Self>) { self.calls.set(self.calls.get() + 1); + if self.declare { + cx.part(craft_behavior::PartKey::new("unexpected"), rect); + } } fn paint(&mut self, _: &mut PaintUi<'_>, _: &Cx<'_, Self>) {} @@ -275,7 +279,84 @@ fn a_component_declaring_no_parts_skips_the_parts_hook() { let mut frames = Frames::new(); let calls = std::cell::Cell::new(0); frames.frame(vec![], |ui| { - NoParts { common: Common::new(), calls: &calls }.show(ui); + NoParts { common: Common::new(), calls: &calls, declare: false }.show(ui); }); assert_eq!(calls.get(), 0, "the parts hook is skipped on ordinary runs"); } + +#[trial] +fn parts_declaration_checks_report_bad_components_and_restore_nested_checks() { + use craft_ui::testing::contract::check_parts_declarations; + let calls = std::cell::Cell::new(0); + let show = || { + Frames::new().frame(vec![], |ui| { + NoParts { common: Common::new(), calls: &calls, declare: true }.show(ui); + }); + }; + let outer = check_parts_declarations(|| { + show(); + let inner = check_parts_declarations(show); + assert!(inner.iter().any(|name| name.contains("NoParts")), "{inner:?}"); + show(); + }); + assert!(outer.len() >= 2 && outer.iter().all(|name| name.contains("NoParts")), "{outer:?}"); + + let panic = std::panic::catch_unwind(|| check_parts_declarations(|| panic!("guard test"))); + assert!(panic.is_err()); + let before = calls.get(); + show(); + assert_eq!(calls.get(), before, "the check is disabled after unwinding"); +} + +#[derive(Component)] +struct FocusParts { + #[common] + common: Common, +} + +impl Component for FocusParts { + const ROLE: Role = Role::None; + type Style = PlainStyle; + type Output = Response; + + fn style(_: &StyleCx<'_>, _: FocusPartsStyleKey) -> PlainStyle { + PlainStyle::min(Vec2::splat(20.0)) + } + + fn sense(&self) -> Sense { + Sense::empty() + } + + fn parts(&mut self, rect: Rect, cx: &mut PartsCx<'_, Self>) { + cx.part(craft_behavior::PartKey::new("first"), rect).focusable(); + cx.part(craft_behavior::PartKey::new("second"), rect).focusable(); + } + + fn finish(self, cx: Cx<'_, Self>) -> Response { + cx.response.clone() + } +} + +#[trial] +fn inspector_places_synthetic_focus_parts_after_each_owner() { + let mut frames = Frames::new(); + let mut recorded = None; + let mut ids = Vec::new(); + frames.frame(vec![], |ui| { + let (shown, record) = craft_ui::runtime::inspect::record(ui, named_id("focus-region"), |ui| { + ["one", "two"].map(|salt| FocusParts { common: Common::new() }.id_salt(salt).show(ui).id) + }); + ids = shown.to_vec(); + recorded = record; + }); + let record = recorded.expect("real pass was recorded"); + let mut stops = Vec::new(); + for id in ids { + let owner = record.elements.iter().position(|element| element.id == id && element.part.is_none()).unwrap(); + let parts = &record.elements[owner + 1..owner + 3]; + assert!(parts.iter().all(|part| part.id == id && part.part.is_some() && part.facts.is_none()), "{parts:?}"); + stops.extend(parts.iter().map(|part| part.stop.expect("part is a focus stop"))); + } + stops.sort_unstable(); + assert_eq!(stops, [1, 2, 3, 4]); +} From 2287e9f3d17d59784718b89f0166eb06040f742e Mon Sep 17 00:00:00 2001 From: aiongg Date: Thu, 19 Nov 2026 14:59:11 +0000 Subject: [PATCH 6/6] design-lint: bind_tracked!'s own definition is not a call of __split_for_bind --- crates/design-lint/src/contract/global_state.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/crates/design-lint/src/contract/global_state.rs b/crates/design-lint/src/contract/global_state.rs index 1da609cd7..75208f2ec 100644 --- a/crates/design-lint/src/contract/global_state.rs +++ b/crates/design-lint/src/contract/global_state.rs @@ -24,8 +24,10 @@ const PATH_FS: [&str; 2] = ["std", "fs"]; const PLAIN_DATA: &str = "contract/no-global-state:plain-data"; const PROJECTION: &str = "contract/no-global-state:projection"; -/// The hidden `Tracked::__split_for_bind`, called only by `bind_tracked!`; the lint reads source before macro expansion, so every textual hit is a direct call. +/// The hidden `Tracked::__split_for_bind`, called only by `bind_tracked!`; the lint reads source before macro expansion, so every textual hit outside its definition is a direct call. const SPLIT_FOR_BIND: &str = "__split_for_bind"; +/// The macro that calls [`SPLIT_FOR_BIND`]; its definition is not a call site. +const BIND_TRACKED: &str = "bind_tracked"; struct Hits { found: Vec<(proc_macro2::Span, String, String)>, @@ -110,6 +112,10 @@ impl Visit<'_> for Hits { } fn visit_item_macro(&mut self, node: &ItemMacro) { + // `bind_tracked!`'s own definition is the one place that names the hidden call. + if node.mac.path.is_ident("macro_rules") && node.ident.as_ref().is_some_and(|i| i == BIND_TRACKED) { + return; + } self.macro_path(&node.mac); visit::visit_item_macro(self, node); }