Repository navigation
improve doc attr span tracking for proc-macro #17678
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
Merged
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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,7 +1,9 @@ | ||
| use clippy_config::Conf; | ||
| use clippy_utils::attrs::is_doc_hidden; | ||
| use clippy_utils::diagnostics::{span_lint, span_lint_and_help, span_lint_and_then}; | ||
| use clippy_utils::{is_entrypoint_fn, is_trait_impl_item}; | ||
| use clippy_utils::macros::root_macro_call; | ||
| use clippy_utils::{is_entrypoint_fn, is_trait_impl_item, sym}; | ||
| use rustc_ast::token::DocFragmentKind; | ||
| use rustc_attr_ir::Attribute; | ||
| use rustc_data_structures::fx::FxHashSet; | ||
| use rustc_errors::Applicability; | ||
|
|
@@ -263,7 +265,7 @@ declare_clippy_lint! { | |
| /// /// Consume the array and return the inner | ||
| /// /// [`SmallVec<[T; INLINE_CAPACITY]>`][SmallVec]. | ||
| /// /// [SmallVec]: SmallVec | ||
| /// fn main() {} | ||
| /// fn foo() {} | ||
| /// ``` | ||
| #[clippy::version = "pre 1.29.0"] | ||
| pub DOC_MARKDOWN, | ||
|
|
@@ -878,11 +880,15 @@ fn check_attrs(cx: &LateContext<'_>, valid_idents: &FxHashSet<String>, attrs: &[ | |
|
|
||
| let (fragments, _) = attrs_to_doc_fragments( | ||
| attrs.iter().filter_map(|attr| { | ||
| if attr.doc_str_and_fragment_kind().is_none() || attr.span().in_external_macro(cx.sess().source_map()) { | ||
| None | ||
| } else { | ||
| Some((attr, None)) | ||
| } | ||
| let (_, kind) = attr.doc_str_and_fragment_kind()?; | ||
| let (is_raw, doc_str_span) = match kind { | ||
| DocFragmentKind::Sugared(_) => (false, attr.span()), | ||
| DocFragmentKind::Raw(span) => (true, span), | ||
| }; | ||
| let from_include_str_macro = is_raw | ||
| && !attr.span().in_external_macro(cx.sess().source_map()) | ||
| && originated_from_include_str_macro(cx, doc_str_span); | ||
| (from_include_str_macro || !doc_str_span.in_external_macro(cx.sess().source_map())).then_some((attr, None)) | ||
|
Comment on lines
+883
to
+891
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. Much better! ❤️ |
||
| }), | ||
| true, | ||
| ); | ||
|
|
@@ -963,6 +969,10 @@ fn check_attrs(cx: &LateContext<'_>, valid_idents: &FxHashSet<String>, attrs: &[ | |
| )) | ||
| } | ||
|
|
||
| fn originated_from_include_str_macro(cx: &LateContext<'_>, span: Span) -> bool { | ||
| root_macro_call(span).is_some_and(|macro_call| cx.tcx.is_diagnostic_item(sym::include_str_macro, macro_call.def_id)) | ||
| } | ||
|
|
||
| enum Container { | ||
| Blockquote, | ||
| List(usize), | ||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
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.
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.
(follow on from #16713 (comment))
Only some of these item kinds produced the 'missing backticks'
clippy::doc_markdownlint due to a very specific requirement in order to resolve aSpanfrom a markdown string:DocFragmentKind::Rawforeign_mod), it's span is resolvedsource_span_for_markdown_range_inner(viaFragments), which cannot disambiguate between multiple instances of a match within a markdown block.All that being said, I feel that properly backticking these item kinds is appropriate.
View changes since the review