Skip to content

Preserve doc comment when type alias is hidden#3122

Open
jschwe wants to merge 3 commits intorust-lang:mainfrom
jschwe:jschwender/3119-typedef-doc
Open

Preserve doc comment when type alias is hidden#3122
jschwe wants to merge 3 commits intorust-lang:mainfrom
jschwe:jschwender/3119-typedef-doc

Conversation

@jschwe
Copy link
Contributor

@jschwe jschwe commented Feb 8, 2025

If a type is not documented, but a type alias with the same canonical path is, then preserve the
documentation of the type alias onto the type, since otherwise it would be lost.

Fixes #3119

}
let type_alias_comment = ctx
.items()
.filter(|(_id, alias)| {
Copy link
Contributor

Choose a reason for hiding this comment

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

Iterating over all items seems not really fine, performance wise. Can we avoid it somehow?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm - I think since we are using this fallback for the case where typedef and struct declaration are at the same time, a potential type alias should always be at item_id + 1. I don't think we currently have a way to access the "next" item or do arithmetic on item ids, but this would avoid iterating through all items.

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we can do it the other way around? During the clang phase, go peek at the typedef's comment? Haven't tried it tho.

Copy link
Contributor Author

@jschwe jschwe Feb 25, 2026

Choose a reason for hiding this comment

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

I got back to this and the new approach should resolve this concern.

If a type is not documented, but a type alias with
the same canonical path is, then generate the
documentation of the typealias onto the type,
since otherwise it would be lost.
@jschwe jschwe force-pushed the jschwender/3119-typedef-doc branch from f9984d7 to 6843b03 Compare February 25, 2026 03:40
@jschwe jschwe changed the title Generate doc comment when type alias is hidden Preserve doc comment when type alias is hidden Feb 25, 2026
@jschwe jschwe force-pushed the jschwender/3119-typedef-doc branch from 6843b03 to 20ceeeb Compare February 25, 2026 03:42
@jschwe jschwe requested a review from emilio February 25, 2026 03:58
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.

Comments are not generated for typedef struct forward declaration.

2 participants