Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[rustdoc] Private macros are not documented with --document-private-items #73754

Closed
TyPR124 opened this issue Jun 26, 2020 · 7 comments · Fixed by #88019
Closed

[rustdoc] Private macros are not documented with --document-private-items #73754

TyPR124 opened this issue Jun 26, 2020 · 7 comments · Fixed by #88019
Assignees
Labels
A-HIR Area: The high-level intermediate representation (HIR) A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-bug Category: This is a bug. E-hard Call for participation: Hard difficulty. Experience needed to fix: A lot. P-medium Medium priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@TyPR124
Copy link
Contributor

TyPR124 commented Jun 26, 2020

Rustdoc has --document-private-items and --document-hidden-items. It would be nice to have an option to document non-exported macros, which is currently not possible as far as I can tell.

@LeSeulArtichaut LeSeulArtichaut added C-feature-request Category: A feature request, i.e: not implemented / a PR. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Jun 26, 2020
@jonas-schievink
Copy link
Contributor

I would expect --document-private-items to also document macros, so this seems like a bug

@jonas-schievink jonas-schievink added the A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) label Jun 26, 2020
@TyPR124 TyPR124 changed the title [rustdoc] Document private macros flag [rustdoc] Cannot document private macros Jun 30, 2020
@jyn514 jyn514 added C-bug Category: This is a bug. and removed C-feature-request Category: A feature request, i.e: not implemented / a PR. labels Oct 11, 2020
@jyn514
Copy link
Member

jyn514 commented Oct 11, 2020

This is because rustdoc gets macros from Crate.exported_macros, which doesn't have the private macros in the first place. Intra-doc links don't have this problem because they look at Resolver::all_macros. Maybe the rest of rustdoc could use that too?

@camelid camelid changed the title [rustdoc] Cannot document private macros [rustdoc] Private macros are not documented with --document-private-items Oct 18, 2020
@camelid
Copy link
Member

camelid commented Oct 18, 2020

Marking as P-medium since this behavior is pretty confusing.

@camelid camelid added the P-medium Medium priority label Oct 18, 2020
@jyn514 jyn514 added the E-medium Call for participation: Medium difficulty. Experience needed to fix: Intermediate. label Nov 6, 2020
@camelid camelid self-assigned this Nov 25, 2020
@camelid
Copy link
Member

camelid commented Nov 25, 2020

Going to try working on this. Hopefully I won't regret it ;)

@jyn514 jyn514 added E-hard Call for participation: Hard difficulty. Experience needed to fix: A lot. and removed E-medium Call for participation: Medium difficulty. Experience needed to fix: Intermediate. labels Dec 15, 2020
@jyn514
Copy link
Member

jyn514 commented Apr 16, 2021

Copying from #79396 (comment):

The rustdoc-based solution is a workaround and technical debt.

For modularized macros (macro and pub macro_rules, if they get merged) their source parent module (the module into which they are placed in source code) and their name-resolution parent module (parent::my_macro) coincide , so preserving these macro items in HIR would be the most natural way to give these items to rustdoc (and perhaps save-analysis as well), in both regular and document-private-items rustdoc mode.
Rustdoc then wouldn't require any special treatment of these macros compared to other items.

macro_rules without #[macro_export] are only documented in document-private-items mode, and correct location for documenting them doesn't really exist, so documenting them in the module in which they are written in source code would be good enough.
That means preserving these macros in HIR and treating exactly like the macro items mentioned above would be the simplest solution.

#[macro_export] macro_rules are the most annoying case.
They may be defined in some module in source code, but they still need to be documented documented in the crate root by rustdoc (and also encoded as placed into the crate root in metadata).
I'm not sure what is the cleanest way to address them, perhaps moving them all into the root module during lowering to HIR would work?

@jyn514 jyn514 added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-HIR Area: The high-level intermediate representation (HIR) labels Apr 16, 2021
@jyn514
Copy link
Member

jyn514 commented Apr 16, 2021

Fixing this properly would also allow removing the hack in #77862.

@inquisitivecrystal inquisitivecrystal self-assigned this Aug 6, 2021
@inquisitivecrystal
Copy link
Contributor

This should get fixed as part of #87406.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-HIR Area: The high-level intermediate representation (HIR) A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-bug Category: This is a bug. E-hard Call for participation: Hard difficulty. Experience needed to fix: A lot. P-medium Medium priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
6 participants