Skip to content

Commit

Permalink
fix [empty_docs] trigger in proc-macro
Browse files Browse the repository at this point in the history
  • Loading branch information
J-ZhengLi committed Mar 12, 2024
1 parent 10677d6 commit 7189636
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 22 deletions.
19 changes: 16 additions & 3 deletions clippy_lints/src/doc/mod.rs
Expand Up @@ -14,7 +14,7 @@ use rustc_data_structures::fx::FxHashSet;
use rustc_hir as hir;
use rustc_hir::intravisit::{self, Visitor};
use rustc_hir::{AnonConst, Expr};
use rustc_lint::{LateContext, LateLintPass};
use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::hir::nested_filter;
use rustc_middle::lint::in_external_macro;
use rustc_middle::ty;
Expand Down Expand Up @@ -523,7 +523,11 @@ struct DocHeaders {
/// Others are checked elsewhere, e.g. in `check_doc` if they need access to markdown, or
/// back in the various late lint pass methods if they need the final doc headers, like "Safety" or
/// "Panics" sections.
fn check_attrs(cx: &LateContext<'_>, valid_idents: &FxHashSet<String>, attrs: &[Attribute]) -> Option<DocHeaders> {
fn check_attrs<'cx>(
cx: &LateContext<'cx>,
valid_idents: &FxHashSet<String>,
attrs: &'cx [Attribute],
) -> Option<DocHeaders> {
/// We don't want the parser to choke on intra doc links. Since we don't
/// actually care about rendering them, just pretend that all broken links
/// point to a fake address.
Expand All @@ -538,7 +542,16 @@ fn check_attrs(cx: &LateContext<'_>, valid_idents: &FxHashSet<String>, attrs: &[

suspicious_doc_comments::check(cx, attrs);

let (fragments, _) = attrs_to_doc_fragments(attrs.iter().map(|attr| (attr, None)), true);
let (fragments, _) = attrs_to_doc_fragments(
attrs.iter().filter_map(|attr| {
if in_external_macro(cx.sess(), attr.span) {
None
} else {
Some((attr, None))
}
}),
true,
);
let mut doc = fragments.iter().fold(String::new(), |mut acc, fragment| {
add_doc_fragment(&mut acc, fragment);
acc
Expand Down
20 changes: 1 addition & 19 deletions tests/ui/empty_docs.stderr
Expand Up @@ -73,23 +73,5 @@ LL | ///
|
= help: consider removing or filling it

error: empty doc comment
--> tests/ui/empty_docs.rs:77:5
|
LL | #[with_empty_docs]
| ^^^^^^^^^^^^^^^^^^
|
= help: consider removing or filling it
= note: this error originates in the attribute macro `with_empty_docs` (in Nightly builds, run with -Z macro-backtrace for more info)

error: empty doc comment
--> tests/ui/empty_docs.rs:82:5
|
LL | #[with_empty_docs]
| ^^^^^^^^^^^^^^^^^^
|
= help: consider removing or filling it
= note: this error originates in the attribute macro `with_empty_docs` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to 11 previous errors
error: aborting due to 9 previous errors

0 comments on commit 7189636

Please sign in to comment.