Skip to content

Commit 10677d6

Browse files
committed
add with_empty_docs attr macro & test cases for issue rust-lang#12377
1 parent 86717f2 commit 10677d6

File tree

3 files changed

+58
-10
lines changed

3 files changed

+58
-10
lines changed

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

+28-10
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,36 +42,54 @@ 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
| ^^^
7373
|
7474
= help: consider removing or filling it
7575

76-
error: aborting due to 9 previous errors
76+
error: empty doc comment
77+
--> tests/ui/empty_docs.rs:77:5
78+
|
79+
LL | #[with_empty_docs]
80+
| ^^^^^^^^^^^^^^^^^^
81+
|
82+
= help: consider removing or filling it
83+
= note: this error originates in the attribute macro `with_empty_docs` (in Nightly builds, run with -Z macro-backtrace for more info)
84+
85+
error: empty doc comment
86+
--> tests/ui/empty_docs.rs:82:5
87+
|
88+
LL | #[with_empty_docs]
89+
| ^^^^^^^^^^^^^^^^^^
90+
|
91+
= help: consider removing or filling it
92+
= note: this error originates in the attribute macro `with_empty_docs` (in Nightly builds, run with -Z macro-backtrace for more info)
93+
94+
error: aborting due to 11 previous errors
7795

0 commit comments

Comments
 (0)