-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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: Discriminate required and provided associated constants and types #95316
Merged
bors
merged 1 commit into
rust-lang:master
from
fmease:rustdoc-discr-req-prov-assoc-consts-tys
Apr 13, 2022
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -577,10 +577,16 @@ impl Item { | |
self.type_() == ItemType::Variant | ||
} | ||
crate fn is_associated_type(&self) -> bool { | ||
self.type_() == ItemType::AssocType | ||
matches!(&*self.kind, AssocTypeItem(..) | StrippedItem(box AssocTypeItem(..))) | ||
} | ||
crate fn is_ty_associated_type(&self) -> bool { | ||
matches!(&*self.kind, TyAssocTypeItem(..) | StrippedItem(box TyAssocTypeItem(..))) | ||
} | ||
crate fn is_associated_const(&self) -> bool { | ||
self.type_() == ItemType::AssocConst | ||
matches!(&*self.kind, AssocConstItem(..) | StrippedItem(box AssocConstItem(..))) | ||
} | ||
crate fn is_ty_associated_const(&self) -> bool { | ||
matches!(&*self.kind, TyAssocConstItem(..) | StrippedItem(box TyAssocConstItem(..))) | ||
} | ||
crate fn is_method(&self) -> bool { | ||
self.type_() == ItemType::Method | ||
|
@@ -726,17 +732,18 @@ crate enum ItemKind { | |
EnumItem(Enum), | ||
FunctionItem(Function), | ||
ModuleItem(Module), | ||
TypedefItem(Typedef, bool /* is associated type */), | ||
TypedefItem(Typedef), | ||
OpaqueTyItem(OpaqueTy), | ||
StaticItem(Static), | ||
ConstantItem(Constant), | ||
TraitItem(Trait), | ||
TraitAliasItem(TraitAlias), | ||
ImplItem(Impl), | ||
/// A method signature only. Used for required methods in traits (ie, | ||
/// non-default-methods). | ||
/// A required method in a trait declaration meaning it's only a function signature. | ||
TyMethodItem(Function), | ||
/// A method with a body. | ||
/// A method in a trait impl or a provided method in a trait declaration. | ||
/// | ||
/// Compared to [TyMethodItem], it also contains a method body. | ||
MethodItem(Function, Option<hir::Defaultness>), | ||
StructFieldItem(Type), | ||
VariantItem(Variant), | ||
|
@@ -749,12 +756,16 @@ crate enum ItemKind { | |
MacroItem(Macro), | ||
ProcMacroItem(ProcMacro), | ||
PrimitiveItem(PrimitiveType), | ||
AssocConstItem(Type, Option<ConstantKind>), | ||
/// An associated item in a trait or trait impl. | ||
/// A required associated constant in a trait declaration. | ||
TyAssocConstItem(Type), | ||
/// An associated associated constant in a trait impl or a provided one in a trait declaration. | ||
AssocConstItem(Type, ConstantKind), | ||
/// A required associated type in a trait declaration. | ||
/// | ||
/// The bounds may be non-empty if there is a `where` clause. | ||
/// The `Option<Type>` is the default concrete type (e.g. `trait Trait { type Target = usize; }`) | ||
AssocTypeItem(Box<Generics>, Vec<GenericBound>, Option<Type>), | ||
TyAssocTypeItem(Box<Generics>, Vec<GenericBound>), | ||
/// An associated type in a trait impl or a provided one in a trait declaration. | ||
AssocTypeItem(Typedef, Vec<GenericBound>), | ||
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 really like this "specialization". It makes it much more clear what it's actually for. |
||
/// An item that has been stripped by a rustdoc pass | ||
StrippedItem(Box<ItemKind>), | ||
KeywordItem(Symbol), | ||
|
@@ -776,7 +787,7 @@ impl ItemKind { | |
ExternCrateItem { .. } | ||
| ImportItem(_) | ||
| FunctionItem(_) | ||
| TypedefItem(_, _) | ||
| TypedefItem(_) | ||
| OpaqueTyItem(_) | ||
| StaticItem(_) | ||
| ConstantItem(_) | ||
|
@@ -791,7 +802,9 @@ impl ItemKind { | |
| MacroItem(_) | ||
| ProcMacroItem(_) | ||
| PrimitiveItem(_) | ||
| TyAssocConstItem(_) | ||
| AssocConstItem(_, _) | ||
| TyAssocTypeItem(..) | ||
| AssocTypeItem(..) | ||
| StrippedItem(_) | ||
| KeywordItem(_) => [].iter(), | ||
|
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.
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.
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 am piercing through
StrippedItem
since that's exactly what theFrom<clean::Item> for ItemType
impl (initem_type.rs
) does which is used inself.type_()
which in turn is used by all thoseis_*
helpers like this one.