From a5a337466cd1b319ef0711a923ca0f3dc03bfb72 Mon Sep 17 00:00:00 2001 From: aiongg Date: Thu, 19 Nov 2026 07:02:51 +0000 Subject: [PATCH] design-lint: no-global-state rejects __split_for_bind instead of __from_field_path (#2336) --- crates/design-lint/README.md | 2 +- crates/design-lint/src/contract/global_state.rs | 12 ++++++------ crates/design-lint/tests/contract_rules.rs | 2 +- .../contract-rules/reject/contract-global-state.rs | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/crates/design-lint/README.md b/crates/design-lint/README.md index c3a66b336..817b02e7a 100644 --- a/crates/design-lint/README.md +++ b/crates/design-lint/README.md @@ -75,7 +75,7 @@ reason = "document-space drawing" | `contract/entry` | in layers 5 and 6 (not layer 8): an inherent `pub fn show`, `show_at`, `show_in` or `ui` on a `pub` type that the file does not make a `Component` or `Pattern`; a `pub fn` taking `&mut Ui` and returning a `*Response` | | `contract/shadow`, `contract/widget`, `contract/overlay-flag` | an inherent `show`, `show_at`, `show_in`, `show_with_tip` or `show_at_with_tip` on a component; `impl egui::Widget`; an `overlay` override on a type without `#[component(overlay)]`. Derive output is the only allowed place, so no file is | | `contract/registration` | an `impl Component for` or `impl Pattern for` a type defined in the file that neither derives that trait nor appears in a `register_contract!(..)` invocation of the file. | -| `contract/no-global-state` | every `static` (including `static mut` and statics inside functions), `thread_local!` and `lazy_static!`; `std::fs` by path or `use`; `impl MemoProps for` and `impl PlainData for` (only the derives implement them; no allowed location); any source occurrence of `__from_field_path` (only the `field!` expansion calls it; no allowed location). Skipped: `#[cfg(test)]` modules, `build.rs`, `src/bin/`. Allowed in: stories and `ui-contract`'s `testing`, and the reviewed per-item list `NO_GLOBAL_STATE` in `workspace.rs` (a file and the item's identifier or `std::fs`), each entry with the fact or later task that covers it. Clocks, called or passed as a fn value, are `contract/motion:clock`; `unsafe_code` is the workspace `forbid` plus `contract/unsafe-allow` | +| `contract/no-global-state` | every `static` (including `static mut` and statics inside functions), `thread_local!` and `lazy_static!`; `std::fs` by path or `use`; `impl MemoProps for` and `impl PlainData for` (only the derives implement them; no allowed location); any source occurrence of `__split_for_bind` (only the `bind_tracked!` expansion calls it; no allowed location). Skipped: `#[cfg(test)]` modules, `build.rs`, `src/bin/`. Allowed in: stories and `ui-contract`'s `testing`, and the reviewed per-item list `NO_GLOBAL_STATE` in `workspace.rs` (a file and the item's identifier or `std::fs`), each entry with the fact or later task that covers it. Clocks, called or passed as a fn value, are `contract/motion:clock`; `unsafe_code` is the workspace `forbid` plus `contract/unsafe-allow` | Egui paths are resolved through the file's `use` items (one table per file, grouped, renamed and glob imports), so a craft type that shares a name with an egui type is not flagged unless it is imported from egui. diff --git a/crates/design-lint/src/contract/global_state.rs b/crates/design-lint/src/contract/global_state.rs index f1791c0da..1da609cd7 100644 --- a/crates/design-lint/src/contract/global_state.rs +++ b/crates/design-lint/src/contract/global_state.rs @@ -24,8 +24,8 @@ 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 constructor behind `field!`; the lint reads source before macro expansion, so every textual hit is a direct call. -const FROM_FIELD_PATH: &str = "__from_field_path"; +/// 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. +const SPLIT_FOR_BIND: &str = "__split_for_bind"; struct Hits { found: Vec<(proc_macro2::Span, String, String)>, @@ -52,7 +52,7 @@ fn static_names(tokens: proc_macro2::TokenStream, out: &mut Vec) { fn field_path_in(tokens: proc_macro2::TokenStream, out: &mut Vec) { for token in tokens { match token { - proc_macro2::TokenTree::Ident(i) if i == FROM_FIELD_PATH => out.push(i.span()), + proc_macro2::TokenTree::Ident(i) if i == SPLIT_FOR_BIND => out.push(i.span()), proc_macro2::TokenTree::Group(g) => field_path_in(g.stream(), out), _ => {} } @@ -131,8 +131,8 @@ impl Visit<'_> for Hits { } fn visit_ident(&mut self, node: &proc_macro2::Ident) { - if node == FROM_FIELD_PATH { - self.projection.push((node.span(), format!("`{FROM_FIELD_PATH}` is called by `field!` only"))); + if node == SPLIT_FOR_BIND { + self.projection.push((node.span(), format!("`{SPLIT_FOR_BIND}` is called by `bind_tracked!` only"))); } } @@ -140,7 +140,7 @@ impl Visit<'_> for Hits { let mut spans = Vec::new(); field_path_in(node.tokens.clone(), &mut spans); for span in spans { - self.projection.push((span, format!("`{FROM_FIELD_PATH}` is called by `field!` only"))); + self.projection.push((span, format!("`{SPLIT_FOR_BIND}` is called by `bind_tracked!` only"))); } visit::visit_macro(self, node); } diff --git a/crates/design-lint/tests/contract_rules.rs b/crates/design-lint/tests/contract_rules.rs index bd10dae4d..5d4354354 100644 --- a/crates/design-lint/tests/contract_rules.rs +++ b/crates/design-lint/tests/contract_rules.rs @@ -101,7 +101,7 @@ fn global_state_counts_every_form_and_honours_the_allowlist() { let src = fixture("reject", "contract-global-state.rs"); let found = analyze_contract(&src, Path::new(FAMILY), &scope(), false); // static, static mut, static OnceLock, thread_local!, impl MemoProps, a static in a fn, `use std::fs`, `std::fs::read`, - // and the two derive-only forms: impl PlainData and a direct `__from_field_path`. + // and the two derive-only forms: impl PlainData and a direct `__split_for_bind`. assert_eq!(found.iter().filter(|f| f.rule == "contract/no-global-state").count(), 10, "{found:?}"); // An entry names one item; the rest of the file is still flagged. The three derive-only forms have no entry. let mut allowed = StaticScope::new(); diff --git a/crates/design-lint/tests/fixtures/contract-rules/reject/contract-global-state.rs b/crates/design-lint/tests/fixtures/contract-rules/reject/contract-global-state.rs index fafa76037..01b98cdac 100644 --- a/crates/design-lint/tests/fixtures/contract-rules/reject/contract-global-state.rs +++ b/crates/design-lint/tests/fixtures/contract-rules/reject/contract-global-state.rs @@ -16,8 +16,8 @@ impl MemoProps for Props {} impl PlainData for Props {} -fn project() -> Path { - Path::__from_field_path(&[]) +fn project() -> Tracked { + Tracked::__split_for_bind(&[]) } fn read(path: &str) -> Vec {