-
-
Notifications
You must be signed in to change notification settings - Fork 16.3k
rustdoc: notable trait badge and popover enhancements #160370
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: main
Are you sure you want to change the base?
Changes from all commits
0477367
136b399
025f6d2
cba5899
17ce955
f0cf8b0
03fbe38
8e7178c
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 |
|---|---|---|
|
|
@@ -2,7 +2,7 @@ use rustc_ast::ast::{AttrStyle, LitKind, MetaItemLit}; | |
| use rustc_attr_ir::target::Target; | ||
| use rustc_attr_ir::{ | ||
| AttributeKind, CfgEntry, CfgHideShow, DocAttribute, DocCfgHideShow, DocCfgHideShowValue, | ||
| DocInline, HideOrShow, | ||
| DocInline, HideOrShow, NotableTraitColor, | ||
| }; | ||
| use rustc_data_structures::fx::{FxHashSet, FxIndexMap, IndexEntry}; | ||
| use rustc_errors::Applicability; | ||
|
|
@@ -15,13 +15,14 @@ use super::{AcceptMapping, AttributeParser, template}; | |
| use crate::context::{AcceptContext, FinalizeContext}; | ||
| use crate::diagnostics::{ | ||
| AttrCrateLevelOnly, DocAliasBadChar, DocAliasDuplicated, DocAliasEmpty, DocAliasMalformed, | ||
| DocAliasStartEnd, DocAttrNotCrateLevel, DocAttributeNotAttribute, DocAutoCfgExpectsHideOrShow, | ||
| DocAutoCfgHideShowExpectsList, DocAutoCfgHideShowNoIdentBeforeValues, | ||
| DocAutoCfgHideShowUnexpectedItem, DocAutoCfgHideShowUnexpectedItemAfterValues, | ||
| DocAutoCfgHideShowValuesMix, DocAutoCfgWrongLiteral, DocKeywordNotKeyword, DocTestLiteral, | ||
| DocTestTakesList, DocTestUnknown, DocUnknownAny, DocUnknownInclude, DocUnknownPasses, | ||
| DocUnknownPlugins, DocUnknownSpotlight, ExpectedNameValue, ExpectedNoArgs, | ||
| IllFormedAttributeInput, MalformedDoc, UnusedDuplicate, | ||
| DocAliasStartEnd, DocAttrNotCrateLevel, DocAttrNotTraitLevel, DocAttributeNotAttribute, | ||
| DocAutoCfgExpectsHideOrShow, DocAutoCfgHideShowExpectsList, | ||
| DocAutoCfgHideShowNoIdentBeforeValues, DocAutoCfgHideShowUnexpectedItem, | ||
| DocAutoCfgHideShowUnexpectedItemAfterValues, DocAutoCfgHideShowValuesMix, | ||
| DocAutoCfgWrongLiteral, DocKeywordNotKeyword, DocTestLiteral, DocTestTakesList, DocTestUnknown, | ||
| DocUnknownAny, DocUnknownInclude, DocUnknownPasses, DocUnknownPlugins, DocUnknownSpotlight, | ||
| ExpectedNameValue, ExpectedNoArgs, IllFormedAttributeInput, InvalidNotableTraitAttr, | ||
| MalformedDoc, UnusedDuplicate, | ||
| }; | ||
| use crate::parser::{ | ||
| ArgParser, MetaItemListParser, MetaItemOrLitParser, MetaItemParser, OwnedPathParser, | ||
|
|
@@ -92,6 +93,78 @@ fn expected_string_literal( | |
| cx.emit_lint(INVALID_DOC_ATTRIBUTES, MalformedDoc, span); | ||
| } | ||
|
|
||
| fn parse_notable_trait( | ||
| cx: &mut AcceptContext<'_, '_>, | ||
| path: &OwnedPathParser, | ||
| args: &ArgParser, | ||
| attr_value: &mut Option<(Option<(NotableTraitColor, Span)>, Span)>, | ||
| attr_name: Symbol, | ||
| ) { | ||
| let span = path.span(); | ||
|
|
||
| let notable_trait_color_attr = match args { | ||
| ArgParser::NoArgs => None, | ||
| ArgParser::List(meta_item_list_parser) => { | ||
| if meta_item_list_parser.is_empty() { | ||
| None | ||
| } else if let Some(meta_item) = meta_item_list_parser.as_single() { | ||
| Some(meta_item) | ||
| } else { | ||
| cx.emit_lint(INVALID_DOC_ATTRIBUTES, InvalidNotableTraitAttr, span); | ||
| return; | ||
| } | ||
| } | ||
| ArgParser::NameValue(_) => { | ||
| cx.emit_lint(INVALID_DOC_ATTRIBUTES, InvalidNotableTraitAttr, span); | ||
| return; | ||
| } | ||
| }; | ||
|
|
||
| let notable_trait_color_and_span = | ||
| if let Some(notable_trait_color_attr) = notable_trait_color_attr { | ||
| let Some(notable_trait_color_attr) = notable_trait_color_attr.meta_item() else { | ||
| cx.emit_lint(INVALID_DOC_ATTRIBUTES, InvalidNotableTraitAttr, span); | ||
| return; | ||
| }; | ||
| if !notable_trait_color_attr.path().word_is(sym::color) { | ||
| cx.emit_lint(INVALID_DOC_ATTRIBUTES, InvalidNotableTraitAttr, span); | ||
| return; | ||
| } | ||
| let Some(notable_trait_color) = notable_trait_color_attr.args().as_name_value() else { | ||
| cx.emit_lint(INVALID_DOC_ATTRIBUTES, InvalidNotableTraitAttr, span); | ||
| return; | ||
| }; | ||
| let Some(notable_trait_color) = notable_trait_color.value_as_str() else { | ||
| cx.emit_lint(INVALID_DOC_ATTRIBUTES, InvalidNotableTraitAttr, span); | ||
|
Member
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. Would be nice to give some extra info because they all emit the same lint with the same span. Or was it on purpose while waiting for team's approval?
Contributor
Author
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 figured that sort of thing could be handled in a follow-up, after we decide on the syntax we want at all.
Member
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. Then add a fixme comment and open an issue. |
||
| return; | ||
| }; | ||
| let notable_trait_color = match notable_trait_color.as_str() { | ||
| "grey" => NotableTraitColor::Grey, | ||
| "red" => NotableTraitColor::Red, | ||
| "green" => NotableTraitColor::Green, | ||
| "yellow" => NotableTraitColor::Yellow, | ||
| "blue" => NotableTraitColor::Blue, | ||
| "magenta" => NotableTraitColor::Magenta, | ||
| "cyan" => NotableTraitColor::Cyan, | ||
| "transparent" => NotableTraitColor::Transparent, | ||
| _ => { | ||
| cx.emit_lint(INVALID_DOC_ATTRIBUTES, InvalidNotableTraitAttr, span); | ||
| return; | ||
| } | ||
| }; | ||
| Some((notable_trait_color, notable_trait_color_attr.span())) | ||
| } else { | ||
| None | ||
| }; | ||
|
|
||
| if cx.shared.target != Target::Trait { | ||
| cx.emit_lint(INVALID_DOC_ATTRIBUTES, DocAttrNotTraitLevel { span, attr_name }, span); | ||
| return; | ||
| } | ||
|
|
||
| *attr_value = Some((notable_trait_color_and_span, span)); | ||
| } | ||
|
|
||
| fn parse_keyword_and_attribute( | ||
| cx: &mut AcceptContext<'_, '_>, | ||
| path: &OwnedPathParser, | ||
|
|
@@ -594,7 +667,13 @@ impl DocParser { | |
| } | ||
| Some(sym::notable_trait) => { | ||
| gated!(doc_notable_trait); | ||
| no_args!(notable_trait) | ||
| parse_notable_trait( | ||
| cx, | ||
| path, | ||
| args, | ||
| &mut self.attribute.notable_trait, | ||
| sym::notable_trait, | ||
| ) | ||
| } | ||
| Some(sym::keyword) => { | ||
| gated!(rustdoc_internals); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -665,6 +665,7 @@ symbols! { | |
| cold, | ||
| cold_path, | ||
| collapse_debuginfo, | ||
| color, | ||
| column, | ||
| common, | ||
| compare_bytes, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
do we want to support both spellings of gray/grey? if not, i believe "gray" is the more common in US english, which is what rustdoc uses (otherwise this would be colour)
View changes since the review
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 thought
graywas only a name until now. I'd been in favour of only usinggrey, as for foreigners, it's how we learn the color name (or colour :p).