use more robust doc attr span checking for proc-macro#16713
use more robust doc attr span checking for proc-macro#16713zihan0822 wants to merge 2 commits intorust-lang:masterfrom
Conversation
|
Some changes occurred in clippy_lints/src/doc cc @notriddle |
|
rustbot has assigned @samueltardieu. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
Lintcheck changes for f0c1cb6
This comment will be updated if you push new changes |
84e7d0a to
3d1dce6
Compare
|
dogfood output in ci makes sense to me. @rustbot ready |
What do you mean? If you mean that some other Clippy sources need to be fixed, by all means do that in a separate commit that you would then move before the current one, so that at any point the CI would be green. Moreover that will show us some real-life consequences of those changes. @rustbot author |
|
Reminder, once the PR becomes ready for a review, use |
3d1dce6 to
d5ffe16
Compare
|
fixed clippy source in a separate commit. @rustbot ready |
c8c6833 to
b7034e0
Compare
| /// /// [`SmallVec<[T; INLINE_CAPACITY]>`][SmallVec]. | ||
| /// /// [SmallVec]: SmallVec | ||
| /// fn main() {} | ||
| /// fn foo() {} |
There was a problem hiding this comment.
fn main() triggers clippy::needless_doctest_main
| /// let a = 0123; | ||
| /// println!("{}", a); | ||
| /// } | ||
| /// let a = 0123; |
There was a problem hiding this comment.
Why did you remove fn main()? Is that some cleanup or the result of applying the lint?
There was a problem hiding this comment.
fn main() in rust listing triggers clippy::needless_doctest_main, main() in C was removed to pair with that.
| /// | Group | Item Kinds | | ||
| /// |--------------------|----------------------| | ||
| /// | `modules` | "mod", "foreign_mod" | | ||
| /// | `modules` | "mod", "foreign mod" | |
There was a problem hiding this comment.
Why did you remove the underscores? I'm not saying this is wrong, I'd like to understand this.
There was a problem hiding this comment.
Snake-cased word is treated as item in markdown and it triggers clippy::doc_markdown with warning "item in documentation is missing backticks".
I actually don't know what we should do about this. I think it might be better to keep those words as snake-cased, since they seem to be used as keywords in clippy::arbitrary_source_item_ordering's config. There is no way to suppress this lint locally, because declare_clippy_lint! only accepts doc attribute. Can we just add backticks to all the words in Item Kinds column or add those words to clippy's allowed markdown idents?
clippy source Signed-off-by: Zihan <zihanli0822@gmail.com>
When checking the span of doc attributes, we use the span of the lit str instead of the span of `hir::Attribute`. This makes the span checking more robust when we are dealing with certain proc-macro crates. For example, some proc-macro crates may take doc lit str from user and attach them to a new `#[doc]` created by the proc-macro. In such cases, checking the span of lit str makes sure that doc related lints can still fire properly on user-provided docs. changelog: [`empty_docs`]: lint user-provided doc on proc-macro expanded codes changelog: [`missing_safety_doc`]: lint user-provided doc on proc-macro expanded codes changelog: [`missing_panics_doc`]: lint user-provided doc on proc-macro expanded codes changelog: [`needless_doctest_main`]: lint user-provided doc on proc-macro expanded codes changelog: [`doc_markdown`]: lint user-provided doc on proc-macro expanded codes Signed-off-by: Zihan <zihanli0822@gmail.com>
b7034e0 to
f0c1cb6
Compare
| /// | `global_asm` | "global_asm" | | ||
| /// | `UPPER_SNAKE_CASE` | "static", "const" | | ||
| /// | `PascalCase` | "ty_alias", "opaque_ty", "enum", "struct", "union", "trait", "trait_alias", "impl" | | ||
| /// | `PascalCase` | "ty alias", "opaque ty", "enum", "struct", "union", "trait", "trait alias", "impl" | |
There was a problem hiding this comment.
It turns out that "foreign_mod" and "global_asm" do not trigger missing backticks, but all other snake-cased words in the table do. "foreign_mod" and "global_asm" actually have not been whitelisted as valid markdown idents in clippy config. I guess there might be some issue with clippy::doc_markdown lint.
fixes #16317
fixes #16382
When checking the span of doc attributes, we use the span of the lit str instead of the span of
hir::Attribute. This makes the span checking more robust when we are dealing with certain proc-macro crates.For example, cxx's bridge takes doc lit str from user and attach them to a new
#[doc]created by the proc-macro. In such case, checking the span of lit str makes sure that doc related lints can still fire properly on user-provided docs.changelog: [
empty_docs]: lint user-provided doc on proc-macro expanded codeschangelog: [
missing_safety_doc]: lint user-provided doc on proc-macro expanded codeschangelog: [
missing_panics_doc]: lint user-provided doc on proc-macro expanded codes