From a00c9f721de6b4449eb0c150a19511ba08d5d4b3 Mon Sep 17 00:00:00 2001 From: daxpedda Date: Thu, 19 Dec 2024 19:33:54 +0100 Subject: [PATCH] Transition to `wasm-bindgen-test/unstable-test-coverage` --- CHANGELOG.md | 6 +++++ Cargo.toml | 13 +++------ crates/backend/Cargo.toml | 1 + crates/backend/src/codegen.rs | 31 ++++++++++++++------- crates/macro-support/Cargo.toml | 1 + crates/macro/Cargo.toml | 1 + crates/test-macro/Cargo.toml | 3 +++ crates/test-macro/src/lib.rs | 9 +++++-- crates/test/Cargo.toml | 16 ++++------- crates/test/src/coverage.rs | 6 ++--- guide/src/wasm-bindgen-test/coverage.md | 6 ++--- src/closure.rs | 26 +++++++++--------- src/convert/closures.rs | 12 ++++----- src/convert/slices.rs | 4 +-- src/describe.rs | 36 ++++++++++++------------- src/lib.rs | 5 ++-- src/link.rs | 2 +- src/rt/mod.rs | 25 +++-------------- 18 files changed, 101 insertions(+), 102 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f00eaaa3cb8..8bf7c6de95b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,12 @@ * `console.*()` calls in tests are now always intercepted by default. To show them use `--nocapture`. When shown they are always printed in-place instead of after test results, analogous to `cargo test`. [#4356](https://github.com/rustwasm/wasm-bindgen/pull/4356) +* Instrumentation is now disabled on internal functions with the `msrv` crate feature instead of `cfg(wasm_bindgen_unstable_test_coverage)`. + [#4369](https://github.com/rustwasm/wasm-bindgen/pull/4369) + +* Replaced `cfg(wasm_bindgen_unstable_test_coverage)` with crate feature `unstable-test-coverage` on `wasm-bindgen-test`. + [#4369](https://github.com/rustwasm/wasm-bindgen/pull/4369) + ### Fixed - Fixed using [JavaScript keyword](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#keywords) as identifiers not being handled correctly. diff --git a/Cargo.toml b/Cargo.toml index 57536ab1ce9..e6eccdc363a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,7 +33,7 @@ std = [] # The current rustc version is detected at compile-time, so enabling this # feature for older compilers will NOT result in a compilation error. Instead, # any unsupported language feature will not be used. -msrv = ["rustversion"] +msrv = ["rustversion", "wasm-bindgen-macro/msrv"] # Whether or not the `#[wasm_bindgen]` macro is strict and generates an error on # all unused attributes @@ -67,15 +67,8 @@ wasm-bindgen-futures = { path = 'crates/futures' } wasm-bindgen-test-crate-a = { path = 'tests/crates/a' } wasm-bindgen-test-crate-b = { path = 'tests/crates/b' } -[lints.rust] -unexpected_cfgs = { level = "warn", check-cfg = ['cfg(wasm_bindgen_unstable_test_coverage)'] } - -[lints.clippy] -large_enum_variant = "allow" -new_without_default = "allow" -overly_complex_bool_expr = "allow" -too_many_arguments = "allow" -type_complexity = "allow" +[lints] +workspace = true [workspace.lints.clippy] large_enum_variant = "allow" diff --git a/crates/backend/Cargo.toml b/crates/backend/Cargo.toml index ab964ab8ec1..b3cd4d2f6f1 100644 --- a/crates/backend/Cargo.toml +++ b/crates/backend/Cargo.toml @@ -15,6 +15,7 @@ version = "0.2.99" [features] extra-traits = ["syn/extra-traits"] +msrv = [] [dependencies] bumpalo = "3.0.0" diff --git a/crates/backend/src/codegen.rs b/crates/backend/src/codegen.rs index c8decb4a136..6959dddcb1a 100644 --- a/crates/backend/src/codegen.rs +++ b/crates/backend/src/codegen.rs @@ -223,6 +223,7 @@ impl ToTokens for ast::Struct { let free_fn = Ident::new(&shared::free_function(&name_str), Span::call_site()); let unwrap_fn = Ident::new(&shared::unwrap_function(&name_str), Span::call_site()); let wasm_bindgen = &self.wasm_bindgen; + let coverage = coverage(wasm_bindgen); (quote! { #[automatically_derived] impl #wasm_bindgen::__rt::marker::SupportsConstructor for #name {} @@ -301,9 +302,9 @@ impl ToTokens for ast::Struct { #[cfg(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "none")))] #[automatically_derived] const _: () = { - #wasm_bindgen::__wbindgen_coverage! { #[no_mangle] #[doc(hidden)] + #coverage // `allow_delayed` is whether it's ok to not actually free the `ptr` immediately // if it's still borrowed. pub unsafe extern "C" fn #free_fn(ptr: u32, allow_delayed: u32) { @@ -320,7 +321,6 @@ impl ToTokens for ast::Struct { let _ = <#name as #wasm_bindgen::convert::FromWasmAbi>::from_abi(ptr); } } - } }; #[automatically_derived] @@ -496,13 +496,14 @@ impl ToTokens for ast::StructField { } let wasm_bindgen = &self.wasm_bindgen; + let coverage = coverage(wasm_bindgen); (quote! { #[automatically_derived] const _: () = { - #wasm_bindgen::__wbindgen_coverage! { #[cfg_attr(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "none")), no_mangle)] #[doc(hidden)] + #coverage pub unsafe extern "C" fn #getter(js: u32) -> #wasm_bindgen::convert::WasmRet<<#ty as #wasm_bindgen::convert::IntoWasmAbi>::Abi> { @@ -517,7 +518,6 @@ impl ToTokens for ast::StructField { let val = #val; <#ty as IntoWasmAbi>::into_abi(val).into() } - } }; }) .to_tokens(tokens); @@ -543,9 +543,9 @@ impl ToTokens for ast::StructField { #[cfg(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "none")))] #[automatically_derived] const _: () = { - #wasm_bindgen::__wbindgen_coverage! { #[no_mangle] #[doc(hidden)] + #coverage pub unsafe extern "C" fn #setter( js: u32, #(#args,)* @@ -559,7 +559,6 @@ impl ToTokens for ast::StructField { let val = <#ty as FromWasmAbi>::from_abi(val); (*js).borrow_mut().#rust_name = val; } - } }; }) .to_tokens(tokens); @@ -584,6 +583,7 @@ impl TryToTokens for ast::Export { let name = &self.rust_name; let wasm_bindgen = &self.wasm_bindgen; + let coverage = coverage(wasm_bindgen); let wasm_bindgen_futures = &self.wasm_bindgen_futures; let receiver = match self.method_self { Some(ast::MethodSelf::ByValue) => { @@ -827,12 +827,12 @@ impl TryToTokens for ast::Export { (quote! { #[automatically_derived] const _: () = { - #wasm_bindgen::__wbindgen_coverage! { #(#attrs)* #[cfg_attr( all(target_arch = "wasm32", any(target_os = "unknown", target_os = "none")), export_name = #export_name, )] + #coverage pub unsafe extern "C" fn #generated_name(#(#args),*) -> #wasm_bindgen::convert::WasmRet<#projection::Abi> { const _: () = { #(#checks)* @@ -841,7 +841,6 @@ impl TryToTokens for ast::Export { let #ret = #call; #convert_ret } - } }; }) .to_tokens(into); @@ -1870,21 +1869,21 @@ impl ToTokens for Descriptor<'_, T> { let inner = &self.inner; let attrs = &self.attrs; let wasm_bindgen = &self.wasm_bindgen; + let coverage = coverage(wasm_bindgen); (quote! { #[cfg(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "none")))] #[automatically_derived] const _: () = { - #wasm_bindgen::__wbindgen_coverage! { #(#attrs)* #[no_mangle] #[doc(hidden)] + #coverage pub extern "C" fn #name() { use #wasm_bindgen::describe::*; // See definition of `link_mem_intrinsics` for what this is doing #wasm_bindgen::__rt::link_mem_intrinsics(); #inner } - } }; }) .to_tokens(tokens); @@ -1969,3 +1968,15 @@ fn respan(input: TokenStream, span: &dyn ToTokens) -> TokenStream { } new_tokens.into_iter().collect() } + +#[cfg(feature = "msrv")] +fn coverage(wasm_bindgen: &syn::Path) -> TokenStream { + quote! { + #[cfg_attr(feature = "msrv", #wasm_bindgen::__rt::rustversion::attr(since(2024-12-18), coverage(off)))] + } +} + +#[cfg(not(feature = "msrv"))] +fn coverage(_: &syn::Path) -> TokenStream { + TokenStream::new() +} diff --git a/crates/macro-support/Cargo.toml b/crates/macro-support/Cargo.toml index 75eab654bd5..df6eb157269 100644 --- a/crates/macro-support/Cargo.toml +++ b/crates/macro-support/Cargo.toml @@ -15,6 +15,7 @@ version = "0.2.99" [features] extra-traits = ["syn/extra-traits"] +msrv = ["wasm-bindgen-backend/msrv"] strict-macro = [] [dependencies] diff --git a/crates/macro/Cargo.toml b/crates/macro/Cargo.toml index 1a194c6dcab..a8a254da2fe 100644 --- a/crates/macro/Cargo.toml +++ b/crates/macro/Cargo.toml @@ -17,6 +17,7 @@ version = "0.2.99" proc-macro = true [features] +msrv = ["wasm-bindgen-macro-support/msrv"] strict-macro = ["wasm-bindgen-macro-support/strict-macro"] xxx_debug_only_print_generated_code = [] diff --git a/crates/test-macro/Cargo.toml b/crates/test-macro/Cargo.toml index 9912554d32d..5a36960bd3a 100644 --- a/crates/test-macro/Cargo.toml +++ b/crates/test-macro/Cargo.toml @@ -12,6 +12,9 @@ version = "0.3.49" [lib] proc-macro = true +[features] +msrv = [] + [dependencies] proc-macro2 = "1.0" quote = "1.0" diff --git a/crates/test-macro/src/lib.rs b/crates/test-macro/src/lib.rs index f123b167b0a..bbdf7c455ca 100644 --- a/crates/test-macro/src/lib.rs +++ b/crates/test-macro/src/lib.rs @@ -93,17 +93,22 @@ pub fn wasm_bindgen_test( let ignore_name = if ignore.is_some() { "$" } else { "" }; let wasm_bindgen_path = attributes.wasm_bindgen_path; + #[cfg(feature = "msrv")] + let coverage = quote! { + #[cfg_attr(feature = "msrv", #wasm_bindgen_path::__rt::rustversion::attr(since(2024-12-18), coverage(off)))] + }; + #[cfg(not(feature = "msrv"))] + let coverage = TokenStream::new(); tokens.extend( quote! { const _: () = { - #wasm_bindgen_path::__rt::wasm_bindgen::__wbindgen_coverage! { #[export_name = ::core::concat!("__wbgt_", #ignore_name, ::core::module_path!(), "::", ::core::stringify!(#ident))] #[cfg(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "none")))] + #coverage extern "C" fn __wbgt_test(cx: &#wasm_bindgen_path::__rt::Context) { let test_name = ::core::concat!(::core::module_path!(), "::", ::core::stringify!(#ident)); #test_body } - } }; }, ); diff --git a/crates/test/Cargo.toml b/crates/test/Cargo.toml index 004e990cac7..f743bbd74eb 100644 --- a/crates/test/Cargo.toml +++ b/crates/test/Cargo.toml @@ -11,6 +11,7 @@ version = "0.3.49" [features] default = ["std"] +msrv = ["wasm-bindgen/msrv", "wasm-bindgen-test-macro/msrv"] std = ["wasm-bindgen/std", "js-sys/std", "wasm-bindgen-futures/std"] [dependencies] @@ -20,18 +21,11 @@ wasm-bindgen = { path = '../..', version = '=0.2.99', default-features = false } wasm-bindgen-futures = { path = '../futures', version = '=0.4.49', default-features = false } wasm-bindgen-test-macro = { path = '../test-macro', version = '=0.3.49' } -[target.'cfg(all(target_arch = "wasm32", wasm_bindgen_unstable_test_coverage))'.dependencies] -minicov = "0.3" +[target.'cfg(target_arch = "wasm32")'.dependencies] +unstable-test-coverage = { package = "minicov", version = "0.3", optional = true } -[lints.rust] -unexpected_cfgs = { level = "warn", check-cfg = ['cfg(wasm_bindgen_unstable_test_coverage)'] } - -[lints.clippy] -large_enum_variant = "allow" -new_without_default = "allow" -overly_complex_bool_expr = "allow" -too_many_arguments = "allow" -type_complexity = "allow" +[lints] +workspace = true [lib] test = false diff --git a/crates/test/src/coverage.rs b/crates/test/src/coverage.rs index 2fe38443ccf..4773166b196 100644 --- a/crates/test/src/coverage.rs +++ b/crates/test/src/coverage.rs @@ -1,13 +1,13 @@ use alloc::vec::Vec; use wasm_bindgen::prelude::wasm_bindgen; -#[cfg(wasm_bindgen_unstable_test_coverage)] +#[cfg(feature = "unstable-test-coverage")] #[wasm_bindgen] pub fn __wbgtest_cov_dump() -> Option> { let mut coverage = Vec::new(); // SAFETY: this function is not thread-safe, but our whole test runner is running single-threaded. unsafe { - minicov::capture_coverage(&mut coverage).unwrap(); + unstable_test_coverage::capture_coverage(&mut coverage).unwrap(); } if coverage.is_empty() { console_error!( @@ -18,7 +18,7 @@ pub fn __wbgtest_cov_dump() -> Option> { Some(coverage) } -#[cfg(not(wasm_bindgen_unstable_test_coverage))] +#[cfg(not(feature = "unstable-test-coverage"))] #[wasm_bindgen] pub fn __wbgtest_cov_dump() -> Option> { None diff --git a/guide/src/wasm-bindgen-test/coverage.md b/guide/src/wasm-bindgen-test/coverage.md index 4bd3e6722ce..92e0381d99f 100644 --- a/guide/src/wasm-bindgen-test/coverage.md +++ b/guide/src/wasm-bindgen-test/coverage.md @@ -9,7 +9,7 @@ You can ask the runner to generate coverage data from functions marked as `#[was ## Enabling the feature -To enable this feature, you need to enable `cfg(wasm_bindgen_unstable_test_coverage)`. +To enable this feature, you need to enable the crate feature `unstable-test-coverage` on `wasm-bindgen-test`. Additionally its recommended to use the `msrv` crate feature on `wasm-bindgen-test` as well to disable profiling on internal functions, significantly improving the accuracy of the test coverage results. ## Generating the data @@ -43,7 +43,7 @@ This adapts code taken from the [Rustc book], see that for more examples and gen ```sh # Run the tests: # `--tests` to not run documentation tests, which is currently not supported. -RUSTFLAGS="-Cinstrument-coverage -Zno-profiler-runtime --emit=llvm-ir --cfg=wasm_bindgen_unstable_test_coverage" \ +RUSTFLAGS="-Cinstrument-coverage -Zno-profiler-runtime --emit=llvm-ir" \ CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_RUNNER=wasm-bindgen-test-runner \ cargo +nightly test --tests # Compile to object files: @@ -54,7 +54,7 @@ crate_name=name_of_the_tested_crate_in_snake_case objects=() IFS=$'\n' for file in $( - RUSTFLAGS="-Cinstrument-coverage -Zno-profiler-runtime --emit=llvm-ir --cfg=wasm_bindgen_unstable_test_coverage" \ + RUSTFLAGS="-Cinstrument-coverage -Zno-profiler-runtime --emit=llvm-ir" \ cargo +nightly test --tests --no-run --message-format=json | \ jq -r "select(.reason == \"compiler-artifact\") | (select(.target.kind == [\"test\"]) // select(.target.name == \"$crate_name\")) | .filenames[0]" ) diff --git a/src/closure.rs b/src/closure.rs index d5107c34ec9..d7485e1b0db 100644 --- a/src/closure.rs +++ b/src/closure.rs @@ -331,14 +331,14 @@ where // See crates/cli-support/src/js/closures.rs for a more information // about what's going on here. - #[cfg_attr(wasm_bindgen_unstable_test_coverage, coverage(off))] + #[cfg_attr(feature = "msrv", rustversion::attr(since(2024-12-18), coverage(off)))] extern "C" fn describe() { inform(CLOSURE); T::describe() } #[inline(never)] - #[cfg_attr(wasm_bindgen_unstable_test_coverage, coverage(off))] + #[cfg_attr(feature = "msrv", rustversion::attr(since(2024-12-18), coverage(off)))] unsafe fn breaks_if_inlined(a: usize, b: usize) -> u32 { super::__wbindgen_describe_closure(a as u32, b as u32, describe:: as usize as u32) } @@ -464,7 +464,7 @@ impl WasmDescribe for Closure where T: WasmClosure + ?Sized, { - #[cfg_attr(wasm_bindgen_unstable_test_coverage, coverage(off))] + #[cfg_attr(feature = "msrv", rustversion::attr(since(2024-12-18), coverage(off)))] fn describe() { inform(EXTERNREF); } @@ -566,10 +566,10 @@ macro_rules! doit { where $($var: FromWasmAbi + 'static,)* R: ReturnWasmAbi + 'static, { - #[cfg_attr(wasm_bindgen_unstable_test_coverage, coverage(off))] + #[cfg_attr(feature = "msrv", rustversion::attr(since(2024-12-18), coverage(off)))] fn describe() { #[allow(non_snake_case)] - #[cfg_attr(wasm_bindgen_unstable_test_coverage, coverage(off))] + #[cfg_attr(feature = "msrv", rustversion::attr(since(2024-12-18), coverage(off)))] unsafe extern "C" fn invoke<$($var: FromWasmAbi,)* R: ReturnWasmAbi>( a: usize, b: usize, @@ -626,10 +626,10 @@ macro_rules! doit { where $($var: FromWasmAbi + 'static,)* R: ReturnWasmAbi + 'static, { - #[cfg_attr(wasm_bindgen_unstable_test_coverage, coverage(off))] + #[cfg_attr(feature = "msrv", rustversion::attr(since(2024-12-18), coverage(off)))] fn describe() { #[allow(non_snake_case)] - #[cfg_attr(wasm_bindgen_unstable_test_coverage, coverage(off))] + #[cfg_attr(feature = "msrv", rustversion::attr(since(2024-12-18), coverage(off)))] unsafe extern "C" fn invoke<$($var: FromWasmAbi,)* R: ReturnWasmAbi>( a: usize, b: usize, @@ -769,10 +769,10 @@ where A: RefFromWasmAbi, R: ReturnWasmAbi + 'static, { - #[cfg_attr(wasm_bindgen_unstable_test_coverage, coverage(off))] + #[cfg_attr(feature = "msrv", rustversion::attr(since(2024-12-18), coverage(off)))] fn describe() { #[allow(non_snake_case)] - #[cfg_attr(wasm_bindgen_unstable_test_coverage, coverage(off))] + #[cfg_attr(feature = "msrv", rustversion::attr(since(2024-12-18), coverage(off)))] unsafe extern "C" fn invoke( a: usize, b: usize, @@ -797,7 +797,7 @@ where inform(invoke:: as usize as u32); - #[cfg_attr(wasm_bindgen_unstable_test_coverage, coverage(off))] + #[cfg_attr(feature = "msrv", rustversion::attr(since(2024-12-18), coverage(off)))] unsafe extern "C" fn destroy(a: usize, b: usize) { // See `Fn()` above for why we simply return if a == 0 { @@ -818,10 +818,10 @@ where A: RefFromWasmAbi, R: ReturnWasmAbi + 'static, { - #[cfg_attr(wasm_bindgen_unstable_test_coverage, coverage(off))] + #[cfg_attr(feature = "msrv", rustversion::attr(since(2024-12-18), coverage(off)))] fn describe() { #[allow(non_snake_case)] - #[cfg_attr(wasm_bindgen_unstable_test_coverage, coverage(off))] + #[cfg_attr(feature = "msrv", rustversion::attr(since(2024-12-18), coverage(off)))] unsafe extern "C" fn invoke( a: usize, b: usize, @@ -847,7 +847,7 @@ where inform(invoke:: as usize as u32); - #[cfg_attr(wasm_bindgen_unstable_test_coverage, coverage(off))] + #[cfg_attr(feature = "msrv", rustversion::attr(since(2024-12-18), coverage(off)))] unsafe extern "C" fn destroy(a: usize, b: usize) { // See `Fn()` above for why we simply return if a == 0 { diff --git a/src/convert/closures.rs b/src/convert/closures.rs index 536ca686d0a..dfa19dcc9a6 100644 --- a/src/convert/closures.rs +++ b/src/convert/closures.rs @@ -56,7 +56,7 @@ macro_rules! stack_closures { where $($var: FromWasmAbi,)* R: ReturnWasmAbi { - #[cfg_attr(wasm_bindgen_unstable_test_coverage, coverage(off))] + #[cfg_attr(feature = "msrv", rustversion::attr(since(2024-12-18), coverage(off)))] fn describe() { inform(FUNCTION); inform($invoke::<$($var,)* R> as usize as u32); @@ -113,7 +113,7 @@ macro_rules! stack_closures { where $($var: FromWasmAbi,)* R: ReturnWasmAbi { - #[cfg_attr(wasm_bindgen_unstable_test_coverage, coverage(off))] + #[cfg_attr(feature = "msrv", rustversion::attr(since(2024-12-18), coverage(off)))] fn describe() { inform(FUNCTION); inform($invoke_mut::<$($var,)* R> as usize as u32); @@ -157,7 +157,7 @@ where } #[allow(non_snake_case)] -#[cfg_attr(wasm_bindgen_unstable_test_coverage, coverage(off))] +#[cfg_attr(feature = "msrv", rustversion::attr(since(2024-12-18), coverage(off)))] unsafe extern "C" fn invoke1_ref( a: usize, b: usize, @@ -184,7 +184,7 @@ where A: RefFromWasmAbi, R: ReturnWasmAbi, { - #[cfg_attr(wasm_bindgen_unstable_test_coverage, coverage(off))] + #[cfg_attr(feature = "msrv", rustversion::attr(since(2024-12-18), coverage(off)))] fn describe() { inform(FUNCTION); inform(invoke1_ref:: as usize as u32); @@ -214,7 +214,7 @@ where } #[allow(non_snake_case)] -#[cfg_attr(wasm_bindgen_unstable_test_coverage, coverage(off))] +#[cfg_attr(feature = "msrv", rustversion::attr(since(2024-12-18), coverage(off)))] unsafe extern "C" fn invoke1_mut_ref( a: usize, b: usize, @@ -241,7 +241,7 @@ where A: RefFromWasmAbi, R: ReturnWasmAbi, { - #[cfg_attr(wasm_bindgen_unstable_test_coverage, coverage(off))] + #[cfg_attr(feature = "msrv", rustversion::attr(since(2024-12-18), coverage(off)))] fn describe() { inform(FUNCTION); inform(invoke1_mut_ref:: as usize as u32); diff --git a/src/convert/slices.rs b/src/convert/slices.rs index ac9a462475e..945fe0245fe 100644 --- a/src/convert/slices.rs +++ b/src/convert/slices.rs @@ -127,7 +127,7 @@ macro_rules! vectors { macro_rules! vectors_internal { ($t:ty) => { impl WasmDescribeVector for $t { - #[cfg_attr(wasm_bindgen_unstable_test_coverage, coverage(off))] + #[cfg_attr(feature = "msrv", rustversion::attr(since(2024-12-18), coverage(off)))] fn describe_vector() { inform(VECTOR); <$t>::describe(); @@ -234,7 +234,7 @@ vectors! { } impl WasmDescribeVector for String { - #[cfg_attr(wasm_bindgen_unstable_test_coverage, coverage(off))] + #[cfg_attr(feature = "msrv", rustversion::attr(since(2024-12-18), coverage(off)))] fn describe_vector() { inform(VECTOR); inform(NAMED_EXTERNREF); diff --git a/src/describe.rs b/src/describe.rs index 708e1103651..88906b29274 100644 --- a/src/describe.rs +++ b/src/describe.rs @@ -58,7 +58,7 @@ tys! { } #[inline(always)] // see the wasm-interpreter crate -#[cfg_attr(wasm_bindgen_unstable_test_coverage, coverage(off))] +#[cfg_attr(feature = "msrv", rustversion::attr(since(2024-12-18), coverage(off)))] pub fn inform(a: u32) { unsafe { super::__wbindgen_describe(a) } } @@ -76,7 +76,7 @@ pub trait WasmDescribeVector { macro_rules! simple { ($($t:ident => $d:ident)*) => ($( impl WasmDescribe for $t { - #[cfg_attr(wasm_bindgen_unstable_test_coverage, coverage(off))] + #[cfg_attr(feature = "msrv", rustversion::attr(since(2024-12-18), coverage(off)))] fn describe() { inform($d) } } )*) @@ -116,28 +116,28 @@ cfg_if! { } impl WasmDescribe for *const T { - #[cfg_attr(wasm_bindgen_unstable_test_coverage, coverage(off))] + #[cfg_attr(feature = "msrv", rustversion::attr(since(2024-12-18), coverage(off)))] fn describe() { inform(U32) } } impl WasmDescribe for *mut T { - #[cfg_attr(wasm_bindgen_unstable_test_coverage, coverage(off))] + #[cfg_attr(feature = "msrv", rustversion::attr(since(2024-12-18), coverage(off)))] fn describe() { inform(U32) } } impl WasmDescribe for NonNull { - #[cfg_attr(wasm_bindgen_unstable_test_coverage, coverage(off))] + #[cfg_attr(feature = "msrv", rustversion::attr(since(2024-12-18), coverage(off)))] fn describe() { inform(NONNULL) } } impl WasmDescribe for [T] { - #[cfg_attr(wasm_bindgen_unstable_test_coverage, coverage(off))] + #[cfg_attr(feature = "msrv", rustversion::attr(since(2024-12-18), coverage(off)))] fn describe() { inform(SLICE); T::describe(); @@ -145,7 +145,7 @@ impl WasmDescribe for [T] { } impl WasmDescribe for &T { - #[cfg_attr(wasm_bindgen_unstable_test_coverage, coverage(off))] + #[cfg_attr(feature = "msrv", rustversion::attr(since(2024-12-18), coverage(off)))] fn describe() { inform(REF); T::describe(); @@ -153,7 +153,7 @@ impl WasmDescribe for &T { } impl WasmDescribe for &mut T { - #[cfg_attr(wasm_bindgen_unstable_test_coverage, coverage(off))] + #[cfg_attr(feature = "msrv", rustversion::attr(since(2024-12-18), coverage(off)))] fn describe() { inform(REFMUT); T::describe(); @@ -174,7 +174,7 @@ cfg_if! { } impl WasmDescribeVector for JsValue { - #[cfg_attr(wasm_bindgen_unstable_test_coverage, coverage(off))] + #[cfg_attr(feature = "msrv", rustversion::attr(since(2024-12-18), coverage(off)))] fn describe_vector() { inform(VECTOR); JsValue::describe(); @@ -182,7 +182,7 @@ impl WasmDescribeVector for JsValue { } impl WasmDescribeVector for T { - #[cfg_attr(wasm_bindgen_unstable_test_coverage, coverage(off))] + #[cfg_attr(feature = "msrv", rustversion::attr(since(2024-12-18), coverage(off)))] fn describe_vector() { inform(VECTOR); T::describe(); @@ -190,7 +190,7 @@ impl WasmDescribeVector for T { } impl WasmDescribe for Box<[T]> { - #[cfg_attr(wasm_bindgen_unstable_test_coverage, coverage(off))] + #[cfg_attr(feature = "msrv", rustversion::attr(since(2024-12-18), coverage(off)))] fn describe() { T::describe_vector(); } @@ -200,14 +200,14 @@ impl WasmDescribe for Vec where Box<[T]>: WasmDescribe, { - #[cfg_attr(wasm_bindgen_unstable_test_coverage, coverage(off))] + #[cfg_attr(feature = "msrv", rustversion::attr(since(2024-12-18), coverage(off)))] fn describe() { >::describe(); } } impl WasmDescribe for Option { - #[cfg_attr(wasm_bindgen_unstable_test_coverage, coverage(off))] + #[cfg_attr(feature = "msrv", rustversion::attr(since(2024-12-18), coverage(off)))] fn describe() { inform(OPTIONAL); T::describe(); @@ -215,14 +215,14 @@ impl WasmDescribe for Option { } impl WasmDescribe for () { - #[cfg_attr(wasm_bindgen_unstable_test_coverage, coverage(off))] + #[cfg_attr(feature = "msrv", rustversion::attr(since(2024-12-18), coverage(off)))] fn describe() { inform(UNIT) } } impl> WasmDescribe for Result { - #[cfg_attr(wasm_bindgen_unstable_test_coverage, coverage(off))] + #[cfg_attr(feature = "msrv", rustversion::attr(since(2024-12-18), coverage(off)))] fn describe() { inform(RESULT); T::describe(); @@ -230,14 +230,14 @@ impl> WasmDescribe for Result { } impl WasmDescribe for MaybeUninit { - #[cfg_attr(wasm_bindgen_unstable_test_coverage, coverage(off))] + #[cfg_attr(feature = "msrv", rustversion::attr(since(2024-12-18), coverage(off)))] fn describe() { T::describe(); } } impl WasmDescribe for Clamped { - #[cfg_attr(wasm_bindgen_unstable_test_coverage, coverage(off))] + #[cfg_attr(feature = "msrv", rustversion::attr(since(2024-12-18), coverage(off)))] fn describe() { inform(CLAMPED); T::describe(); @@ -245,7 +245,7 @@ impl WasmDescribe for Clamped { } impl WasmDescribe for JsError { - #[cfg_attr(wasm_bindgen_unstable_test_coverage, coverage(off))] + #[cfg_attr(feature = "msrv", rustversion::attr(since(2024-12-18), coverage(off)))] fn describe() { JsValue::describe(); } diff --git a/src/lib.rs b/src/lib.rs index 0c81941bc39..83ae3f1d5ec 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -22,6 +22,8 @@ //! //! When compiling with Rust v1.78 or later, this feature enables better error messages for invalid methods on structs and enums. //! +//! When compiling with Rust nightly 2024-12-18 or later, this feature disables instrumentation on internal function to improve test coverage results for users. +//! //! ### `std` (default) //! //! Enabling this feature will make the crate depend on the Rust standard library. @@ -47,10 +49,9 @@ //! **Deprecated:** This feature became a no-op in wasm-bindgen v0.2.20 (Sep 7, 2018). #![no_std] -#![cfg_attr(wasm_bindgen_unstable_test_coverage, feature(coverage_attribute))] #![cfg_attr(target_feature = "atomics", feature(thread_local))] #![cfg_attr( - any(target_feature = "atomics", wasm_bindgen_unstable_test_coverage), + target_feature = "atomics", feature(allow_internal_unstable), allow(internal_features) )] diff --git a/src/link.rs b/src/link.rs index 4d9858189ab..937b5e65335 100644 --- a/src/link.rs +++ b/src/link.rs @@ -1,4 +1,4 @@ // see comment in module above this in `link_mem_intrinsics` #[inline(never)] -#[cfg_attr(wasm_bindgen_unstable_test_coverage, coverage(off))] +#[cfg_attr(feature = "msrv", rustversion::attr(since(2024-12-18), coverage(off)))] pub fn link_intrinsics() {} diff --git a/src/rt/mod.rs b/src/rt/mod.rs index c4b104abf4d..2d067b62fce 100644 --- a/src/rt/mod.rs +++ b/src/rt/mod.rs @@ -12,6 +12,9 @@ use alloc::boxed::Box; use alloc::rc::Rc; use once_cell::unsync::Lazy; +#[cfg(feature = "msrv")] +pub use rustversion; + pub extern crate alloc; pub extern crate core; #[cfg(feature = "std")] @@ -155,26 +158,6 @@ macro_rules! __wbindgen_thread_local { }}; } -#[macro_export] -#[doc(hidden)] -#[cfg(not(wasm_bindgen_unstable_test_coverage))] -macro_rules! __wbindgen_coverage { - ($item:item) => { - $item - }; -} - -#[macro_export] -#[doc(hidden)] -#[cfg(wasm_bindgen_unstable_test_coverage)] -#[allow_internal_unstable(coverage_attribute)] -macro_rules! __wbindgen_coverage { - ($item:item) => { - #[coverage(off)] - $item - }; -} - #[inline] pub fn assert_not_null(s: *mut T) { if s.is_null() { @@ -520,7 +503,7 @@ pub unsafe extern "C" fn __wbindgen_free(ptr: *mut u8, size: usize, align: usize /// in the object file and link the intrinsics. /// /// Ideas for how to improve this are most welcome! -#[cfg_attr(wasm_bindgen_unstable_test_coverage, coverage(off))] +#[cfg_attr(feature = "msrv", rustversion::attr(since(2024-12-18), coverage(off)))] pub fn link_mem_intrinsics() { crate::link::link_intrinsics(); }