Skip to content

fix(macros): resolve quick start source info from item spans#18

Merged
eboody merged 2 commits intomainfrom
fix/quick-start-source-resolution
Mar 27, 2026
Merged

fix(macros): resolve quick start source info from item spans#18
eboody merged 2 commits intomainfrom
fix/quick-start-source-resolution

Conversation

@eboody
Copy link
Copy Markdown
Owner

@eboody eboody commented Mar 27, 2026

Fixes #17.

Summary

  • prefer annotated item spans over anonymous proc-macro call sites when resolving source and module information for #[state], #[machine], #[transition], and #[validators]
  • reject non-disk span files before attempting source scans and keep the call-site path only as a fallback
  • add a Quick Start regression fixture and switch docs/inspector-plan.md to repo-relative links so the docs link check passes under act

Testing

  • cargo test --workspace
  • act -j stable
  • act -j msrv-1-93
  • act -j security-deny
  • act -j security-audit
  • act -j nightly-canary

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes Quick Start failures (Issue #17) by improving how the statum-macros proc-macros resolve source file + module path information, preferring annotated item spans over proc-macro call-site spans and avoiding non-disk paths during source scans.

Changes:

  • Add span-based source/module resolution helpers in macro_registry and switch #[state], #[machine], #[transition], and #[validators] to use them.
  • Improve validator machine resolution diagnostics by using span-derived source info (with call-site fallback) for source scanning.
  • Add a Quick Start regression UI fixture and update docs to use repo-relative links so link checking works under act.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
statum-macros/tests/ui/valid_quick_start.rs Adds a Quick Start regression fixture exercising #[state], #[machine], and #[transition].
statum-macros/tests/macro_errors.rs Registers the new Quick Start UI test as a passing trybuild case.
statum-macros/src/validators/resolution.rs Uses span-derived source info to improve candidate scanning/diagnostics during validator machine resolution.
statum-macros/src/validators.rs Adjusts parse_validators to accept a parsed ItemImpl (caller parses once).
statum-macros/src/state.rs Switches #[state] enum metadata/module resolution to span-based helpers.
statum-macros/src/machine/metadata.rs Switches #[machine] struct metadata/module resolution to span-based helpers.
statum-macros/src/lib.rs Uses impl-item spans for resolving module path in #[transition] / #[validators], and parses ItemImpl once for validators.
macro_registry/src/callsite.rs Introduces span-based (file,line) and module-path helpers, rejecting non-disk paths before scanning.
macro_registry/Cargo.toml Adds proc-macro2 with span-locations to support span-based resolution.
docs/inspector-plan.md Replaces absolute local-file links with repo-relative links for CI doc link checks.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

let line_number = Span::call_site().start().line;
let module_path = match resolved_current_module_path(Span::call_site(), "#[validators]") {
let item_impl = parse_macro_input!(item as ItemImpl);
let line_number = item_impl.impl_token.span.start().line;
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line_number for #[validators] is now taken from item_impl.impl_token.span.start().line, which can be 0 when span location info is unavailable. That value is later used to derive stable hashed identifiers (and potentially in diagnostics), so a 0 can increase the chance of identifier collisions and reduce error-message quality. Consider deriving the line number via macro_registry::callsite::source_info_for_span_or_callsite(item_impl.impl_token.span) (or falling back to Span::call_site().start().line when 0).

Suggested change
let line_number = item_impl.impl_token.span.start().line;
let mut line_number = item_impl.impl_token.span.start().line;
if line_number == 0 {
line_number = Span::call_site().start().line;
}

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 3b71577. #[validators] now derives line_number from source_info_for_span_or_callsite(span) and only falls back to the raw span line when needed.

@eboody eboody merged commit 25d4e77 into main Mar 27, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Internal error: could not read source information

2 participants