Skip to content

Commit 09bda50

Browse files
committed
Don't emit unexpected cfgs in proc-macros
1 parent f071c7e commit 09bda50

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
@@ -28,3 +28,6 @@ proc-macro2 = "1.0"
2828
quote = '1.0'
2929
syn = { version = '2.0', features = ['full'] }
3030
wasm-bindgen-shared = { path = "../shared", version = "=0.2.95" }
31+
32+
[lints.rust]
33+
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
@@ -224,6 +224,11 @@ impl ToTokens for ast::Struct {
224224
let free_fn = Ident::new(&shared::free_function(&name_str), Span::call_site());
225225
let unwrap_fn = Ident::new(&shared::unwrap_function(&name_str), Span::call_site());
226226
let wasm_bindgen = &self.wasm_bindgen;
227+
let maybe_no_coverage = if cfg!(wasm_bindgen_unstable_test_coverage) {
228+
Some(quote! { #[coverage(off)] })
229+
} else {
230+
None
231+
};
227232
(quote! {
228233
#[automatically_derived]
229234
impl #wasm_bindgen::describe::WasmDescribe for #name {
@@ -300,7 +305,7 @@ impl ToTokens for ast::Struct {
300305
#[doc(hidden)]
301306
// `allow_delayed` is whether it's ok to not actually free the `ptr` immediately
302307
// if it's still borrowed.
303-
#[cfg_attr(wasm_bindgen_unstable_test_coverage, coverage(off))]
308+
#maybe_no_coverage
304309
pub unsafe extern "C" fn #free_fn(ptr: u32, allow_delayed: u32) {
305310
use #wasm_bindgen::__rt::alloc::rc::Rc;
306311

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

480490
// Split this out so that it isn't affected by `quote_spanned!`.
481491
//
@@ -496,7 +506,7 @@ impl ToTokens for ast::StructField {
496506
const _: () = {
497507
#[cfg_attr(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "none")), no_mangle)]
498508
#[doc(hidden)]
499-
#[cfg_attr(wasm_bindgen_unstable_test_coverage, coverage(off))]
509+
#maybe_no_coverage
500510
pub unsafe extern "C" fn #getter(js: u32)
501511
-> #wasm_bindgen::convert::WasmRet<<#ty as #wasm_bindgen::convert::IntoWasmAbi>::Abi>
502512
{
@@ -538,7 +548,7 @@ impl ToTokens for ast::StructField {
538548
const _: () = {
539549
#[no_mangle]
540550
#[doc(hidden)]
541-
#[cfg_attr(wasm_bindgen_unstable_test_coverage, coverage(off))]
551+
#maybe_no_coverage
542552
pub unsafe extern "C" fn #setter(
543553
js: u32,
544554
#(#args,)*
@@ -787,6 +797,12 @@ impl TryToTokens for ast::Export {
787797
quote! {}
788798
};
789799

800+
let maybe_no_coverage = if cfg!(wasm_bindgen_unstable_test_coverage) {
801+
Some(quote! { #[coverage(off)] })
802+
} else {
803+
None
804+
};
805+
790806
(quote! {
791807
#[automatically_derived]
792808
const _: () = {
@@ -795,7 +811,7 @@ impl TryToTokens for ast::Export {
795811
all(target_arch = "wasm32", any(target_os = "unknown", target_os = "none")),
796812
export_name = #export_name,
797813
)]
798-
#[cfg_attr(wasm_bindgen_unstable_test_coverage, coverage(off))]
814+
#maybe_no_coverage
799815
pub unsafe extern "C" fn #generated_name(#(#args),*) -> #wasm_bindgen::convert::WasmRet<#projection::Abi> {
800816
#start_check
801817

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

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

12431265
#[automatically_derived]
12441266
impl #wasm_bindgen::describe::WasmDescribe for #enum_name {
1245-
#[cfg_attr(wasm_bindgen_unstable_test_coverage, coverage(off))]
1267+
#maybe_no_coverage
12461268
fn describe() {
12471269
use #wasm_bindgen::describe::*;
12481270
inform(STRING_ENUM);
@@ -1536,6 +1558,11 @@ impl ToTokens for ast::Enum {
15361558
let name_len = name_str.len() as u32;
15371559
let name_chars = name_str.chars().map(|c| c as u32);
15381560
let hole = &self.hole;
1561+
let maybe_no_coverage = if cfg!(wasm_bindgen_unstable_test_coverage) {
1562+
Some(quote! { #[coverage(off)] })
1563+
} else {
1564+
None
1565+
};
15391566
let underlying = if self.signed {
15401567
quote! { i32 }
15411568
} else {
@@ -1588,7 +1615,7 @@ impl ToTokens for ast::Enum {
15881615

15891616
#[automatically_derived]
15901617
impl #wasm_bindgen::describe::WasmDescribe for #enum_name {
1591-
#[cfg_attr(wasm_bindgen_unstable_test_coverage, coverage(off))]
1618+
#maybe_no_coverage
15921619
fn describe() {
15931620
use #wasm_bindgen::describe::*;
15941621
inform(ENUM);
@@ -1853,6 +1880,12 @@ impl<'a, T: ToTokens> ToTokens for Descriptor<'a, T> {
18531880
return;
18541881
}
18551882

1883+
let maybe_no_coverage = if cfg!(wasm_bindgen_unstable_test_coverage) {
1884+
Some(quote! { #[coverage(off)] })
1885+
} else {
1886+
None
1887+
};
1888+
18561889
let name = Ident::new(&format!("__wbindgen_describe_{}", ident), ident.span());
18571890
let inner = &self.inner;
18581891
let attrs = &self.attrs;
@@ -1864,7 +1897,7 @@ impl<'a, T: ToTokens> ToTokens for Descriptor<'a, T> {
18641897
#(#attrs)*
18651898
#[no_mangle]
18661899
#[doc(hidden)]
1867-
#[cfg_attr(wasm_bindgen_unstable_test_coverage, coverage(off))]
1900+
#maybe_no_coverage
18681901
pub extern "C" fn #name() {
18691902
use #wasm_bindgen::describe::*;
18701903
// 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", any(target_os = "unknown", target_os = "none")))]
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)