Skip to content

Commit

Permalink
add with_empty_docs attr macro & test cases for issue #12377
Browse files Browse the repository at this point in the history
  • Loading branch information
J-ZhengLi committed Mar 12, 2024
1 parent 86717f2 commit 10677d6
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 10 deletions.
13 changes: 13 additions & 0 deletions tests/ui/auxiliary/proc_macro_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,16 @@ pub fn rewrite_struct(_args: TokenStream, input: TokenStream) -> TokenStream {

quote!(#item_struct).into()
}

#[proc_macro_attribute]
pub fn with_empty_docs(_attr: TokenStream, input: TokenStream) -> TokenStream {
let item = parse_macro_input!(input as syn::Item);
let attrs: Vec<syn::Attribute> = vec![];
let doc_comment = "";
quote! {
#(#attrs)*
#[doc = #doc_comment]
#item
}
.into()
}
17 changes: 17 additions & 0 deletions tests/ui/empty_docs.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
//@aux-build:proc_macro_attr.rs

#![allow(unused)]
#![warn(clippy::empty_docs)]
#![allow(clippy::mixed_attributes_style)]
#![feature(extern_types)]

mod outer {
//!
Expand Down Expand Up @@ -67,3 +70,17 @@ mod outer {
y: i32,
}
}

mod issue_12377 {
use proc_macro_attr::with_empty_docs;

#[with_empty_docs]
extern "C" {
type Test;
}

#[with_empty_docs]
struct Foo {
a: u8,
}
}
38 changes: 28 additions & 10 deletions tests/ui/empty_docs.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: empty doc comment
--> tests/ui/empty_docs.rs:6:5
--> tests/ui/empty_docs.rs:9:5
|
LL | //!
| ^^^
Expand All @@ -9,31 +9,31 @@ LL | //!
= help: to override `-D warnings` add `#[allow(clippy::empty_docs)]`

error: empty doc comment
--> tests/ui/empty_docs.rs:14:5
--> tests/ui/empty_docs.rs:17:5
|
LL | ///
| ^^^
|
= help: consider removing or filling it

error: empty doc comment
--> tests/ui/empty_docs.rs:16:9
--> tests/ui/empty_docs.rs:19:9
|
LL | ///
| ^^^
|
= help: consider removing or filling it

error: empty doc comment
--> tests/ui/empty_docs.rs:27:5
--> tests/ui/empty_docs.rs:30:5
|
LL | #[doc = ""]
| ^^^^^^^^^^^
|
= help: consider removing or filling it

error: empty doc comment
--> tests/ui/empty_docs.rs:30:5
--> tests/ui/empty_docs.rs:33:5
|
LL | / #[doc = ""]
LL | | #[doc = ""]
Expand All @@ -42,36 +42,54 @@ LL | | #[doc = ""]
= help: consider removing or filling it

error: empty doc comment
--> tests/ui/empty_docs.rs:37:5
--> tests/ui/empty_docs.rs:40:5
|
LL | ///
| ^^^
|
= help: consider removing or filling it

error: empty doc comment
--> tests/ui/empty_docs.rs:50:13
--> tests/ui/empty_docs.rs:53:13
|
LL | /*! */
| ^^^^^^
|
= help: consider removing or filling it

error: empty doc comment
--> tests/ui/empty_docs.rs:58:13
--> tests/ui/empty_docs.rs:61:13
|
LL | ///
| ^^^
|
= help: consider removing or filling it

error: empty doc comment
--> tests/ui/empty_docs.rs:66:9
--> tests/ui/empty_docs.rs:69:9
|
LL | ///
| ^^^
|
= help: consider removing or filling it

error: aborting due to 9 previous errors
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

0 comments on commit 10677d6

Please sign in to comment.