Skip to content

Commit 99e8000

Browse files
committed
Auto merge of #12466 - J-ZhengLi:issue12377, r=blyxyas
fix [`empty_docs`] trigger in proc-macro fixes: #12377 --- changelog: fix [`empty_docs`] trigger in proc-macros
2 parents 92ca7c9 + 3cd6fd1 commit 99e8000

File tree

4 files changed

+50
-11
lines changed

4 files changed

+50
-11
lines changed

clippy_lints/src/doc/mod.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use rustc_data_structures::fx::FxHashSet;
1414
use rustc_hir as hir;
1515
use rustc_hir::intravisit::{self, Visitor};
1616
use rustc_hir::{AnonConst, Expr};
17-
use rustc_lint::{LateContext, LateLintPass};
17+
use rustc_lint::{LateContext, LateLintPass, LintContext};
1818
use rustc_middle::hir::nested_filter;
1919
use rustc_middle::lint::in_external_macro;
2020
use rustc_middle::ty;
@@ -538,7 +538,16 @@ fn check_attrs(cx: &LateContext<'_>, valid_idents: &FxHashSet<String>, attrs: &[
538538

539539
suspicious_doc_comments::check(cx, attrs);
540540

541-
let (fragments, _) = attrs_to_doc_fragments(attrs.iter().map(|attr| (attr, None)), true);
541+
let (fragments, _) = attrs_to_doc_fragments(
542+
attrs.iter().filter_map(|attr| {
543+
if in_external_macro(cx.sess(), attr.span) {
544+
None
545+
} else {
546+
Some((attr, None))
547+
}
548+
}),
549+
true,
550+
);
542551
let mut doc = fragments.iter().fold(String::new(), |mut acc, fragment| {
543552
add_doc_fragment(&mut acc, fragment);
544553
acc

tests/ui/auxiliary/proc_macro_attr.rs

+13
Original file line numberDiff line numberDiff line change
@@ -163,3 +163,16 @@ pub fn rewrite_struct(_args: TokenStream, input: TokenStream) -> TokenStream {
163163

164164
quote!(#item_struct).into()
165165
}
166+
167+
#[proc_macro_attribute]
168+
pub fn with_empty_docs(_attr: TokenStream, input: TokenStream) -> TokenStream {
169+
let item = parse_macro_input!(input as syn::Item);
170+
let attrs: Vec<syn::Attribute> = vec![];
171+
let doc_comment = "";
172+
quote! {
173+
#(#attrs)*
174+
#[doc = #doc_comment]
175+
#item
176+
}
177+
.into()
178+
}

tests/ui/empty_docs.rs

+17
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
//@aux-build:proc_macro_attr.rs
2+
13
#![allow(unused)]
24
#![warn(clippy::empty_docs)]
35
#![allow(clippy::mixed_attributes_style)]
6+
#![feature(extern_types)]
47

58
mod outer {
69
//!
@@ -67,3 +70,17 @@ mod outer {
6770
y: i32,
6871
}
6972
}
73+
74+
mod issue_12377 {
75+
use proc_macro_attr::with_empty_docs;
76+
77+
#[with_empty_docs]
78+
extern "C" {
79+
type Test;
80+
}
81+
82+
#[with_empty_docs]
83+
struct Foo {
84+
a: u8,
85+
}
86+
}

tests/ui/empty_docs.stderr

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: empty doc comment
2-
--> tests/ui/empty_docs.rs:6:5
2+
--> tests/ui/empty_docs.rs:9:5
33
|
44
LL | //!
55
| ^^^
@@ -9,31 +9,31 @@ LL | //!
99
= help: to override `-D warnings` add `#[allow(clippy::empty_docs)]`
1010

1111
error: empty doc comment
12-
--> tests/ui/empty_docs.rs:14:5
12+
--> tests/ui/empty_docs.rs:17:5
1313
|
1414
LL | ///
1515
| ^^^
1616
|
1717
= help: consider removing or filling it
1818

1919
error: empty doc comment
20-
--> tests/ui/empty_docs.rs:16:9
20+
--> tests/ui/empty_docs.rs:19:9
2121
|
2222
LL | ///
2323
| ^^^
2424
|
2525
= help: consider removing or filling it
2626

2727
error: empty doc comment
28-
--> tests/ui/empty_docs.rs:27:5
28+
--> tests/ui/empty_docs.rs:30:5
2929
|
3030
LL | #[doc = ""]
3131
| ^^^^^^^^^^^
3232
|
3333
= help: consider removing or filling it
3434

3535
error: empty doc comment
36-
--> tests/ui/empty_docs.rs:30:5
36+
--> tests/ui/empty_docs.rs:33:5
3737
|
3838
LL | / #[doc = ""]
3939
LL | | #[doc = ""]
@@ -42,31 +42,31 @@ LL | | #[doc = ""]
4242
= help: consider removing or filling it
4343

4444
error: empty doc comment
45-
--> tests/ui/empty_docs.rs:37:5
45+
--> tests/ui/empty_docs.rs:40:5
4646
|
4747
LL | ///
4848
| ^^^
4949
|
5050
= help: consider removing or filling it
5151

5252
error: empty doc comment
53-
--> tests/ui/empty_docs.rs:50:13
53+
--> tests/ui/empty_docs.rs:53:13
5454
|
5555
LL | /*! */
5656
| ^^^^^^
5757
|
5858
= help: consider removing or filling it
5959

6060
error: empty doc comment
61-
--> tests/ui/empty_docs.rs:58:13
61+
--> tests/ui/empty_docs.rs:61:13
6262
|
6363
LL | ///
6464
| ^^^
6565
|
6666
= help: consider removing or filling it
6767

6868
error: empty doc comment
69-
--> tests/ui/empty_docs.rs:66:9
69+
--> tests/ui/empty_docs.rs:69:9
7070
|
7171
LL | ///
7272
| ^^^

0 commit comments

Comments
 (0)