-
Notifications
You must be signed in to change notification settings - Fork 13.7k
[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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ use itertools::Either; | |
use rustc_abi::{ExternAbi, VariantIdx}; | ||
use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet}; | ||
use rustc_hir::attrs::{AttributeKind, DeprecatedSince, Deprecation}; | ||
use rustc_hir::def::{CtorKind, DefKind, Res}; | ||
use rustc_hir::def::{CtorKind, DefKind, MacroKinds, Res}; | ||
use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE, LocalDefId}; | ||
use rustc_hir::lang_items::LangItem; | ||
use rustc_hir::{BodyId, ConstStability, Mutability, Stability, StableSince, find_attr}; | ||
|
@@ -642,6 +642,18 @@ impl Item { | |
ItemType::from(self) | ||
} | ||
|
||
/// Generates the HTML file name based on the item kind. | ||
pub(crate) fn html_filename(&self) -> String { | ||
let type_ = if self.is_macro_placeholder() { ItemType::Macro } else { self.type_() }; | ||
format!("{type_}.{}.html", self.name.unwrap()) | ||
} | ||
|
||
/// If the current item is a "fake" macro (ie, `AttrMacroItem | ItemKind::DeriveMacroItem` which | ||
/// don't hold any data), it returns `true`. | ||
pub(crate) fn is_macro_placeholder(&self) -> bool { | ||
matches!(self.kind, ItemKind::AttrMacroItem | ItemKind::DeriveMacroItem) | ||
} | ||
|
||
pub(crate) fn is_default(&self) -> bool { | ||
match self.kind { | ||
ItemKind::MethodItem(_, Some(defaultness)) => { | ||
|
@@ -924,7 +936,9 @@ pub(crate) enum ItemKind { | |
ForeignStaticItem(Static, hir::Safety), | ||
/// `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 commentThe reason will be displayed to describe this comment to others. Learn more. I don't like the use of
I think the rationale for the second is that this represents extra macro kinds, but I think the use of |
||
AttrMacroItem, | ||
DeriveMacroItem, | ||
Comment on lines
+940
to
+941
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel like these should at the very least have a doc comment saying these are for non-proc macros. |
||
ProcMacroItem(ProcMacro), | ||
PrimitiveItem(PrimitiveType), | ||
/// A required associated constant in a trait declaration. | ||
|
@@ -974,7 +988,9 @@ impl ItemKind { | |
| ForeignFunctionItem(_, _) | ||
| ForeignStaticItem(_, _) | ||
| ForeignTypeItem | ||
| MacroItem(_) | ||
| MacroItem(..) | ||
| AttrMacroItem | ||
| DeriveMacroItem | ||
| ProcMacroItem(_) | ||
| PrimitiveItem(_) | ||
| RequiredAssocConstItem(..) | ||
|
@@ -1005,7 +1021,7 @@ impl ItemKind { | |
| ForeignFunctionItem(_, _) | ||
| ForeignStaticItem(_, _) | ||
| ForeignTypeItem | ||
| MacroItem(_) | ||
| MacroItem(..) | ||
| ProcMacroItem(_) | ||
| PrimitiveItem(_) | ||
) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -95,6 +95,10 @@ impl<'a> From<&'a clean::Item> for ItemType { | |
clean::ForeignFunctionItem(..) => ItemType::Function, // no ForeignFunction | ||
clean::ForeignStaticItem(..) => ItemType::Static, // no ForeignStatic | ||
clean::MacroItem(..) => ItemType::Macro, | ||
// Is this a good idea? | ||
clean::AttrMacroItem => ItemType::ProcAttribute, | ||
// Is this a good idea? | ||
clean::DeriveMacroItem => ItemType::ProcDerive, | ||
Comment on lines
+98
to
+101
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 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. |
||
clean::PrimitiveItem(..) => ItemType::Primitive, | ||
clean::RequiredAssocConstItem(..) | ||
| clean::ProvidedAssocConstItem(..) | ||
|
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 justMacroKinds::BANG
?