Skip to content

Commit 79c6457

Browse files
committed
Don't emit unexpected cfgs in proc-macros
1 parent fe5d89f commit 79c6457

File tree

3 files changed

+49
-8
lines changed

3 files changed

+49
-8
lines changed

crates/backend/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,6 @@ proc-macro2 = "1.0"
2525
quote = '1.0'
2626
syn = { version = '2.0', features = ['full'] }
2727
wasm-bindgen-shared = { path = "../shared", version = "=0.2.95" }
28+
29+
[lints.rust]
30+
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(wasm_bindgen_unstable_test_coverage)'] }

crates/backend/src/codegen.rs

+40-7
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,11 @@ impl ToTokens for ast::Struct {
223223
let free_fn = Ident::new(&shared::free_function(&name_str), Span::call_site());
224224
let unwrap_fn = Ident::new(&shared::unwrap_function(&name_str), Span::call_site());
225225
let wasm_bindgen = &self.wasm_bindgen;
226+
let maybe_no_coverage = if cfg!(wasm_bindgen_unstable_test_coverage) {
227+
Some(quote! { #[coverage(off)] })
228+
} else {
229+
None
230+
};
226231
(quote! {
227232
#[automatically_derived]
228233
impl #wasm_bindgen::describe::WasmDescribe for #name {
@@ -299,7 +304,7 @@ impl ToTokens for ast::Struct {
299304
#[doc(hidden)]
300305
// `allow_delayed` is whether it's ok to not actually free the `ptr` immediately
301306
// if it's still borrowed.
302-
#[cfg_attr(wasm_bindgen_unstable_test_coverage, coverage(off))]
307+
#maybe_no_coverage
303308
pub unsafe extern "C" fn #free_fn(ptr: u32, allow_delayed: u32) {
304309
use #wasm_bindgen::__rt::alloc::rc::Rc;
305310

@@ -475,6 +480,11 @@ impl ToTokens for ast::StructField {
475480
quote! { assert_copy::<#ty>() }
476481
};
477482
let maybe_assert_copy = respan(maybe_assert_copy, ty);
483+
let maybe_no_coverage = if cfg!(wasm_bindgen_unstable_test_coverage) {
484+
Some(quote! { #[coverage(off)] })
485+
} else {
486+
None
487+
};
478488

479489
// Split this out so that it isn't affected by `quote_spanned!`.
480490
//
@@ -495,7 +505,7 @@ impl ToTokens for ast::StructField {
495505
const _: () = {
496506
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), no_mangle)]
497507
#[doc(hidden)]
498-
#[cfg_attr(wasm_bindgen_unstable_test_coverage, coverage(off))]
508+
#maybe_no_coverage
499509
pub unsafe extern "C" fn #getter(js: u32)
500510
-> #wasm_bindgen::convert::WasmRet<<#ty as #wasm_bindgen::convert::IntoWasmAbi>::Abi>
501511
{
@@ -537,7 +547,7 @@ impl ToTokens for ast::StructField {
537547
const _: () = {
538548
#[no_mangle]
539549
#[doc(hidden)]
540-
#[cfg_attr(wasm_bindgen_unstable_test_coverage, coverage(off))]
550+
#maybe_no_coverage
541551
pub unsafe extern "C" fn #setter(
542552
js: u32,
543553
#(#args,)*
@@ -786,6 +796,12 @@ impl TryToTokens for ast::Export {
786796
quote! {}
787797
};
788798

799+
let maybe_no_coverage = if cfg!(wasm_bindgen_unstable_test_coverage) {
800+
Some(quote! { #[coverage(off)] })
801+
} else {
802+
None
803+
};
804+
789805
(quote! {
790806
#[automatically_derived]
791807
const _: () = {
@@ -794,7 +810,7 @@ impl TryToTokens for ast::Export {
794810
all(target_arch = "wasm32", target_os = "unknown"),
795811
export_name = #export_name,
796812
)]
797-
#[cfg_attr(wasm_bindgen_unstable_test_coverage, coverage(off))]
813+
#maybe_no_coverage
798814
pub unsafe extern "C" fn #generated_name(#(#args),*) -> #wasm_bindgen::convert::WasmRet<#projection::Abi> {
799815
#start_check
800816

@@ -1155,6 +1171,12 @@ impl ToTokens for ast::StringEnum {
11551171
let hole = variant_count + 1;
11561172
let attrs = &self.rust_attrs;
11571173

1174+
let maybe_no_coverage = if cfg!(wasm_bindgen_unstable_test_coverage) {
1175+
Some(quote! { #[coverage(off)] })
1176+
} else {
1177+
None
1178+
};
1179+
11581180
let invalid_to_str_msg = format!(
11591181
"Converting an invalid string enum ({}) back to a string is currently not supported",
11601182
enum_name
@@ -1241,7 +1263,7 @@ impl ToTokens for ast::StringEnum {
12411263

12421264
#[automatically_derived]
12431265
impl #wasm_bindgen::describe::WasmDescribe for #enum_name {
1244-
#[cfg_attr(wasm_bindgen_unstable_test_coverage, coverage(off))]
1266+
#maybe_no_coverage
12451267
fn describe() {
12461268
use #wasm_bindgen::describe::*;
12471269
inform(STRING_ENUM);
@@ -1535,6 +1557,11 @@ impl ToTokens for ast::Enum {
15351557
let name_len = name_str.len() as u32;
15361558
let name_chars = name_str.chars().map(|c| c as u32);
15371559
let hole = &self.hole;
1560+
let maybe_no_coverage = if cfg!(wasm_bindgen_unstable_test_coverage) {
1561+
Some(quote! { #[coverage(off)] })
1562+
} else {
1563+
None
1564+
};
15381565
let underlying = if self.signed {
15391566
quote! { i32 }
15401567
} else {
@@ -1587,7 +1614,7 @@ impl ToTokens for ast::Enum {
15871614

15881615
#[automatically_derived]
15891616
impl #wasm_bindgen::describe::WasmDescribe for #enum_name {
1590-
#[cfg_attr(wasm_bindgen_unstable_test_coverage, coverage(off))]
1617+
#maybe_no_coverage
15911618
fn describe() {
15921619
use #wasm_bindgen::describe::*;
15931620
inform(ENUM);
@@ -1813,6 +1840,12 @@ impl<'a, T: ToTokens> ToTokens for Descriptor<'a, T> {
18131840
return;
18141841
}
18151842

1843+
let maybe_no_coverage = if cfg!(wasm_bindgen_unstable_test_coverage) {
1844+
Some(quote! { #[coverage(off)] })
1845+
} else {
1846+
None
1847+
};
1848+
18161849
let name = Ident::new(&format!("__wbindgen_describe_{}", ident), ident.span());
18171850
let inner = &self.inner;
18181851
let attrs = &self.attrs;
@@ -1824,7 +1857,7 @@ impl<'a, T: ToTokens> ToTokens for Descriptor<'a, T> {
18241857
#(#attrs)*
18251858
#[no_mangle]
18261859
#[doc(hidden)]
1827-
#[cfg_attr(wasm_bindgen_unstable_test_coverage, coverage(off))]
1860+
#maybe_no_coverage
18281861
pub extern "C" fn #name() {
18291862
use #wasm_bindgen::describe::*;
18301863
// See definition of `link_mem_intrinsics` for what this is doing

crates/test-macro/src/lib.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,17 @@ pub fn wasm_bindgen_test(
109109
// main test harness. This is the entry point for all tests.
110110
let name = format_ident!("__wbgt_{}_{}", ident, CNT.fetch_add(1, Ordering::SeqCst));
111111
let wasm_bindgen_path = attributes.wasm_bindgen_path;
112+
let coverage = if cfg!(wasm_bindgen_unstable_test_coverage) {
113+
Some(quote! { #[coverage(off)] })
114+
} else {
115+
None
116+
};
112117
tokens.extend(
113118
quote! {
114119
const _: () = {
115120
#[no_mangle]
116121
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
117-
#[cfg_attr(wasm_bindgen_unstable_test_coverage, coverage(off))]
122+
#coverage
118123
pub extern "C" fn #name(cx: &#wasm_bindgen_path::__rt::Context) {
119124
let test_name = ::core::concat!(::core::module_path!(), "::", ::core::stringify!(#ident));
120125
#test_body

0 commit comments

Comments
 (0)