-
Notifications
You must be signed in to change notification settings - Fork 13.8k
[rustdoc] Add support new bang macro kinds #145458
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
base: master
Are you sure you want to change the base?
[rustdoc] Add support new bang macro kinds #145458
Conversation
r? @notriddle rustbot has assigned @notriddle. Use |
Some changes occurred in HTML/CSS/JS. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't really say much about the actual logic correctness (it seems mostly fine?), but i do have a few nitpicks about naming, datatype structure and logic clarity.
It was also a bit weird reviewing this with the two alternate implementations, since as far as I can tell there's a few lines of code that are common between both impls, but actually have different semantics between them.
|
||
struct SidebarItem { | ||
name: String, | ||
is_actually_macro: bool, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unclear what "actually" means here, is it possible for a sidebar item to be a macro, but not actually be a macro?
I think this should probably be renamed to is_decl_macro
or is_macro_rules
, or maybe is_macro_placeholder
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This definitely needs a comment, or a better name, that explains more specifically what it is. Without it, I have no way to tell short of examining where it's used to figure out what it is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did both. :)
src/librustdoc/clean/mod.rs
Outdated
source: display_macro_source(cx, name, macro_def), | ||
macro_rules: macro_def.macro_rules, | ||
}, | ||
None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why None
and not just MacroKinds::BANG
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough, it'll simply move some checks later on.
src/librustdoc/clean/types.rs
Outdated
/// `type`s from an extern block | ||
ForeignTypeItem, | ||
MacroItem(Macro), | ||
MacroItem(Macro, Option<MacroKinds>), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like the use of Option
here, for two reasons:
MacroKinds::empty()
already can represent the absence of any value- what
None
actually represents here isMacroKinds::BANG
I think the rationale for the second is that this represents extra macro kinds, but I think the use of Option
is still unnecessary, as it leaves MacroKinds::empty()
as a meaningless value that should never be used, which seems like something we would want to avoid.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
// Is this a good idea? | ||
clean::AttrMacroItem => ItemType::ProcAttribute, | ||
// Is this a good idea? | ||
clean::DeriveMacroItem => ItemType::ProcDerive, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems fairly confusing to me, I don't see the advantage (is it so item_module
groups things correctly? if that's the case, then the first commit on its own would not be correct, since it would categorize these macros as ItemType::Macro
), and it already causes a bit of weirdness in html_filename
which would not be needed if these were categorized as Macro
instead.
if we did want to make this change, I would at least want to change the names of the item types to not imply they must be derives.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea is for these macros to show up if we filter on attribute macros or on derive macros as that's what they actually are (among potentially other things).
@rustbot author |
e173857
to
08c5d0c
Compare
This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
08c5d0c
to
ac60bd4
Compare
This comment has been minimized.
This comment has been minimized.
ac60bd4
to
8729f78
Compare
@rustbot ready |
☔ The latest upstream changes (presumably #138907) made this pull request unmergeable. Please resolve the merge conflicts. |
This implements #145153 in rustdoc. This PR voluntarily doesn't touch anything related to intra-doc links, I'll send a follow-up if needed.
So now about the implementation itself: this is a weird case where a macro can be different things at once but still only gets one file generated. I saw two ways to implement this:
ItemKind::Macro
differently and iter through itsMacroKinds
values.ItemKind
enum, which means that when we encounter them in rendering, we need to ignore them. It also makes theItemKind
enum bigger (and also needs more code to be handled). Another downside is that it needs to be handled in the JSON output.I implemented 1. in the first commit and 2. in the third commit so if we don't to keep 2., I can simply remove it. I personally have no preference for one or the other since the first is "simpler" but it's easy to forget to go through the macro kinds whereas the second needs a lot more code.Now there was an interesting improvement that came with this PR in the
html::render::print_item::item_module
function: I simplified its implementation and split the different parts in aHashMap
where the key is the item type. So then, we can just iterate through the keys and open/close the section at each iteration instead of keeping anOption<section>
around.cc @joshtriplett