Repository navigation
Document the items the macros generate - #286
Merged
Merged
Conversation
A crate that enabled `missing_docs` failed the build on every item a CGP macro declares, because a doc comment on the invocation never reaches the generated code. Each macro now emits a short doc for the items it declares: the component marker, the provider struct, the namespace struct, trait, and associated type, the wiring-table structs, and the data derives' companion types. A `#[cgp_fn]` function's own doc now stays on the method, where the function's body lands, instead of moving to the trait, and the trait carries a generated line naming the operation. The `generated_docs` module in the test library denies `missing_docs` while using every macro, so a generated item that loses its line fails the build, and three snapshots pin where a user's doc comment lands.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
[deepseek-v4.1-flash] Every macro that declares a public item now emits a short doc for it, so a crate can enable
#![warn(missing_docs)]without the lint reporting generated code. A user's own doc comment is preserved, and a#[cgp_fn]function's doc now stays on the method instead of moving to the trait.Motivation
missing_docsruns after macro expansion, so it reports the items a macro generates, and a doc comment written on the invocation never reaches them: rustdoc does not document macro invocations, so the macro must emit the documentation itself. Before this change, a crate that used a component and enabled the lint failed the build on the component marker, the provider struct, the namespace items, and the data derives' companion types.Impact
The generated lines name the item and link the trait it belongs to, such as
Component marker for [CanGreet].andProviderGreetHellofor [Greeter].. A generated line is never appended after a user's doc: it fills a gap, so no item carries both.A doc on a
#[cgp_component]consumer trait is copied onto the five items the macro derives from it, which is harmless on docs.rs because impl docs are not rendered. A doc on acgp_namespace!ordelegate_components!invocation is dropped with anunused_doc_commentswarning, so the generated line is all those items can carry.The
generated_docsmodule in the test library deniesmissing_docswhile using every macro, so a generated item that loses its line fails the build. It lives in the library crate becausemissing_docsonly fires on items exported from a library, and a test binary exports nothing. Three snapshots pin where a user's doc comment lands, in the concept targets that own their macros.