From aa61115455096564da56eac5876cfd181cf49ef8 Mon Sep 17 00:00:00 2001 From: Kevin Flansburg Date: Tue, 7 May 2024 23:59:11 -0400 Subject: [PATCH] Fix `clippy` lint `empty_docs` (#3946) * Do not include docstring if empty Closes #3945 * Move changelog entry to correct section --- CHANGELOG.md | 3 +++ crates/backend/src/codegen.rs | 19 ++++++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c06fa7f3e0..3c0db74a1e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,9 @@ * Fix MSRV compilation. [#3927](https://github.com/rustwasm/wasm-bindgen/pull/3927) +* Fixed `clippy::empty_docs` lint. + [#3946](https://github.com/rustwasm/wasm-bindgen/pull/3946) + -------------------------------------------------------------------------------- ## [0.2.92](https://github.com/rustwasm/wasm-bindgen/compare/0.2.91...0.2.92) diff --git a/crates/backend/src/codegen.rs b/crates/backend/src/codegen.rs index be1ff5608fa..ffd953104ad 100644 --- a/crates/backend/src/codegen.rs +++ b/crates/backend/src/codegen.rs @@ -815,10 +815,18 @@ impl ToTokens for ast::ImportType { let no_deref = self.no_deref; + let doc = if doc_comment.is_empty() { + quote! {} + } else { + quote! { + #[doc = #doc_comment] + } + }; + (quote! { #[automatically_derived] #(#attrs)* - #[doc = #doc_comment] + #doc #[repr(transparent)] #vis struct #rust_name { obj: #internal_obj @@ -1294,7 +1302,12 @@ impl TryToTokens for ast::ImportFunction { let abi_arguments = &abi_arguments[..]; let abi_argument_names = &abi_argument_names[..]; - let doc_comment = &self.doc_comment; + let doc = if self.doc_comment.is_empty() { + quote! {} + } else { + let doc_comment = &self.doc_comment; + quote! { #[doc = #doc_comment] } + }; let me = if is_method { quote! { &self, } } else { @@ -1343,7 +1356,7 @@ impl TryToTokens for ast::ImportFunction { #[allow(nonstandard_style)] #[allow(clippy::all, clippy::nursery, clippy::pedantic, clippy::restriction)] #(#attrs)* - #[doc = #doc_comment] + #doc #vis #maybe_async #maybe_unsafe fn #rust_name(#me #(#arguments),*) #ret { #extern_fn