Skip to content

Conversation

@ophilli
Copy link
Contributor

@ophilli ophilli commented Oct 2, 2025

Problem: state_machine!() users could not document their state and superstate handler functions with doc comments that would appear on the generated enum variants. This made the generated code harder to understand, reduced IDE support, and meant users could not use lints like missing_docs.

Solution: Propagate doc comments through the macro pipeline by extracting them from the state/superstate handler functions during analysis, and then attaching the extracted doc comments as attributes to the generated enum variants. Additionally we added default doc comments to the generated State and Superstate enums.

Testing: Added trybuild tests that use #![deny(missing_docs)] to validate that the doc comments are propagated.

Copy link
Owner

@mdeloof mdeloof left a comment

Choose a reason for hiding this comment

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

Looks good to me! Thank you for your work :)

@ophilli
Copy link
Contributor Author

ophilli commented Oct 20, 2025

These build failures are really interesting. Both the stable & nightly builds are failing with mismatches in the trybuild tests/ui/custom_state_derive_error.rs [should fail to compile] and the tests/ui/doc_comments_missing_lint.rs [should fail to compile] tests. The expected and actual output looks the same to me at first glance.

It's interesting that the custom_state_derive_error.rs test is failing now too - this PR didn't even touch those tests & they all passed when I ran locally.

@mdeloof would you mind triggering another GitHub Actions run against https://github.com/mdeloof/statig/tree/refs/heads/main ? I see on this repo's actions page that the last action run against main is from 2025-07-05T14:56Z. I wonder if a Rust upgrade caused these tests to rot.

@mdeloof
Copy link
Owner

mdeloof commented Oct 23, 2025

Yeah, I ran the workflow on main again and it is failing too now. If I diff the 'EXPECTED' vs 'ACTUAL OUTPUT' it seems the single digit line numbers have different levels of indentation, for example:

- 1  | #![deny(missing_docs)]    // EXPECTED
+  1 | #![deny(missing_docs)]    // ACTUAL OUTPUT

@ophilli
Copy link
Contributor Author

ophilli commented Oct 25, 2025

I've published #75 which should fix the existing ui tests & then updated the commit in this PR so that the new ui tests' line number matches the right aligned format.

Problem: `state_machine!()` users could not document their state and
superstate handler functions with doc comments that would appear on
the generated enum variants. This made the generated code harder to
understand, reduced IDE support, and meant users could not use lints
like `missing_docs`.

Solution: Propagate doc comments through the macro pipeline by
extracting them from the state/superstate handler functions during
analysis, and then attaching the extracted doc comments as attributes
to the generated enum variants. Additionally we added default doc
comments to the generated State and Superstate enums.

Testing: Added trybuild tests that use `#![deny(missing_docs)]` to
validate that the doc comments are propagated.
@ophilli
Copy link
Contributor Author

ophilli commented Oct 25, 2025

Okay - looks like I mis-staged the actual test fixes for this commit last night. 😅 Things are looking good now though!

Thanks for turning on the runners automatically @mdeloof!

@mdeloof mdeloof merged commit 65f9abe into mdeloof:main Oct 27, 2025
2 checks passed
@mdeloof
Copy link
Owner

mdeloof commented Oct 27, 2025

Thanks again @ophilli and @christianheussy!

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.

3 participants