Skip to content

Commit b4b44a7

Browse files
committed
Fix some cases with #[deny(missing_docs)]
Generated functions by wasm-bindgen should either be `#[doc(hidden)]` or include the docs on the original item! Closes #425
1 parent bfec9e6 commit b4b44a7

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

crates/backend/src/codegen.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ impl ToTokens for ast::Struct {
191191

192192
#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))]
193193
#[no_mangle]
194+
#[doc(hidden)]
194195
pub unsafe extern fn #free_fn(ptr: u32) {
195196
<#name as ::wasm_bindgen::convert::FromWasmAbi>::from_abi(
196197
ptr,
@@ -246,6 +247,7 @@ impl ToTokens for ast::StructField {
246247
);
247248
(quote! {
248249
#[no_mangle]
250+
#[doc(hidden)]
249251
#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))]
250252
pub unsafe extern fn #getter(js: u32)
251253
-> <#ty as ::wasm_bindgen::convert::IntoWasmAbi>::Abi
@@ -279,6 +281,7 @@ impl ToTokens for ast::StructField {
279281

280282
(quote! {
281283
#[no_mangle]
284+
#[doc(hidden)]
282285
#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))]
283286
pub unsafe extern fn #setter(
284287
js: u32,
@@ -441,8 +444,10 @@ impl ToTokens for ast::Export {
441444
let descriptor_name = Ident::new(&descriptor_name, Span::call_site());
442445
let nargs = self.function.arguments.len() as u32;
443446
let argtys = self.function.arguments.iter().map(|arg| &arg.ty);
447+
let attrs = &self.function.rust_attrs;
444448

445449
let tokens = quote! {
450+
#(#attrs)*
446451
#[export_name = #export_name]
447452
#[allow(non_snake_case)]
448453
#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))]

tests/all/import_class.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,3 +456,52 @@ fn rename_setter_getter() {
456456
)
457457
.test();
458458
}
459+
460+
#[test]
461+
fn deny_missing_docs() {
462+
project()
463+
.file(
464+
"src/lib.rs",
465+
r#"
466+
//! dox
467+
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
468+
#![deny(missing_docs)]
469+
#![allow(dead_code)]
470+
471+
extern crate wasm_bindgen;
472+
473+
use wasm_bindgen::prelude::*;
474+
475+
/// dox
476+
#[wasm_bindgen]
477+
pub struct Bar {
478+
/// dox
479+
pub a: u32,
480+
b: i64,
481+
}
482+
483+
#[wasm_bindgen]
484+
extern {
485+
/// dox
486+
pub type Foo;
487+
488+
/// dox
489+
#[wasm_bindgen(constructor)]
490+
pub fn new() -> Foo;
491+
492+
/// dox
493+
#[wasm_bindgen(getter = a, method)]
494+
pub fn test(this: &Foo) -> i32;
495+
496+
/// dox
497+
pub fn foo();
498+
}
499+
500+
/// dox
501+
#[wasm_bindgen]
502+
pub fn test() {
503+
}
504+
"#,
505+
)
506+
.test();
507+
}

0 commit comments

Comments
 (0)