diff --git a/crates/design-lint/src/workspace.rs b/crates/design-lint/src/workspace.rs index 80d4f53f8..3c57cd1cd 100644 --- a/crates/design-lint/src/workspace.rs +++ b/crates/design-lint/src/workspace.rs @@ -135,6 +135,8 @@ const NO_GLOBAL_STATE_PREFIXES: &[&str] = &[ /// a `static` or `thread_local!` item or [`FS`] for `std::fs`. Each group names the settled fact or environment key that /// covers it, or the later task of craft-libs#2336 that removes the state. A new item in these files is flagged. const NO_GLOBAL_STATE: &[(&str, &str)] = &[ + // Compile-time registry discovery reads the defining crate's source, never a view input. + ("crates/ui-macros/src/registry.rs", FS), // The trait's home crate: it implements `MemoProps` by hand for std and framework value types. ("crates/ui-contract/src/contract/memo.rs", "MemoProps"), // Settled fact: constant font bytes, decompressed once from compile-time input and immutable after init. diff --git a/crates/ui-contract/src/testing/story.rs b/crates/ui-contract/src/testing/story.rs index eea92afa7..a60f60d16 100644 --- a/crates/ui-contract/src/testing/story.rs +++ b/crates/ui-contract/src/testing/story.rs @@ -178,6 +178,7 @@ impl Story { /// A story registered by `#[story]`, linked to its type by the type's registered name. #[doc(hidden)] +#[derive(Clone, Copy)] #[non_exhaustive] pub struct StoryRegistration { /// The package that declares the story. diff --git a/crates/ui-gallery/src/chrome/card.rs b/crates/ui-gallery/src/chrome/card.rs index 75754c601..66957596c 100644 --- a/crates/ui-gallery/src/chrome/card.rs +++ b/crates/ui-gallery/src/chrome/card.rs @@ -61,14 +61,14 @@ pub struct CardStory<'a> { /// The index of the story in the catalog: the key of its state. pub index: usize, /// The story. - pub story: &'static StoryRegistration, + pub story: StoryRegistration, /// The story's caption. pub caption: &'a str, } impl<'a> CardStory<'a> { /// The story at catalog index `index`, under `caption`. - pub fn new(index: usize, story: &'static StoryRegistration, caption: &'a str) -> Self { + pub fn new(index: usize, story: StoryRegistration, caption: &'a str) -> Self { CardStory { index, story, caption } } } @@ -241,7 +241,7 @@ pub struct StoryBody { /// The id scope of the story: unique among the stories of a pass. pub key: String, /// The story. - pub story: &'static StoryRegistration, + pub story: StoryRegistration, /// The surface the story sits on. pub surface: Surface, /// The most a story that fills takes. @@ -268,7 +268,7 @@ pub struct BodyShown { impl StoryBody { /// The body of `story` on `surface`, in the window's look, with ungated wheel takers. - pub fn new(key: impl Into, story: &'static StoryRegistration, surface: Surface, room: f32, panel_pad: Pad) -> Self { + pub fn new(key: impl Into, story: StoryRegistration, surface: Surface, room: f32, panel_pad: Pad) -> Self { StoryBody { key: key.into(), story, surface, room, look: Look::default(), gated: false, panel_pad, caption: None, inspect: None } } diff --git a/crates/ui-gallery/src/chrome/overview.rs b/crates/ui-gallery/src/chrome/overview.rs index f9892f4bd..6255b3aec 100644 --- a/crates/ui-gallery/src/chrome/overview.rs +++ b/crates/ui-gallery/src/chrome/overview.rs @@ -36,7 +36,7 @@ pub struct SpecStory { /// The index of the story in the catalog. pub index: usize, /// The story's registration. - pub story: &'static StoryRegistration, + pub story: StoryRegistration, /// The story's caption. pub caption: String, } diff --git a/crates/ui-gallery/src/lib.rs b/crates/ui-gallery/src/lib.rs index ac528766e..a83fd504d 100644 --- a/crates/ui-gallery/src/lib.rs +++ b/crates/ui-gallery/src/lib.rs @@ -72,9 +72,8 @@ pub fn register_all(registry: &mut craft_ui::testing::Registry) { } /// The registry of the viewer and the crates whose stories it shows. -pub fn registry() -> &'static craft_ui::testing::Registry { - static REGISTRY: std::sync::OnceLock = std::sync::OnceLock::new(); - REGISTRY.get_or_init(|| craft_ui::testing::Registry::of(&[register_all])) +pub fn registry() -> craft_ui::testing::Registry { + craft_ui::testing::Registry::of(&[register_all]) } /// How many registrations each selected crate contributes, and how many stories there are in all. diff --git a/crates/ui-gallery/src/viewer/catalog.rs b/crates/ui-gallery/src/viewer/catalog.rs index df7280146..9b3b47b20 100644 --- a/crates/ui-gallery/src/viewer/catalog.rs +++ b/crates/ui-gallery/src/viewer/catalog.rs @@ -10,7 +10,7 @@ use std::sync::OnceLock; #[non_exhaustive] pub struct Entry { /// The registration. - pub registration: &'static StoryRegistration, + pub registration: StoryRegistration, /// The registered name of the type the story shows. pub type_name: &'static str, } @@ -109,7 +109,8 @@ pub fn fold_filter(filter: &str) -> String { pub(crate) fn linked_catalog() -> &'static contract::Catalog { static CATALOG: OnceLock = OnceLock::new(); CATALOG.get_or_init(|| { - let registrations: Vec<_> = crate::registry().registrations().iter().collect(); + let registry = crate::registry(); + let registrations: Vec<_> = registry.registrations().iter().collect(); contract::catalog(®istrations) }) } @@ -121,7 +122,7 @@ pub fn display_name(type_name: &str) -> String { /// Every story linked into the viewer, ordered by type then story name. pub fn entries() -> Vec { - crate::registry().stories().iter().map(|registration| Entry { registration, type_name: (registration.type_name)() }).collect() + crate::registry().stories().iter().map(|registration| Entry { registration: *registration, type_name: (registration.type_name)() }).collect() } /// What a registration says about a type: where it is declared and what it is for. @@ -133,7 +134,7 @@ pub struct Declared { /// The first sentence of the type's doc comment. pub purpose: &'static str, /// The component probe; `None` for a pattern. - pub probe: Option<&'static Probe>, + pub probe: Option, } /// The registration of each registered component and pattern type, by the type's registered name. @@ -142,7 +143,7 @@ pub fn declared() -> HashMap<&'static str, Declared> { for registration in crate::registry().registrations() { match registration { Registration::Component(probe) => { - out.insert(probe.type_name(), Declared { module: probe.module, purpose: probe.purpose, probe: Some(probe) }); + out.insert(probe.type_name(), Declared { module: probe.module, purpose: probe.purpose, probe: Some(*probe) }); } Registration::Pattern(probe) => { out.insert(probe.type_name(), Declared { module: probe.module, purpose: probe.purpose, probe: None });