diff --git a/.cargo/config.toml b/.cargo/config.toml index 11543229379..6440da0591e 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,15 +1,2 @@ [target.'cfg(target_arch = "wasm32")'] runner = 'cargo run -p wasm-bindgen-cli --bin wasm-bindgen-test-runner --' - -[target.'cfg(all())'] -rustflags = [ - "-Adead_code", - "-Anon_upper_case_globals", - "-Aunused_doc_comments", - "-Aclippy::large_enum_variant", - "-Aclippy::missing_safety_doc", - "-Aclippy::new_without_default", - "-Aclippy::overly_complex_bool_expr", - "-Aclippy::too_many_arguments", - "-Aclippy::type_complexity", -] diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 9d3f4ef1e86..b5e9de0542a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -62,6 +62,7 @@ jobs: - run: rustup update --no-self-update stable && rustup default stable - run: rustup target add wasm32-unknown-unknown - run: cargo clippy --no-deps --all-features -p wasm-bindgen-backend -- -D warnings + - run: cargo clippy --no-deps --all-features -p wasm-bindgen -- -D warnings - run: cargo clippy --no-deps --all-features -p wasm-bindgen-cli -- -D warnings - run: cargo clippy --no-deps --all-features -p wasm-bindgen-cli-support -- -D warnings - run: cargo clippy --no-deps --all-features -p example-tests -- -D warnings @@ -89,8 +90,8 @@ jobs: - uses: actions/checkout@v4 - run: rustup update --no-self-update stable && rustup default stable - run: rustup target add wasm32-unknown-unknown - - run: cargo clippy --no-deps --all-features --target wasm32-unknown-unknown -p js-sys -- -D warnings - - run: cargo clippy --no-deps --all-features --target wasm32-unknown-unknown -p web-sys -- -D warnings + - run: cargo clippy --no-deps --all-features --target wasm32-unknown-unknown -p js-sys --all-targets -- -D warnings + - run: cargo clippy --no-deps --all-features --target wasm32-unknown-unknown -p web-sys --all-targets -- -D warnings # Run `cargo clippy` over crates that support `no_std` clippy_no_std: @@ -111,7 +112,7 @@ jobs: name: Clippy `no_std` with `atomics` runs-on: ubuntu-latest env: - CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_RUSTFLAGS: -Ctarget-feature=+atomics,+bulk-memory + RUSTFLAGS: -Ctarget-feature=+atomics,+bulk-memory steps: - uses: actions/checkout@v4 - run: rustup default nightly-2024-07-06 diff --git a/Cargo.toml b/Cargo.toml index e9dba81a41c..873238e5999 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -70,6 +70,20 @@ 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" + +[workspace.lints.clippy] +large_enum_variant = "allow" +new_without_default = "allow" +overly_complex_bool_expr = "allow" +too_many_arguments = "allow" +type_complexity = "allow" + [workspace] exclude = ["crates/msrv"] members = [ diff --git a/crates/backend/Cargo.toml b/crates/backend/Cargo.toml index a19b7812efd..50d744bb681 100644 --- a/crates/backend/Cargo.toml +++ b/crates/backend/Cargo.toml @@ -29,3 +29,6 @@ proc-macro2 = "1.0" quote = '1.0' syn = { version = '2.0', features = ['full'] } wasm-bindgen-shared = { path = "../shared", version = "=0.2.95" } + +[lints] +workspace = true diff --git a/crates/cli-support/Cargo.toml b/crates/cli-support/Cargo.toml index 6db47660790..6eed3b636eb 100644 --- a/crates/cli-support/Cargo.toml +++ b/crates/cli-support/Cargo.toml @@ -29,3 +29,6 @@ wasm-bindgen-shared = { path = "../shared", version = '=0.2.95' } wasm-bindgen-threads-xform = { path = '../threads-xform', version = '=0.2.95' } wasm-bindgen-wasm-conventions = { path = '../wasm-conventions', version = '=0.2.95' } wasm-bindgen-wasm-interpreter = { path = "../wasm-interpreter", version = '=0.2.95' } + +[lints] +workspace = true diff --git a/crates/cli-support/src/lib.rs b/crates/cli-support/src/lib.rs index 6253e89b29a..fb5b4f02549 100755 --- a/crates/cli-support/src/lib.rs +++ b/crates/cli-support/src/lib.rs @@ -812,13 +812,3 @@ where pairs.sort_by_key(|(k, _)| *k); pairs.into_iter() } - -/// Like `sorted_iter`, but produces mutable references to the values -fn sorted_iter_mut(map: &mut HashMap) -> impl Iterator -where - K: Ord, -{ - let mut pairs = map.iter_mut().collect::>(); - pairs.sort_by_key(|(k, _)| *k); - pairs.into_iter() -} diff --git a/crates/cli-support/src/wit/nonstandard.rs b/crates/cli-support/src/wit/nonstandard.rs index e43a49988df..4ff93298281 100644 --- a/crates/cli-support/src/wit/nonstandard.rs +++ b/crates/cli-support/src/wit/nonstandard.rs @@ -244,6 +244,7 @@ pub enum AuxImport { mutable: bool, // whether or not this was a `FnMut` closure dtor: u32, // table element index of the destructor function adapter: AdapterId, // the adapter which translates the types for this closure + #[allow(dead_code)] nargs: usize, }, diff --git a/crates/cli-support/src/wit/standard.rs b/crates/cli-support/src/wit/standard.rs index 7feee8986a2..e34866d2609 100644 --- a/crates/cli-support/src/wit/standard.rs +++ b/crates/cli-support/src/wit/standard.rs @@ -40,6 +40,7 @@ pub enum AdapterKind { instructions: Vec, }, Import { + #[allow(dead_code)] module: String, name: String, kind: AdapterJsImportKind, @@ -139,10 +140,12 @@ pub enum Instruction { /// Pops a typed integer (`u8`, `s16`, etc.) and pushes a plain Wasm `i32` or `i64` equivalent. IntToWasm { input: AdapterType, + #[allow(dead_code)] output: walrus::ValType, }, /// Pops a Wasm `i32` or `i64` and pushes a typed integer (`u8`, `s16`, etc.) equivalent. WasmToInt { + #[allow(dead_code)] input: walrus::ValType, output: AdapterType, }, @@ -166,6 +169,7 @@ pub enum Instruction { OptionWasmToStringEnum { name: String, + #[allow(dead_code)] hole: u32, }, @@ -310,6 +314,7 @@ pub enum Instruction { /// pops ptr/length i32, loads string from cache CachedStringLoad { owned: bool, + #[allow(dead_code)] optional: bool, mem: walrus::MemoryId, free: walrus::FunctionId, diff --git a/crates/cli/Cargo.toml b/crates/cli/Cargo.toml index 4d0891b1136..4ee94630eca 100644 --- a/crates/cli/Cargo.toml +++ b/crates/cli/Cargo.toml @@ -57,3 +57,6 @@ rustls-tls = ["ureq/tls"] # Legacy support openssl = ["dep:native-tls"] vendored-openssl = ["openssl", "native-tls/vendored"] + +[lints] +workspace = true diff --git a/crates/externref-xform/Cargo.toml b/crates/externref-xform/Cargo.toml index ac3467d3f9d..ae4dc7f0a3d 100644 --- a/crates/externref-xform/Cargo.toml +++ b/crates/externref-xform/Cargo.toml @@ -24,6 +24,9 @@ wasmprinter = "0.214" wast = "214" wat = "1.0" +[lints] +workspace = true + [[test]] harness = false name = "all" diff --git a/crates/futures/Cargo.toml b/crates/futures/Cargo.toml index 6e4c8e1994b..d748c4a15f9 100644 --- a/crates/futures/Cargo.toml +++ b/crates/futures/Cargo.toml @@ -38,3 +38,6 @@ version = "=0.3.72" futures-channel-preview = { version = "0.3.0-alpha.18" } futures-lite = { version = "1.11.3", default-features = false } wasm-bindgen-test = { path = '../test' } + +[lints] +workspace = true diff --git a/crates/js-sys/Cargo.toml b/crates/js-sys/Cargo.toml index 16400a046cf..466598c42f7 100644 --- a/crates/js-sys/Cargo.toml +++ b/crates/js-sys/Cargo.toml @@ -34,3 +34,10 @@ web-sys = { path = "../web-sys", features = ["Headers", "Response", "ResponseIni [lints.rust] unexpected_cfgs = { level = "warn", check-cfg = ['cfg(js_sys_unstable_apis)'] } + +[lints.clippy] +large_enum_variant = "allow" +new_without_default = "allow" +overly_complex_bool_expr = "allow" +too_many_arguments = "allow" +type_complexity = "allow" diff --git a/crates/js-sys/tests/wasm/Array.rs b/crates/js-sys/tests/wasm/Array.rs index b2ff7419d5f..53a4bc0e30b 100644 --- a/crates/js-sys/tests/wasm/Array.rs +++ b/crates/js-sys/tests/wasm/Array.rs @@ -13,9 +13,7 @@ macro_rules! js_array { macro_rules! array { ($($e:expr),*) => ({ - let mut __x = Vec::new(); - $(__x.push(JsValue::from($e));)* - __x + vec![$(JsValue::from($e)),*] }) } @@ -38,7 +36,7 @@ fn from_iter() { assert_eq!( to_rust( - &vec![JsValue::from("a"), JsValue::from("b"), JsValue::from("c"),] + &[JsValue::from("a"), JsValue::from("b"), JsValue::from("c")] .iter() .collect() ), @@ -53,7 +51,7 @@ fn from_iter() { ); assert_eq!( - to_rust(&vec![array.clone(),].iter().collect()), + to_rust(&[array.clone()].iter().collect()), vec![JsValue::from(array)], ); @@ -74,7 +72,7 @@ fn from_iter() { let v = vec!["a", "b", "c"]; assert_eq!( - to_rust(&Array::from_iter(v.into_iter().map(|s| JsValue::from(s)))), + to_rust(&Array::from_iter(v.into_iter().map(JsValue::from))), vec!["a", "b", "c"], ); } @@ -290,6 +288,7 @@ fn sort() { } #[wasm_bindgen_test] +#[allow(clippy::cmp_owned)] fn some() { let array = js_array!["z", 1, "y", 2]; assert!(array.some(&mut |e| e == JsValue::from(2))); @@ -553,7 +552,7 @@ fn find_last_index() { fn to_locale_string() { let output = js_array![1, "a", Date::new(&"21 Dec 1997 14:12:00 UTC".into())] .to_locale_string(&"en".into(), &JsValue::undefined()); - assert!(String::from(output).len() > 0); + assert!(!String::from(output).is_empty()); } #[wasm_bindgen_test] @@ -567,7 +566,7 @@ fn for_each() { res } - assert_eq!(sum_indices_of_evens(&js_array![2, 4, 6, 8]), 0 + 1 + 2 + 3); + assert_eq!(sum_indices_of_evens(&js_array![2, 4, 6, 8]), 1 + 2 + 3); assert_eq!(sum_indices_of_evens(&js_array![1, 3, 5, 7]), 0); assert_eq!(sum_indices_of_evens(&js_array![3, 5, 7, 10]), 3); } @@ -578,7 +577,7 @@ fn set_length() { array.set_length(3); assert_eq!( array.iter().collect::>(), - [1.0, 2.0, 3.0].map(|x| JsValue::from_f64(x)) + [1.0, 2.0, 3.0].map(JsValue::from_f64) ); array.set_length(7); @@ -587,7 +586,7 @@ fn set_length() { [1.0, 2.0, 3.0] .iter() .copied() - .map(|x| JsValue::from_f64(x)) + .map(JsValue::from_f64) .chain([JsValue::UNDEFINED; 4]) .collect::>() ); @@ -620,8 +619,7 @@ fn test_array_view_mut_raw( let start: u8 = 10; let len: usize = 32; let end: u8 = start + len as u8; - let mut buffer: Vec = Vec::new(); - buffer.reserve(len); + let mut buffer: Vec = Vec::with_capacity(len); unsafe { let array: ArrT = sut(buffer.as_mut_ptr(), len); populate_array( diff --git a/crates/js-sys/tests/wasm/Boolean.rs b/crates/js-sys/tests/wasm/Boolean.rs index 2021d10a24c..ed1eddf5465 100644 --- a/crates/js-sys/tests/wasm/Boolean.rs +++ b/crates/js-sys/tests/wasm/Boolean.rs @@ -6,13 +6,13 @@ use wasm_bindgen_test::*; #[allow(deprecated)] #[wasm_bindgen_test] fn new_undefined() { - assert_eq!(Boolean::new(&JsValue::undefined()).value_of(), false); + assert!(!Boolean::new(&JsValue::undefined()).value_of()); } #[allow(deprecated)] #[wasm_bindgen_test] fn new_truly() { - assert_eq!(Boolean::new(&JsValue::from("foo")).value_of(), true); + assert!(Boolean::new(&JsValue::from("foo")).value_of()); } #[allow(deprecated)] diff --git a/crates/js-sys/tests/wasm/Intl.rs b/crates/js-sys/tests/wasm/Intl.rs index a58d12abe27..5d4675e8a5f 100644 --- a/crates/js-sys/tests/wasm/Intl.rs +++ b/crates/js-sys/tests/wasm/Intl.rs @@ -118,15 +118,15 @@ fn relative_time_format() { let opts = Object::new(); let c = Intl::RelativeTimeFormat::new(&locales, &opts); - assert!(c.format(1_f64.into(), &"seconds").is_string()); + assert!(c.format(1_f64, "seconds").is_string()); assert!(c - .format_to_parts(1_f64.into(), &"seconds") + .format_to_parts(1_f64, "seconds") .is_instance_of::()); assert!(c.resolved_options().is_instance_of::()); - assert_eq!(c.format(1_f64.into(), &"seconds"), "in 1 second"); - assert_eq!(c.format(1.5.into(), &"seconds"), "in 1.5 seconds"); - assert_eq!(c.format((-1.5).into(), &"seconds"), "1.5 seconds ago"); + assert_eq!(c.format(1_f64, "seconds"), "in 1 second"); + assert_eq!(c.format(1.5, "seconds"), "in 1.5 seconds"); + assert_eq!(c.format(-1.5, "seconds"), "1.5 seconds ago"); let a = Intl::RelativeTimeFormat::supported_locales_of(&locales, &opts); assert!(a.is_instance_of::()); diff --git a/crates/js-sys/tests/wasm/JsString.rs b/crates/js-sys/tests/wasm/JsString.rs index c96046234b8..31aed27f589 100644 --- a/crates/js-sys/tests/wasm/JsString.rs +++ b/crates/js-sys/tests/wasm/JsString.rs @@ -1,3 +1,5 @@ +#![cfg(test)] + use js_sys::*; use wasm_bindgen::prelude::*; use wasm_bindgen_test::*; @@ -69,9 +71,9 @@ fn ends_with() { let js = JsString::from(s); // TODO: remove third parameter once we have optional parameters - assert_eq!(js.ends_with("question.", s.len() as i32), true); - assert_eq!(js.ends_with("to be", s.len() as i32), false); - assert_eq!(js.ends_with("to be", 19), true); + assert!(js.ends_with("question.", s.len() as i32)); + assert!(!js.ends_with("to be", s.len() as i32)); + assert!(js.ends_with("to be", 19)); } #[wasm_bindgen_test] @@ -93,7 +95,7 @@ fn from_char_code() { let codes_u16: Vec = codes .into_iter() .map(|code| { - assert!(code <= u32::from(u16::max_value())); + assert!(code <= u32::from(u16::MAX)); code as u16 }) .collect(); @@ -121,9 +123,9 @@ fn from_code_point() { ); assert_eq!(JsString::from_code_point(&codes).unwrap(), "☃★♲你"); - assert!(!JsString::from_code_point1(0x10FFFF).is_err()); + assert!(JsString::from_code_point1(0x10FFFF).is_ok()); assert!(JsString::from_code_point1(0x110000).is_err()); - assert!(JsString::from_code_point1(u32::max_value()).is_err()); + assert!(JsString::from_code_point1(u32::MAX).is_err()); } #[wasm_bindgen_test] @@ -131,13 +133,13 @@ fn includes() { let str = JsString::from("Blue Whale"); // TODO: remove second parameter once we have optional parameters - assert_eq!(str.includes("Blue", 0), true); - assert_eq!(str.includes("Blute", 0), false); - assert_eq!(str.includes("Whale", 0), true); - assert_eq!(str.includes("Whale", 5), true); - assert_eq!(str.includes("Whale", 7), false); - assert_eq!(str.includes("", 0), true); - assert_eq!(str.includes("", 16), true); + assert!(str.includes("Blue", 0)); + assert!(!str.includes("Blute", 0)); + assert!(str.includes("Whale", 0)); + assert!(str.includes("Whale", 5)); + assert!(!str.includes("Whale", 7)); + assert!(str.includes("", 0)); + assert!(str.includes("", 16)); } #[wasm_bindgen_test] @@ -225,12 +227,12 @@ fn match_all() { .unwrap(); let obj = &result[0]; - assert_eq!(Reflect::get(obj.as_ref(), &"0".into()).unwrap(), "The"); - assert_eq!(Reflect::get(obj.as_ref(), &"1".into()).unwrap(), "he"); + assert_eq!(Reflect::get(obj, &"0".into()).unwrap(), "The"); + assert_eq!(Reflect::get(obj, &"1".into()).unwrap(), "he"); let obj = &result[1]; - assert_eq!(Reflect::get(obj.as_ref(), &"0".into()).unwrap(), "It"); - assert_eq!(Reflect::get(obj.as_ref(), &"1".into()).unwrap(), "t"); + assert_eq!(Reflect::get(obj, &"0".into()).unwrap(), "It"); + assert_eq!(Reflect::get(obj, &"1".into()).unwrap(), "t"); let result: Vec<_> = JsString::from("foo") .match_all(&re) @@ -249,29 +251,20 @@ fn match_all() { let obj = &result[0]; assert_eq!( - Reflect::get(obj.as_ref(), &"0".into()).unwrap(), + Reflect::get(obj, &"0".into()).unwrap(), "see Chapter 3.4.5.1" ); - assert_eq!( - Reflect::get(obj.as_ref(), &"1".into()).unwrap(), - "Chapter 3.4.5.1" - ); - assert_eq!(Reflect::get(obj.as_ref(), &"2".into()).unwrap(), ".1"); - assert_eq!(Reflect::get(obj.as_ref(), &"index".into()).unwrap(), 22); - assert_eq!(Reflect::get(obj.as_ref(), &"input".into()).unwrap(), s); + assert_eq!(Reflect::get(obj, &"1".into()).unwrap(), "Chapter 3.4.5.1"); + assert_eq!(Reflect::get(obj, &"2".into()).unwrap(), ".1"); + assert_eq!(Reflect::get(obj, &"index".into()).unwrap(), 22); + assert_eq!(Reflect::get(obj, &"input".into()).unwrap(), s); let obj = &result[1]; - assert_eq!( - Reflect::get(obj.as_ref(), &"0".into()).unwrap(), - "see Chapter 3.1.4" - ); - assert_eq!( - Reflect::get(obj.as_ref(), &"1".into()).unwrap(), - "Chapter 3.1.4" - ); - assert_eq!(Reflect::get(obj.as_ref(), &"2".into()).unwrap(), ".4"); - assert_eq!(Reflect::get(obj.as_ref(), &"index".into()).unwrap(), 48); - assert_eq!(Reflect::get(obj.as_ref(), &"input".into()).unwrap(), s); + assert_eq!(Reflect::get(obj, &"0".into()).unwrap(), "see Chapter 3.1.4"); + assert_eq!(Reflect::get(obj, &"1".into()).unwrap(), "Chapter 3.1.4"); + assert_eq!(Reflect::get(obj, &"2".into()).unwrap(), ".4"); + assert_eq!(Reflect::get(obj, &"index".into()).unwrap(), 48); + assert_eq!(Reflect::get(obj, &"input".into()).unwrap(), s); } #[wasm_bindgen_test] @@ -512,8 +505,8 @@ fn to_locale_lower_case() { let js = JsString::from("Mozilla"); assert_eq!(js.to_locale_lower_case(None), "mozilla"); let s = JsString::from("\u{0130}"); - assert_eq!(s.to_locale_lower_case(Some("tr".into())), "i"); - assert_ne!(s.to_locale_lower_case(Some("en-US".into())), "i"); + assert_eq!(s.to_locale_lower_case(Some("tr")), "i"); + assert_ne!(s.to_locale_lower_case(Some("en-US")), "i"); } #[wasm_bindgen_test] @@ -521,8 +514,8 @@ fn to_locale_upper_case() { let js = JsString::from("mozilla"); assert_eq!(js.to_locale_upper_case(None), "MOZILLA"); let s = JsString::from("i\u{0307}"); - assert_eq!(s.to_locale_upper_case(Some("lt".into())), "I"); - assert_ne!(s.to_locale_upper_case(Some("en-US".into())), "I"); + assert_eq!(s.to_locale_upper_case(Some("lt")), "I"); + assert_ne!(s.to_locale_upper_case(Some("en-US")), "I"); } #[wasm_bindgen_test] @@ -573,7 +566,7 @@ fn value_of() { fn raw() { let call_site = Object::new(); let raw = Array::of3(&"foo".into(), &"bar".into(), &"123".into()); - Reflect::set(&call_site.as_ref(), &"raw".into(), &raw.into()).unwrap(); + Reflect::set(call_site.as_ref(), &"raw".into(), &raw.into()).unwrap(); assert_eq!( JsString::raw_2(&call_site, "5", "JavaScript").unwrap(), "foo5barJavaScript123" diff --git a/crates/js-sys/tests/wasm/Map.rs b/crates/js-sys/tests/wasm/Map.rs index 8223c6e709e..3bdff9b504e 100644 --- a/crates/js-sys/tests/wasm/Map.rs +++ b/crates/js-sys/tests/wasm/Map.rs @@ -19,8 +19,8 @@ fn delete() { let map = Map::new(); map.set(&"foo".into(), &"bar".into()); assert_eq!(map.size(), 1); - assert_eq!(map.delete(&"foo".into()), true); - assert_eq!(map.delete(&"bar".into()), false); + assert!(map.delete(&"foo".into())); + assert!(!map.delete(&"bar".into())); assert_eq!(map.size(), 0); } @@ -63,8 +63,8 @@ fn get() { fn has() { let map = Map::new(); map.set(&"foo".into(), &"bar".into()); - assert_eq!(map.has(&"foo".into()), true); - assert_eq!(map.has(&"bar".into()), false); + assert!(map.has(&"foo".into())); + assert!(!map.has(&"bar".into())); } #[wasm_bindgen_test] @@ -76,8 +76,8 @@ fn new() { fn set() { let map = Map::new(); let new = map.set(&"foo".into(), &"bar".into()); - assert_eq!(map.has(&"foo".into()), true); - assert_eq!(new.has(&"foo".into()), true); + assert!(map.has(&"foo".into())); + assert!(new.has(&"foo".into())); } #[wasm_bindgen_test] diff --git a/crates/js-sys/tests/wasm/MapIterator.rs b/crates/js-sys/tests/wasm/MapIterator.rs index 6a6eec391fb..6b64c0861bd 100644 --- a/crates/js-sys/tests/wasm/MapIterator.rs +++ b/crates/js-sys/tests/wasm/MapIterator.rs @@ -9,7 +9,7 @@ fn entries() { let entries = map.entries(); let next = entries.next().unwrap(); - assert_eq!(next.done(), false); + assert!(!next.done()); assert!(next.value().is_object()); assert_eq!(Reflect::get(&next.value(), &0.into()).unwrap(), "uno"); assert_eq!(Reflect::get(&next.value(), &1.into()).unwrap(), 1); @@ -27,7 +27,7 @@ fn keys() { let keys = map.keys(); let next = keys.next().unwrap(); - assert_eq!(next.done(), false); + assert!(!next.done()); assert_eq!(next.value(), "uno"); let next = keys.next().unwrap(); @@ -43,7 +43,7 @@ fn values() { let values = map.values(); let next = values.next().unwrap(); - assert_eq!(next.done(), false); + assert!(!next.done()); assert_eq!(next.value(), 1); let next = values.next().unwrap(); diff --git a/crates/js-sys/tests/wasm/Math.rs b/crates/js-sys/tests/wasm/Math.rs index 95b70b5c00d..e1e97ee0620 100644 --- a/crates/js-sys/tests/wasm/Math.rs +++ b/crates/js-sys/tests/wasm/Math.rs @@ -1,5 +1,4 @@ -use std::f64::consts::PI; -use std::f64::{NAN, NEG_INFINITY}; +use std::f64::consts::{FRAC_PI_3, LN_2, LOG10_2, PI}; use js_sys::*; use wasm_bindgen_test::*; @@ -30,7 +29,7 @@ fn abs() { #[wasm_bindgen_test] fn acos() { assert_eq!(Math::acos(-1.), PI); - assert_eq!(Math::acos(0.5), 1.0471975511965979); + assert_eq!(Math::acos(0.5), FRAC_PI_3); assert!(Math::acos(2.).is_nan()); } @@ -127,9 +126,9 @@ fn floor() { #[wasm_bindgen_test] fn fround() { assert!(Math::fround(5.5) == 5.5); - assert!(Math::fround(5.05) == 5.050000190734863); + assert!(Math::fround(5.05) == 5.05); assert!(Math::fround(5.) == 5.); - assert!(Math::fround(-5.05) == -5.050000190734863); + assert!(Math::fround(-5.05) == -5.05); } #[wasm_bindgen_test] @@ -157,14 +156,14 @@ fn log() { fn log10() { assert_eq!(Math::log10(100000.), 5.); assert_eq!(Math::log10(1.), 0.); - assert_eq!(Math::log10(2.), 0.3010299956639812); + assert_eq!(Math::log10(2.), LOG10_2); } #[wasm_bindgen_test] fn log1p() { - assert_eq!(Math::log1p(1.), 0.6931471805599453); + assert_eq!(Math::log1p(1.), LN_2); assert_eq!(Math::log1p(0.), 0.); - assert_eq!(Math::log1p(-1.), NEG_INFINITY); + assert_eq!(Math::log1p(-1.), f64::NEG_INFINITY); assert!(Math::log1p(-2.).is_nan()); } @@ -173,7 +172,7 @@ fn log2() { assert_eq!(Math::log2(3.), 1.584962500721156); assert_eq!(Math::log2(2.), 1.); assert_eq!(Math::log2(1.), 0.); - assert_eq!(Math::log2(0.), NEG_INFINITY); + assert_eq!(Math::log2(0.), f64::NEG_INFINITY); } #[wasm_bindgen_test] @@ -222,7 +221,7 @@ fn sign() { assert_eq!(Math::sign(-3.), -1.); assert_eq!(Math::sign(2.3), 1.); assert_eq!(Math::sign(0.), 0.); - assert!(Math::sign(NAN).is_nan()); + assert!(Math::sign(f64::NAN).is_nan()); } #[wasm_bindgen_test] diff --git a/crates/js-sys/tests/wasm/Number.rs b/crates/js-sys/tests/wasm/Number.rs index 31f3f565fe8..55199bfbb83 100644 --- a/crates/js-sys/tests/wasm/Number.rs +++ b/crates/js-sys/tests/wasm/Number.rs @@ -1,7 +1,4 @@ -use std::{ - convert::TryFrom, - f64::{INFINITY, NAN}, -}; +use std::convert::TryFrom; use js_sys::*; use wasm_bindgen::prelude::*; @@ -23,8 +20,8 @@ fn is_finite() { assert!(Number::is_finite(&42.into())); assert!(Number::is_finite(&42.1.into())); assert!(!Number::is_finite(&"42".into())); - assert!(!Number::is_finite(&NAN.into())); - assert!(!Number::is_finite(&INFINITY.into())); + assert!(!Number::is_finite(&f64::NAN.into())); + assert!(!Number::is_finite(&f64::INFINITY.into())); } #[wasm_bindgen_test] @@ -35,7 +32,7 @@ fn is_integer() { #[wasm_bindgen_test] fn is_nan() { - assert!(Number::is_nan(&NAN.into())); + assert!(Number::is_nan(&f64::NAN.into())); assert!(!Number::is_nan(&JsValue::TRUE)); assert!(!Number::is_nan(&JsValue::NULL)); @@ -53,16 +50,13 @@ fn is_nan() { #[wasm_bindgen_test] fn is_safe_integer() { - assert_eq!(Number::is_safe_integer(&42.into()), true); - assert_eq!( - Number::is_safe_integer(&(Math::pow(2., 53.) - 1.).into()), - true - ); - assert_eq!(Number::is_safe_integer(&Math::pow(2., 53.).into()), false); - assert_eq!(Number::is_safe_integer(&"42".into()), false); - assert_eq!(Number::is_safe_integer(&42.1.into()), false); - assert_eq!(Number::is_safe_integer(&NAN.into()), false); - assert_eq!(Number::is_safe_integer(&INFINITY.into()), false); + assert!(Number::is_safe_integer(&42.into())); + assert!(Number::is_safe_integer(&(Math::pow(2., 53.) - 1.).into())); + assert!(!Number::is_safe_integer(&Math::pow(2., 53.).into())); + assert!(!Number::is_safe_integer(&"42".into())); + assert!(!Number::is_safe_integer(&42.1.into())); + assert!(!Number::is_safe_integer(&f64::NAN.into())); + assert!(!Number::is_safe_integer(&f64::INFINITY.into())); } #[allow(deprecated)] diff --git a/crates/js-sys/tests/wasm/Object.rs b/crates/js-sys/tests/wasm/Object.rs index 460fe0f77ce..7388c4e1046 100644 --- a/crates/js-sys/tests/wasm/Object.rs +++ b/crates/js-sys/tests/wasm/Object.rs @@ -1,5 +1,6 @@ +#![cfg(test)] + use js_sys::*; -use std::f64::NAN; use wasm_bindgen::prelude::*; use wasm_bindgen_test::*; @@ -213,7 +214,10 @@ fn is() { assert!(Object::is(&JsValue::FALSE, &JsValue::FALSE)); assert!(Object::is(&"foo".into(), &"foo".into())); assert!(Object::is(&JsValue::from(42), &JsValue::from(42))); - assert!(Object::is(&JsValue::from(NAN), &JsValue::from(NAN))); + assert!(Object::is( + &JsValue::from(f64::NAN), + &JsValue::from(f64::NAN) + )); let another_object = JsValue::from(Object::new()); assert!(!Object::is(&object, &another_object)); @@ -296,7 +300,10 @@ fn value_of() { let a = JsValue::from(foo_42()); let b = JsValue::from(foo_42()); let a2 = JsValue::from(Object::from(a.clone()).value_of()); - assert_eq!(a, a); + #[allow(clippy::eq_op)] + { + assert_eq!(a, a); + } assert_eq!(a, a2); assert_ne!(a, b); assert_ne!(a2, b); diff --git a/crates/js-sys/tests/wasm/Reflect.rs b/crates/js-sys/tests/wasm/Reflect.rs index d50629ec12b..5936b013d9e 100644 --- a/crates/js-sys/tests/wasm/Reflect.rs +++ b/crates/js-sys/tests/wasm/Reflect.rs @@ -1,3 +1,5 @@ +#![allow(deprecated)] + use js_sys::*; use wasm_bindgen::prelude::*; use wasm_bindgen_test::*; diff --git a/crates/js-sys/tests/wasm/Set.rs b/crates/js-sys/tests/wasm/Set.rs index 94905bef1ff..3346de472d0 100644 --- a/crates/js-sys/tests/wasm/Set.rs +++ b/crates/js-sys/tests/wasm/Set.rs @@ -5,7 +5,7 @@ use wasm_bindgen_test::*; fn set2vec(s: &Set) -> Vec { let mut result = Vec::new(); s.for_each(&mut |x, _, _| result.push(x)); - return result; + result } #[wasm_bindgen_test] diff --git a/crates/js-sys/tests/wasm/Symbol.rs b/crates/js-sys/tests/wasm/Symbol.rs index 0f1e3d0f63d..0f7a8868309 100644 --- a/crates/js-sys/tests/wasm/Symbol.rs +++ b/crates/js-sys/tests/wasm/Symbol.rs @@ -1,3 +1,5 @@ +#![cfg(test)] + use js_sys::*; use wasm_bindgen::prelude::*; use wasm_bindgen_futures::JsFuture; @@ -85,8 +87,11 @@ fn to_string_tag() { fn for_() { let foo = JsValue::from(Symbol::for_("foo")); let bar = JsValue::from(Symbol::for_("bar")); - assert_eq!(foo, foo); - assert_eq!(bar, bar); + #[allow(clippy::eq_op)] + { + assert_eq!(foo, foo); + assert_eq!(bar, bar); + } assert_ne!(foo, bar); assert_ne!(bar, foo); diff --git a/crates/js-sys/tests/wasm/WebAssembly.rs b/crates/js-sys/tests/wasm/WebAssembly.rs index 4a236548175..ed28d764137 100644 --- a/crates/js-sys/tests/wasm/WebAssembly.rs +++ b/crates/js-sys/tests/wasm/WebAssembly.rs @@ -101,7 +101,7 @@ fn module_imports() { #[wasm_bindgen_test] fn table_inheritance() { - let table = WebAssembly::Table::new(&get_table_object().into()).unwrap(); + let table = WebAssembly::Table::new(&get_table_object()).unwrap(); assert!(table.is_instance_of::()); assert!(table.is_instance_of::()); @@ -118,7 +118,7 @@ fn table_error() { #[wasm_bindgen_test] fn table() { - let table = WebAssembly::Table::new(&get_table_object().into()).unwrap(); + let table = WebAssembly::Table::new(&get_table_object()).unwrap(); assert_eq!(table.length(), 1); assert!(table.get(0).is_ok()); diff --git a/crates/js-sys/tests/wasm/global_fns.rs b/crates/js-sys/tests/wasm/global_fns.rs index 1a2c5e1c573..b15344bdf4e 100644 --- a/crates/js-sys/tests/wasm/global_fns.rs +++ b/crates/js-sys/tests/wasm/global_fns.rs @@ -1,12 +1,9 @@ -use std::f64::{INFINITY, NAN}; - use js_sys::*; use wasm_bindgen_test::*; #[wasm_bindgen_test] fn test_decode_uri() { let x = decode_uri("https://mozilla.org/?x=%D1%88%D0%B5%D0%BB%D0%BB%D1%8B") - .ok() .expect("should decode URI OK"); assert_eq!(String::from(x), "https://mozilla.org/?x=шеллы"); @@ -15,9 +12,7 @@ fn test_decode_uri() { #[wasm_bindgen_test] fn test_decode_uri_component() { - let x = decode_uri_component("%3Fx%3Dtest") - .ok() - .expect("should decode URI OK"); + let x = decode_uri_component("%3Fx%3Dtest").expect("should decode URI OK"); assert_eq!(String::from(x), "?x=test"); assert!(decode_uri_component("%E0%A4%A").is_err()); @@ -37,12 +32,10 @@ fn test_encode_uri_component() { #[wasm_bindgen_test] fn test_eval() { - let x = eval("42").ok().expect("should eval OK"); + let x = eval("42").expect("should eval OK"); assert_eq!(x.as_f64().unwrap(), 42.0); - let err = eval("(function () { throw 42; }())") - .err() - .expect("eval should throw"); + let err = eval("(function () { throw 42; }())").expect_err("eval should throw"); assert_eq!(err.as_f64().unwrap(), 42.0); } @@ -51,8 +44,8 @@ fn test_is_finite() { assert!(is_finite(&42.into())); assert!(is_finite(&42.1.into())); assert!(is_finite(&"42".into())); - assert!(!is_finite(&NAN.into())); - assert!(!is_finite(&INFINITY.into())); + assert!(!is_finite(&f64::NAN.into())); + assert!(!is_finite(&f64::INFINITY.into())); } #[wasm_bindgen_test] diff --git a/crates/macro-support/Cargo.toml b/crates/macro-support/Cargo.toml index 61ce9c2b9fc..f9f024ac8ee 100644 --- a/crates/macro-support/Cargo.toml +++ b/crates/macro-support/Cargo.toml @@ -28,3 +28,6 @@ quote = '1.0' syn = { version = '2.0', features = ['visit', 'visit-mut', 'full'] } wasm-bindgen-backend = { path = "../backend", version = "=0.2.95", default-features = false } wasm-bindgen-shared = { path = "../shared", version = "=0.2.95" } + +[lints] +workspace = true diff --git a/crates/macro/Cargo.toml b/crates/macro/Cargo.toml index d2b699ff2aa..bf6c7690a5e 100644 --- a/crates/macro/Cargo.toml +++ b/crates/macro/Cargo.toml @@ -35,3 +35,6 @@ trybuild = "1.0" wasm-bindgen = { path = "../.." } wasm-bindgen-futures = { path = "../futures" } web-sys = { path = "../web-sys", features = ["Worker"] } + +[lints] +workspace = true diff --git a/crates/multi-value-xform/Cargo.toml b/crates/multi-value-xform/Cargo.toml index 50a5098eb03..05d176cf6b9 100644 --- a/crates/multi-value-xform/Cargo.toml +++ b/crates/multi-value-xform/Cargo.toml @@ -24,6 +24,9 @@ wasmprinter = "0.214" wast = "214" wat = "1.0" +[lints] +workspace = true + [[test]] harness = false name = "all" diff --git a/crates/shared/Cargo.toml b/crates/shared/Cargo.toml index 2e5fe6b1a78..3cc734b74a8 100644 --- a/crates/shared/Cargo.toml +++ b/crates/shared/Cargo.toml @@ -18,3 +18,6 @@ version = "0.2.95" # graph, pretend we link a native library so that `cargo` will provide better # error messages than the esoteric linker errors we would otherwise trigger. links = "wasm_bindgen" + +[lints] +workspace = true diff --git a/crates/test-macro/Cargo.toml b/crates/test-macro/Cargo.toml index d43aafe11d8..1d0ecab4815 100644 --- a/crates/test-macro/Cargo.toml +++ b/crates/test-macro/Cargo.toml @@ -29,3 +29,6 @@ syn = { version = "2.0", default-features = false, features = [ tokio = { version = "1", features = ["macros", "rt-multi-thread"] } trybuild = "1.0" wasm-bindgen-test = { path = "../test" } + +[lints] +workspace = true diff --git a/crates/test/Cargo.toml b/crates/test/Cargo.toml index a51d8ff68ab..fccd1b96f61 100644 --- a/crates/test/Cargo.toml +++ b/crates/test/Cargo.toml @@ -29,5 +29,12 @@ wasm-bindgen-test-macro = { path = '../test-macro', version = '=0.3.45', feature [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" + [lib] test = false diff --git a/crates/test/src/rt/mod.rs b/crates/test/src/rt/mod.rs index 5489e19bf8f..2d508c6e1dc 100644 --- a/crates/test/src/rt/mod.rs +++ b/crates/test/src/rt/mod.rs @@ -272,7 +272,6 @@ impl Context { /// coordinated, and this will collect output and results for all executed /// tests. #[wasm_bindgen(constructor)] - #[allow(clippy::new_without_default)] pub fn new() -> Context { fn panic_handling(mut message: String) { let should_panic = CURRENT_OUTPUT.with(|output| { diff --git a/crates/threads-xform/Cargo.toml b/crates/threads-xform/Cargo.toml index 0658efb8227..b65754be09d 100644 --- a/crates/threads-xform/Cargo.toml +++ b/crates/threads-xform/Cargo.toml @@ -24,6 +24,9 @@ wasmparser = "0.214" wasmprinter = "0.214" wat = "1.0" +[lints] +workspace = true + [[test]] harness = false name = "all" diff --git a/crates/typescript-tests/Cargo.toml b/crates/typescript-tests/Cargo.toml index 90d394bc285..1bd464ffb71 100644 --- a/crates/typescript-tests/Cargo.toml +++ b/crates/typescript-tests/Cargo.toml @@ -15,3 +15,6 @@ web-sys = { path = '../web-sys', features = ['HtmlElement', 'Node', 'Document'] [lib] crate-type = ['cdylib'] + +[lints] +workspace = true diff --git a/crates/typescript-tests/src/custom_section.rs b/crates/typescript-tests/src/custom_section.rs index 68c748c89c7..4ed757c35ca 100644 --- a/crates/typescript-tests/src/custom_section.rs +++ b/crates/typescript-tests/src/custom_section.rs @@ -8,6 +8,7 @@ const TS_INTERFACE_EXPORT: &'static str = r" #[wasm_bindgen(typescript_custom_section)] const TS_INTERFACE_EXPORT1: &'static str = include_str!("./custom_section_types.d.ts"); +#[allow(dead_code)] const TS_INTERFACE_EXPORT2: &str = "interface Person2 { height: number; }"; #[wasm_bindgen(typescript_custom_section)] const _: &str = TS_INTERFACE_EXPORT2; diff --git a/crates/wasm-conventions/Cargo.toml b/crates/wasm-conventions/Cargo.toml index f721e22506d..66ec85f8e34 100644 --- a/crates/wasm-conventions/Cargo.toml +++ b/crates/wasm-conventions/Cargo.toml @@ -18,3 +18,6 @@ walrus = "0.23" anyhow = "1.0" log = "0.4" wasmparser = "0.212" + +[lints] +workspace = true diff --git a/crates/wasm-interpreter/Cargo.toml b/crates/wasm-interpreter/Cargo.toml index abffcf6da5b..8c5f1b1d9dd 100644 --- a/crates/wasm-interpreter/Cargo.toml +++ b/crates/wasm-interpreter/Cargo.toml @@ -22,3 +22,6 @@ wasm-bindgen-wasm-conventions = { path = "../wasm-conventions", version = "0.2.9 [dev-dependencies] tempfile = "3" wat = "1.0" + +[lints] +workspace = true diff --git a/crates/web-sys/Cargo.toml b/crates/web-sys/Cargo.toml index e3ddae0c305..b5dea9e5a0b 100644 --- a/crates/web-sys/Cargo.toml +++ b/crates/web-sys/Cargo.toml @@ -34,6 +34,13 @@ wasm-bindgen-test = { path = '../test' } [lints.rust] unexpected_cfgs = { level = "warn", check-cfg = ['cfg(web_sys_unstable_apis)'] } +[lints.clippy] +large_enum_variant = "allow" +new_without_default = "allow" +overly_complex_bool_expr = "allow" +too_many_arguments = "allow" +type_complexity = "allow" + # This list is auto-generated by the wasm-bindgen-webidl program [features] default = ["std"] diff --git a/crates/web-sys/tests/wasm/button_element.rs b/crates/web-sys/tests/wasm/button_element.rs index 5a1296a0899..f46051b3ceb 100644 --- a/crates/web-sys/tests/wasm/button_element.rs +++ b/crates/web-sys/tests/wasm/button_element.rs @@ -9,6 +9,7 @@ extern "C" { } #[wasm_bindgen_test] +#[allow(deprecated)] fn test_button_element() { let element = new_button(); let location = web_sys::window().unwrap().location().href().unwrap(); @@ -21,8 +22,9 @@ fn test_button_element() { assert!(element.disabled(), "Should be disabled"); match element.form() { - None => assert!(true, "Shouldn't have a form"), - _ => assert!(false, "Shouldn't have a form"), + // Shouldn't have a form + None => (), + _ => unreachable!("Shouldn't have a form"), }; assert_eq!( @@ -73,17 +75,17 @@ fn test_button_element() { element.set_value("value1"); assert_eq!(element.value(), "value1", "Should have a value"); - assert_eq!(element.will_validate(), false, "Shouldn't validate"); + assert!(!element.will_validate(), "Shouldn't validate"); assert_eq!( element.validation_message().unwrap(), "", "Shouldn't have a value" ); - assert_eq!(element.check_validity(), true, "Should be valid"); - assert_eq!(element.report_validity(), true, "Should be valid"); + assert!(element.check_validity(), "Should be valid"); + assert!(element.report_validity(), "Should be valid"); element.set_custom_validity("Boop"); // Method exists but doesn't impact validity - assert_eq!(element.check_validity(), true, "Should be valid"); - assert_eq!(element.report_validity(), true, "Should be valid"); + assert!(element.check_validity(), "Should be valid"); + assert!(element.report_validity(), "Should be valid"); assert_eq!( element.labels().length(), @@ -102,9 +104,10 @@ fn test_button_element_in_form() { form.append_child(&button).unwrap(); match button.form() { - None => assert!(false, "Should have a form"), + // Should have a form + None => (), Some(form) => { - assert!(true, "Should have a form"); + // Should have a form assert_eq!( form.name(), "test-form", diff --git a/crates/web-sys/tests/wasm/element.rs b/crates/web-sys/tests/wasm/element.rs index ba4053627a1..8cc1cefc706 100644 --- a/crates/web-sys/tests/wasm/element.rs +++ b/crates/web-sys/tests/wasm/element.rs @@ -14,7 +14,10 @@ fn element() { */ let element = new_div(); - assert_eq!(element, element); + #[allow(clippy::eq_op)] + { + assert_eq!(element, element); + } assert_eq!(element.prefix(), None, "Shouldn't have a prefix"); assert_eq!(element.local_name(), "div", "Should have a div local name"); @@ -24,17 +27,11 @@ fn element() { assert_eq!(element.id(), "beep", "Should have an id of 'beep'"); // must_use is set on this result? - assert_eq!( - element.set_attribute("id", "beep").unwrap(), - (), - "Should set id" - ); + // Should set id + let _: () = element.set_attribute("id", "beep").unwrap(); assert!(element.has_attribute("id"), "Should now have an id"); - assert_eq!( - element.remove_attribute("id").unwrap(), - (), - "Should return nothing if removed" - ); + // Should return nothing if removed + let _: () = element.remove_attribute("id").unwrap(); assert_eq!(element.class_name(), "", "Shouldn't have a class name"); element.set_class_name("test thing"); @@ -48,11 +45,8 @@ fn element() { "test thing", "Should have a class name" ); - assert_eq!( - element.remove_attribute("class").unwrap(), - (), - "Should return nothing if removed" - ); + // Should return nothing if removed + let _: () = element.remove_attribute("class").unwrap(); /* Tests needed for: get_attribute_ns */ @@ -79,71 +73,52 @@ fn element() { assert!(!element.has_attribute("disabled"), "Should not be disabled"); assert!(!element.has_attribute("title"), "Should not have a title"); - assert_eq!( - element.set_attribute("title", "boop").unwrap(), - (), - "Should return nothing if set correctly" - ); + // Should return nothing if set correctly + let _: () = element.set_attribute("title", "boop").unwrap(); assert!(element.has_attribute("title"), "Should have a title"); assert_eq!( element.get_attribute("title").unwrap(), "boop", "Title should be 'boop'" ); - assert_eq!( - element.remove_attribute("title").unwrap(), - (), - "Should return nothing if removed" - ); + // Should return nothing if removed + let _: () = element.remove_attribute("title").unwrap(); assert!(!element.has_attribute("title"), "Should not have a title"); /* Tests needed for: set_attribute_ns */ assert!(!element.has_attributes(), "Should not have any attributes"); - assert_eq!( - element.set_attribute("title", "boop").unwrap(), - (), - "Should return nothing if set correctly" - ); + // Should return nothing if set correctly + let _: () = element.set_attribute("title", "boop").unwrap(); assert!(element.has_attributes(), "Should have attributes"); - assert_eq!( - element.remove_attribute("title").unwrap(), - (), - "Should return nothing if removed" - ); + // Should return nothing if removed + let _: () = element.remove_attribute("title").unwrap(); /* Tests needed for: remove_attribute_ns has_attribute_ns closest */ - assert_eq!( - element.matches(".this-is-a-thing").unwrap(), - false, + assert!( + !element.matches(".this-is-a-thing").unwrap(), "Should not match selector" ); - assert_eq!( - element.webkit_matches_selector(".this-is-a-thing").unwrap(), - false, + assert!( + !element.webkit_matches_selector(".this-is-a-thing").unwrap(), "Should not match selector" ); element.set_class_name("this-is-a-thing"); - assert_eq!( + assert!( element.matches(".this-is-a-thing").unwrap(), - true, "Should match selector" ); - assert_eq!( + assert!( element.webkit_matches_selector(".this-is-a-thing").unwrap(), - true, "Should match selector" ); - assert_eq!( - element.remove_attribute("class").unwrap(), - (), - "Should return nothing if removed" - ); + // Should return nothing if removed + let _: () = element.remove_attribute("class").unwrap(); /* Tests needed for: insert_adjacent_element diff --git a/crates/web-sys/tests/wasm/head_element.rs b/crates/web-sys/tests/wasm/head_element.rs index 4b827335727..7bd2c15eedc 100644 --- a/crates/web-sys/tests/wasm/head_element.rs +++ b/crates/web-sys/tests/wasm/head_element.rs @@ -10,5 +10,5 @@ extern "C" { #[wasm_bindgen_test] fn test_head_element() { let _element = new_head(); - assert!(true, "Head doesn't have an interface"); + // Head doesn't have an interface } diff --git a/crates/web-sys/tests/wasm/headers.rs b/crates/web-sys/tests/wasm/headers.rs index f7cb4f7d7e8..8433ee50e05 100644 --- a/crates/web-sys/tests/wasm/headers.rs +++ b/crates/web-sys/tests/wasm/headers.rs @@ -1,4 +1,4 @@ -use js_sys::{Array, Function, JsString}; +use js_sys::Array; use wasm_bindgen::prelude::*; use wasm_bindgen_test::*; use web_sys::Headers; @@ -65,6 +65,6 @@ fn headers_for_each() { } count += 1; }) as Box); - let res = new_headers_2().for_each(&cb.as_ref().unchecked_ref()); + let res = new_headers_2().for_each(cb.as_ref().unchecked_ref()); assert!(res.is_ok()); } diff --git a/crates/web-sys/tests/wasm/hr_element.rs b/crates/web-sys/tests/wasm/hr_element.rs index fe63c14045a..d707b5a5e58 100644 --- a/crates/web-sys/tests/wasm/hr_element.rs +++ b/crates/web-sys/tests/wasm/hr_element.rs @@ -20,5 +20,5 @@ fn test_hr_element() { assert_eq!(hr.width(), "256"); hr.set_no_shade(true); - assert_eq!(hr.no_shade(), true); + assert!(hr.no_shade()); } diff --git a/crates/web-sys/tests/wasm/html_element.rs b/crates/web-sys/tests/wasm/html_element.rs index 4f5173ed02e..710699e76fe 100644 --- a/crates/web-sys/tests/wasm/html_element.rs +++ b/crates/web-sys/tests/wasm/html_element.rs @@ -93,10 +93,10 @@ fn test_html_element() { assert_eq!(element.tab_index(), 1, "Should be tab_index"); // TODO add a focus handler here - assert_eq!(element.focus().unwrap(), (), "No result"); + let _: () = element.focus().unwrap(); // TODO add a blur handler here - assert_eq!(element.blur().unwrap(), (), "No result"); + let _: () = element.blur().unwrap(); assert_eq!(element.access_key(), "", "Shouldn't have a access_key"); element.set_access_key("a"); @@ -128,8 +128,9 @@ fn test_html_element() { // TODO verify case where we have an offset_parent match element.offset_parent() { - None => assert!(true, "Shouldn't have an offset_parent set"), - _ => assert!(false, "Shouldn't have a offset_parent set"), + // Shouldn't have an offset_parent set + None => (), + _ => unreachable!("Shouldn't have a offset_parent set"), }; // TODO verify when we have offsets diff --git a/crates/web-sys/tests/wasm/input_element.rs b/crates/web-sys/tests/wasm/input_element.rs index 30fc4ba7b66..ea2f9c66a56 100644 --- a/crates/web-sys/tests/wasm/input_element.rs +++ b/crates/web-sys/tests/wasm/input_element.rs @@ -8,6 +8,7 @@ extern "C" { } #[wasm_bindgen_test] +#[allow(deprecated)] fn test_input_element() { let element = new_input(); let location = web_sys::window().unwrap().location().href().unwrap(); @@ -49,8 +50,9 @@ fn test_input_element() { assert!(element.disabled(), "Should be disabled"); match element.form() { - None => assert!(true, "Shouldn't have a form"), - _ => assert!(false, "Shouldn't have a form"), + // Shouldn't have a form + None => (), + _ => unreachable!("Shouldn't have a form"), }; assert_eq!( @@ -179,17 +181,17 @@ fn test_input_element() { "The width attribute should be 12" ); - assert_eq!(element.will_validate(), false, "Shouldn't validate"); + assert!(!element.will_validate(), "Shouldn't validate"); assert_eq!( element.validation_message().unwrap(), "", "Shouldn't have a value" ); - assert_eq!(element.check_validity(), true, "Should be valid"); - assert_eq!(element.report_validity(), true, "Should be valid"); + assert!(element.check_validity(), "Should be valid"); + assert!(element.report_validity(), "Should be valid"); element.set_custom_validity("Boop"); // Method exists but doesn't impact validity ?!??! TODO look into - assert_eq!(element.check_validity(), true, "Should be valid"); - assert_eq!(element.report_validity(), true, "Should be valid"); + assert!(element.check_validity(), "Should be valid"); + assert!(element.report_validity(), "Should be valid"); /*TODO add tests pub fn labels(&self) -> Option pub fn select(&self) diff --git a/crates/web-sys/tests/wasm/menu_element.rs b/crates/web-sys/tests/wasm/menu_element.rs index 85df4159997..c1ed7504751 100644 --- a/crates/web-sys/tests/wasm/menu_element.rs +++ b/crates/web-sys/tests/wasm/menu_element.rs @@ -12,16 +12,14 @@ fn test_menu_element() { let menu = new_menu(); menu.set_compact(true); - assert_eq!( + assert!( menu.compact(), - true, "Menu should be compact after we set it to be compact." ); menu.set_compact(false); - assert_eq!( - menu.compact(), - false, + assert!( + !menu.compact(), "Menu should not be compact after we set it to be not-compact." ); } diff --git a/crates/web-sys/tests/wasm/olist_element.rs b/crates/web-sys/tests/wasm/olist_element.rs index 56785c0e796..9108bd24b24 100644 --- a/crates/web-sys/tests/wasm/olist_element.rs +++ b/crates/web-sys/tests/wasm/olist_element.rs @@ -12,16 +12,14 @@ fn test_olist_element() { let olist = new_olist(); olist.set_reversed(true); - assert_eq!( + assert!( olist.reversed(), - true, "Olist should be reversed after we set it to be reversed." ); olist.set_reversed(false); - assert_eq!( - olist.reversed(), - false, + assert!( + !olist.reversed(), "Olist should not be reversed after we set it to be not reversed." ); @@ -47,16 +45,14 @@ fn test_olist_element() { ); olist.set_compact(true); - assert_eq!( + assert!( olist.compact(), - true, "Olist should be compact after we set it to be compact." ); olist.set_compact(false); - assert_eq!( - olist.compact(), - false, + assert!( + !olist.compact(), "Olist should not be compact after we set it to be not compact." ); } diff --git a/crates/web-sys/tests/wasm/opfs.rs b/crates/web-sys/tests/wasm/opfs.rs index 98bd9fc92c6..db679e4f95c 100644 --- a/crates/web-sys/tests/wasm/opfs.rs +++ b/crates/web-sys/tests/wasm/opfs.rs @@ -26,8 +26,9 @@ async fn create_directory( path: &str, ) -> FileSystemDirectoryHandle { let mut opts = FileSystemGetDirectoryOptions::new(); + #[allow(deprecated)] opts.create(true); - JsFuture::from(dir.get_directory_handle_with_options(&path, &opts)) + JsFuture::from(dir.get_directory_handle_with_options(path, &opts)) .await .expect("Couldn't create test directory") .dyn_into::() @@ -41,6 +42,7 @@ async fn create_test_directory(path: &str) -> FileSystemDirectoryHandle { async fn create_file(dir: &FileSystemDirectoryHandle, path: &str) { let mut opts = FileSystemGetFileOptions::new(); + #[allow(deprecated)] opts.create(true); let _ = JsFuture::from(dir.get_file_handle_with_options(path, &opts)).await; } @@ -81,8 +83,9 @@ async fn test_write_to_file() { // create file let mut opts = FileSystemGetFileOptions::new(); + #[allow(deprecated)] opts.create(true); - let file = JsFuture::from(test_dir.get_file_handle_with_options(&"test.txt", &opts)) + let file = JsFuture::from(test_dir.get_file_handle_with_options("test.txt", &opts)) .await .expect("Couldn't create file") .dyn_into::() @@ -95,11 +98,11 @@ async fn test_write_to_file() { .unwrap() .dyn_into::() .unwrap(); - JsFuture::from(write_stream.write_with_str(test_txt).unwrap()).await; + let _ = JsFuture::from(write_stream.write_with_str(test_txt).unwrap()).await; JsFuture::from(write_stream.close()).await.unwrap(); // Read and check contents - let mut values = JsStream::from(test_dir.values()) + let values = JsStream::from(test_dir.values()) .map(|x| x.unwrap().dyn_into::().unwrap()) .collect::>() .await; @@ -140,17 +143,17 @@ async fn test_entries() { assert_eq!(entries.len(), 3); match entries.get("dir") { - Some(handle) => assert!(FileSystemDirectoryHandle::instanceof(&handle)), + Some(handle) => assert!(FileSystemDirectoryHandle::instanceof(handle)), _ => panic!("Didn't find directory"), } match entries.get("file") { - Some(handle) => assert!(FileSystemFileHandle::instanceof(&handle)), + Some(handle) => assert!(FileSystemFileHandle::instanceof(handle)), _ => panic!("Couldn't find file"), } match entries.get("file2") { - Some(handle) => assert!(FileSystemFileHandle::instanceof(&handle)), + Some(handle) => assert!(FileSystemFileHandle::instanceof(handle)), _ => panic!("Couldn't find file2"), } } diff --git a/crates/web-sys/tests/wasm/optgroup_element.rs b/crates/web-sys/tests/wasm/optgroup_element.rs index 99d72dada4a..3e6bea5bf83 100644 --- a/crates/web-sys/tests/wasm/optgroup_element.rs +++ b/crates/web-sys/tests/wasm/optgroup_element.rs @@ -12,16 +12,14 @@ fn test_optgroup_element() { let optgroup = new_optgroup(); optgroup.set_disabled(true); - assert_eq!( + assert!( optgroup.disabled(), - true, "Optgroup should be disabled after we set it to be disabled." ); optgroup.set_disabled(false); - assert_eq!( - optgroup.disabled(), - false, + assert!( + !optgroup.disabled(), "Optgroup should not be disabled after we set it to be not-disabled." ); diff --git a/crates/web-sys/tests/wasm/option_element.rs b/crates/web-sys/tests/wasm/option_element.rs index 10661b29b49..7c060668d04 100644 --- a/crates/web-sys/tests/wasm/option_element.rs +++ b/crates/web-sys/tests/wasm/option_element.rs @@ -12,16 +12,14 @@ fn test_option_element() { .unwrap(); option.set_disabled(true); - assert_eq!( + assert!( option.disabled(), - true, "Option should be disabled after we set it to be disabled." ); option.set_disabled(false); - assert_eq!( - option.disabled(), - false, + assert!( + !option.disabled(), "Option should not be disabled after we set it to be not-disabled." ); @@ -38,30 +36,26 @@ fn test_option_element() { ); option.set_default_selected(true); - assert_eq!( + assert!( option.default_selected(), - true, "Option should be default_selected after we set it to be default_selected." ); option.set_default_selected(false); - assert_eq!( - option.default_selected(), - false, + assert!( + !option.default_selected(), "Option should not be default_selected after we set it to be not default_selected." ); option.set_selected(true); - assert_eq!( + assert!( option.selected(), - true, "Option should be selected after we set it to be selected." ); option.set_selected(false); - assert_eq!( - option.selected(), - false, + assert!( + !option.selected(), "Option should not be selected after we set it to be not selected." ); diff --git a/crates/web-sys/tests/wasm/response.rs b/crates/web-sys/tests/wasm/response.rs index bd172797157..c856be20eaa 100644 --- a/crates/web-sys/tests/wasm/response.rs +++ b/crates/web-sys/tests/wasm/response.rs @@ -53,6 +53,7 @@ async fn wasm_instantiate_streaming() { let headers = Headers::new().unwrap(); headers.append("Content-Type", "application/wasm").unwrap(); + #[allow(deprecated)] let response = Response::new_with_opt_u8_array_and_init( Some(&mut wasm), ResponseInit::new().headers(&headers), diff --git a/crates/web-sys/tests/wasm/rtc_rtp_transceiver_direction.rs b/crates/web-sys/tests/wasm/rtc_rtp_transceiver_direction.rs index 38b30dd0bee..67e5a20cfe6 100644 --- a/crates/web-sys/tests/wasm/rtc_rtp_transceiver_direction.rs +++ b/crates/web-sys/tests/wasm/rtc_rtp_transceiver_direction.rs @@ -25,6 +25,7 @@ async fn rtc_rtp_transceiver_direction() { let pc1: RtcPeerConnection = RtcPeerConnection::new().unwrap(); + #[allow(deprecated)] let tr1: RtcRtpTransceiver = pc1.add_transceiver_with_str_and_init( "audio", tr_init.direction(RtcRtpTransceiverDirection::Sendonly), diff --git a/crates/web-sys/tests/wasm/script_element.rs b/crates/web-sys/tests/wasm/script_element.rs index f8816bd8f2b..afddb7ce54b 100644 --- a/crates/web-sys/tests/wasm/script_element.rs +++ b/crates/web-sys/tests/wasm/script_element.rs @@ -59,7 +59,7 @@ fn test_script_element() { ); assert_eq!(element.text().unwrap(), "", "Shouldn't have text"); - assert_eq!(element.set_text("text").unwrap(), ()); + let _: () = element.set_text("text").unwrap(); assert_eq!(element.text().unwrap(), "text", "Should have text"); assert_eq!(element.event(), "", "Shouldn't have an event"); diff --git a/crates/web-sys/tests/wasm/select_element.rs b/crates/web-sys/tests/wasm/select_element.rs index 18a1a37535a..f5fd865395e 100644 --- a/crates/web-sys/tests/wasm/select_element.rs +++ b/crates/web-sys/tests/wasm/select_element.rs @@ -8,21 +8,20 @@ extern "C" { } #[wasm_bindgen_test] +#[allow(deprecated)] fn test_select_element() { // Creates a select with four options. Options are ["tomato", "potato", "orange", "apple"], where // the string is the .value and .text of each option. let select = new_select_with_food_opts(); select.set_autofocus(true); - assert_eq!( + assert!( select.autofocus(), - true, "Select element should have a true autofocus property." ); select.set_autofocus(false); - assert_eq!( - select.autofocus(), - false, + assert!( + !select.autofocus(), "Select element should have a false autofocus property." ); @@ -34,18 +33,10 @@ fn test_select_element() { ); select.set_disabled(true); - assert_eq!( - select.disabled(), - true, - "Select element should be disabled." - ); + assert!(select.disabled(), "Select element should be disabled."); select.set_disabled(false); - assert_eq!( - select.disabled(), - false, - "Select element should not be disabled." - ); + assert!(!select.disabled(), "Select element should not be disabled."); assert!( select.form().is_none(), @@ -53,16 +44,14 @@ fn test_select_element() { ); select.set_multiple(false); - assert_eq!( - select.multiple(), - false, + assert!( + !select.multiple(), "Select element should have a false multiple property." ); select.set_multiple(true); - assert_eq!( + assert!( select.multiple(), - true, "Select element should have a true multiple property." ); @@ -74,18 +63,10 @@ fn test_select_element() { ); select.set_required(true); - assert_eq!( - select.required(), - true, - "Select element should be required." - ); + assert!(select.required(), "Select element should be required."); select.set_required(false); - assert_eq!( - select.required(), - false, - "Select element should not be required." - ); + assert!(!select.required(), "Select element should not be required."); select.set_size(432); assert_eq!( @@ -97,7 +78,7 @@ fn test_select_element() { // Default type seems to be "select-multiple" for the browsers I tested, but there's no guarantee // on this, so let's just make sure we get back something here. assert!( - select.type_().len() > 0, + !select.type_().is_empty(), "Select element should have some type." ); @@ -143,9 +124,8 @@ fn test_select_element() { ); // This might be browser dependent, potentially rendering this test useless? Worked fine in Chrome and Firefox for now. - assert_eq!( + assert!( select.will_validate(), - true, "Select element should not validate by default." ); diff --git a/crates/web-sys/tests/wasm/span_element.rs b/crates/web-sys/tests/wasm/span_element.rs index 490df42adb1..cc0bd42a411 100644 --- a/crates/web-sys/tests/wasm/span_element.rs +++ b/crates/web-sys/tests/wasm/span_element.rs @@ -10,5 +10,5 @@ extern "C" { #[wasm_bindgen_test] fn test_span_element() { let _element = new_span(); - assert!(true, "Span doesn't have an interface"); + // Span doesn't have an interface } diff --git a/crates/web-sys/tests/wasm/title_element.rs b/crates/web-sys/tests/wasm/title_element.rs index ebc7aa74e6e..4a139d4fea8 100644 --- a/crates/web-sys/tests/wasm/title_element.rs +++ b/crates/web-sys/tests/wasm/title_element.rs @@ -11,6 +11,6 @@ extern "C" { fn title_element() { let element = new_title(); assert_eq!(element.text().unwrap(), "", "Shouldn't have an text"); - assert_eq!(element.set_text("page text").unwrap(), ()); + let _: () = element.set_text("page text").unwrap(); assert_eq!(element.text().unwrap(), "page text", "Should have an text"); } diff --git a/crates/web-sys/tests/wasm/whitelisted_immutable_slices.rs b/crates/web-sys/tests/wasm/whitelisted_immutable_slices.rs index 30d70bf3f6d..9030a161ac7 100644 --- a/crates/web-sys/tests/wasm/whitelisted_immutable_slices.rs +++ b/crates/web-sys/tests/wasm/whitelisted_immutable_slices.rs @@ -18,7 +18,7 @@ use web_sys::{ use web_sys::{WebGl2RenderingContext, WebGlRenderingContext, WebSocket}; // Ensure that our whitelisted WebGlRenderingContext methods compile with immutable slices. -fn test_webgl_rendering_context_immutable_slices() { +pub fn test_webgl_rendering_context_immutable_slices() { let gl = JsValue::null().unchecked_into::(); gl.vertex_attrib1fv_with_f32_array(0, &[1.]); @@ -35,7 +35,7 @@ fn test_webgl_rendering_context_immutable_slices() { gl.uniform_matrix3fv_with_f32_array(None, false, &[1.]); gl.uniform_matrix4fv_with_f32_array(None, false, &[1.]); - gl.tex_image_2d_with_i32_and_i32_and_i32_and_format_and_type_and_opt_u8_array( + let _ = gl.tex_image_2d_with_i32_and_i32_and_i32_and_format_and_type_and_opt_u8_array( 0, 0, 0, @@ -46,7 +46,7 @@ fn test_webgl_rendering_context_immutable_slices() { 0, Some(&[1]), ); - gl.tex_sub_image_2d_with_i32_and_i32_and_u32_and_type_and_opt_u8_array( + let _ = gl.tex_sub_image_2d_with_i32_and_i32_and_u32_and_type_and_opt_u8_array( 0, 0, 0, @@ -61,18 +61,18 @@ fn test_webgl_rendering_context_immutable_slices() { } // Ensure that our whitelisted WebGl2RenderingContext methods compile with immutable slices. -fn test_webgl2_rendering_context_immutable_slices() { +pub fn test_webgl2_rendering_context_immutable_slices() { let gl = JsValue::null().unchecked_into::(); - gl.tex_image_3d_with_opt_u8_array(0, 0, 0, 0, 0, 0, 0, 0, 0, Some(&[1])); - gl.tex_sub_image_3d_with_opt_u8_array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, Some(&[1])); + let _ = gl.tex_image_3d_with_opt_u8_array(0, 0, 0, 0, 0, 0, 0, 0, 0, Some(&[1])); + let _ = gl.tex_sub_image_3d_with_opt_u8_array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, Some(&[1])); gl.compressed_tex_image_3d_with_u8_array(0, 0, 0, 0, 0, 0, 0, &[1]); } // Ensure that our whitelisted WebSocket methods compile with immutable slices. -fn test_websocket_immutable_slices() { +pub fn test_websocket_immutable_slices() { let ws = JsValue::null().unchecked_into::(); - ws.send_with_u8_array(&[0]); + let _ = ws.send_with_u8_array(&[0]); } // Ensure that our whitelisted FileSystemSyncAccessHandle methods compile with immutable slices. diff --git a/crates/web-sys/tests/wasm/xpath_result.rs b/crates/web-sys/tests/wasm/xpath_result.rs index 933ac97ba4a..2c90784464d 100644 --- a/crates/web-sys/tests/wasm/xpath_result.rs +++ b/crates/web-sys/tests/wasm/xpath_result.rs @@ -14,7 +14,7 @@ fn test_xpath_result() { xpath_result.result_type(), XPathResult::UNORDERED_NODE_ITERATOR_TYPE ); - assert_eq!(xpath_result.invalid_iterator_state(), false); + assert!(!xpath_result.invalid_iterator_state()); assert_eq!( xpath_result .iterate_next() diff --git a/crates/webidl/Cargo.toml b/crates/webidl/Cargo.toml index fde8c524d39..2471cb853e1 100644 --- a/crates/webidl/Cargo.toml +++ b/crates/webidl/Cargo.toml @@ -19,3 +19,6 @@ sourcefile = "0.2" syn = { version = '2.0', features = ['extra-traits', 'full'] } wasm-bindgen-backend = { path = "../backend" } weedle = { git = "https://github.com/rustwasm/weedle.git" } + +[lints] +workspace = true diff --git a/examples/add/Cargo.toml b/examples/add/Cargo.toml index 5836f5cc25e..d6bf4247df5 100644 --- a/examples/add/Cargo.toml +++ b/examples/add/Cargo.toml @@ -10,3 +10,6 @@ crate-type = ["cdylib"] [dependencies] wasm-bindgen = { path = "../../" } + +[lints] +workspace = true diff --git a/examples/canvas/Cargo.toml b/examples/canvas/Cargo.toml index 4aec70ddc8d..b0548d0985f 100644 --- a/examples/canvas/Cargo.toml +++ b/examples/canvas/Cargo.toml @@ -15,3 +15,6 @@ wasm-bindgen = { path = "../../" } [dependencies.web-sys] features = ['CanvasRenderingContext2d', 'Document', 'Element', 'HtmlCanvasElement', 'Window'] path = "../../crates/web-sys" + +[lints] +workspace = true diff --git a/examples/char/Cargo.toml b/examples/char/Cargo.toml index bc6bf3c363f..dd78108c30a 100644 --- a/examples/char/Cargo.toml +++ b/examples/char/Cargo.toml @@ -10,3 +10,6 @@ crate-type = ["cdylib"] [dependencies] wasm-bindgen = { path = "../../" } + +[lints] +workspace = true diff --git a/examples/closures/Cargo.toml b/examples/closures/Cargo.toml index 4a70ab8a6da..15641af00f0 100644 --- a/examples/closures/Cargo.toml +++ b/examples/closures/Cargo.toml @@ -15,3 +15,6 @@ wasm-bindgen = { path = "../../" } [dependencies.web-sys] features = ['CssStyleDeclaration', 'Document', 'Element', 'HtmlElement', 'Window'] path = "../../crates/web-sys" + +[lints] +workspace = true diff --git a/examples/console_log/Cargo.toml b/examples/console_log/Cargo.toml index 165c280c86f..8419ced96c7 100644 --- a/examples/console_log/Cargo.toml +++ b/examples/console_log/Cargo.toml @@ -11,3 +11,6 @@ crate-type = ["cdylib"] [dependencies] wasm-bindgen = { path = "../../" } web-sys = { path = "../../crates/web-sys", features = ['console'] } + +[lints] +workspace = true diff --git a/examples/deno/Cargo.toml b/examples/deno/Cargo.toml index 8268d48e4c8..5ebb011c7c9 100644 --- a/examples/deno/Cargo.toml +++ b/examples/deno/Cargo.toml @@ -10,3 +10,6 @@ crate-type = ["cdylib"] [dependencies] wasm-bindgen = { path = "../../" } + +[lints] +workspace = true diff --git a/examples/dom/Cargo.toml b/examples/dom/Cargo.toml index 0b4b310464b..3b0284db49d 100644 --- a/examples/dom/Cargo.toml +++ b/examples/dom/Cargo.toml @@ -14,3 +14,6 @@ wasm-bindgen = { path = "../../" } [dependencies.web-sys] features = ['Document', 'Element', 'HtmlElement', 'Node', 'Window'] path = "../../crates/web-sys" + +[lints] +workspace = true diff --git a/examples/duck-typed-interfaces/Cargo.toml b/examples/duck-typed-interfaces/Cargo.toml index 50f470d2642..a924f2477e2 100644 --- a/examples/duck-typed-interfaces/Cargo.toml +++ b/examples/duck-typed-interfaces/Cargo.toml @@ -10,3 +10,6 @@ crate-type = ["cdylib"] [dependencies] wasm-bindgen = { path = "../../" } + +[lints] +workspace = true diff --git a/examples/explicit-resource-management/Cargo.toml b/examples/explicit-resource-management/Cargo.toml index 1bba26018ff..01787b2279b 100644 --- a/examples/explicit-resource-management/Cargo.toml +++ b/examples/explicit-resource-management/Cargo.toml @@ -10,3 +10,6 @@ crate-type = ["cdylib"] [dependencies] wasm-bindgen = { path = "../../" } + +[lints] +workspace = true diff --git a/examples/explicit-resource-management/src/lib.rs b/examples/explicit-resource-management/src/lib.rs index 67441dd798d..52e49d30ea1 100644 --- a/examples/explicit-resource-management/src/lib.rs +++ b/examples/explicit-resource-management/src/lib.rs @@ -39,8 +39,8 @@ extern "C" { #[wasm_bindgen] pub struct MyStruct { - x: Vec, - y: Vec, + _x: Vec, + _y: Vec, name: String, } @@ -50,8 +50,8 @@ impl MyStruct { pub fn new(name: String) -> MyStruct { Self { name, - x: (0..50).collect(), - y: (0..50).collect(), + _x: (0..50).collect(), + _y: (0..50).collect(), } } } diff --git a/examples/fetch/Cargo.toml b/examples/fetch/Cargo.toml index 27719b43b4a..1f93bcc8fec 100644 --- a/examples/fetch/Cargo.toml +++ b/examples/fetch/Cargo.toml @@ -16,3 +16,6 @@ wasm-bindgen-futures = { path = "../../crates/futures" } [dependencies.web-sys] features = ['Headers', 'Request', 'RequestInit', 'RequestMode', 'Response', 'Window'] path = "../../crates/web-sys" + +[lints] +workspace = true diff --git a/examples/guide-supported-types-examples/Cargo.toml b/examples/guide-supported-types-examples/Cargo.toml index 5918ea94451..84f15c3539c 100644 --- a/examples/guide-supported-types-examples/Cargo.toml +++ b/examples/guide-supported-types-examples/Cargo.toml @@ -11,3 +11,6 @@ crate-type = ["cdylib"] [dependencies] js-sys = { path = "../../crates/js-sys" } wasm-bindgen = { path = "../../" } + +[lints] +workspace = true diff --git a/examples/hello_world/Cargo.toml b/examples/hello_world/Cargo.toml index d1218b0be6d..10721d8e7fc 100644 --- a/examples/hello_world/Cargo.toml +++ b/examples/hello_world/Cargo.toml @@ -10,3 +10,6 @@ crate-type = ["cdylib"] [dependencies] wasm-bindgen = { path = "../../" } + +[lints] +workspace = true diff --git a/examples/import_js/crate/Cargo.toml b/examples/import_js/crate/Cargo.toml index 5b53eb99be6..449e85308e1 100644 --- a/examples/import_js/crate/Cargo.toml +++ b/examples/import_js/crate/Cargo.toml @@ -10,3 +10,6 @@ crate-type = ["cdylib"] [dependencies] wasm-bindgen = { path = "../../../" } + +[lints] +workspace = true diff --git a/examples/julia_set/Cargo.toml b/examples/julia_set/Cargo.toml index 8bdb3ff22af..751aa7d5d89 100644 --- a/examples/julia_set/Cargo.toml +++ b/examples/julia_set/Cargo.toml @@ -14,3 +14,6 @@ wasm-bindgen = { path = "../../" } [dependencies.web-sys] features = ['ImageData', 'CanvasRenderingContext2d'] path = "../../crates/web-sys" + +[lints] +workspace = true diff --git a/examples/paint/Cargo.toml b/examples/paint/Cargo.toml index 9771b0b413b..ffb7aa13c04 100644 --- a/examples/paint/Cargo.toml +++ b/examples/paint/Cargo.toml @@ -26,3 +26,6 @@ features = [ 'Window', ] path = "../../crates/web-sys" + +[lints] +workspace = true diff --git a/examples/performance/Cargo.toml b/examples/performance/Cargo.toml index ef3aa683d1f..daeb5299f5a 100644 --- a/examples/performance/Cargo.toml +++ b/examples/performance/Cargo.toml @@ -15,3 +15,6 @@ wasm-bindgen = { path = "../../" } [dependencies.web-sys] features = ['Window', 'Performance', 'PerformanceTiming'] path = "../../crates/web-sys" + +[lints] +workspace = true diff --git a/examples/raytrace-parallel/Cargo.toml b/examples/raytrace-parallel/Cargo.toml index 79bdebdaf90..384317c8b5f 100644 --- a/examples/raytrace-parallel/Cargo.toml +++ b/examples/raytrace-parallel/Cargo.toml @@ -32,3 +32,6 @@ features = [ 'MessageEvent', ] path = "../../crates/web-sys" + +[lints] +workspace = true diff --git a/examples/request-animation-frame/Cargo.toml b/examples/request-animation-frame/Cargo.toml index 3fe83f77730..c9f6b948e25 100644 --- a/examples/request-animation-frame/Cargo.toml +++ b/examples/request-animation-frame/Cargo.toml @@ -14,3 +14,6 @@ wasm-bindgen = { path = "../../" } [dependencies.web-sys] features = ['Document', 'Element', 'HtmlElement', 'Node', 'Window'] path = "../../crates/web-sys" + +[lints] +workspace = true diff --git a/examples/synchronous-instantiation/Cargo.toml b/examples/synchronous-instantiation/Cargo.toml index 9eda0ee8692..3af99fe2a49 100644 --- a/examples/synchronous-instantiation/Cargo.toml +++ b/examples/synchronous-instantiation/Cargo.toml @@ -10,3 +10,6 @@ crate-type = ["cdylib"] [dependencies] wasm-bindgen = { path = "../../" } + +[lints] +workspace = true diff --git a/examples/todomvc/Cargo.toml b/examples/todomvc/Cargo.toml index 67fe6bcd18d..8cfa60891a0 100644 --- a/examples/todomvc/Cargo.toml +++ b/examples/todomvc/Cargo.toml @@ -38,3 +38,6 @@ features = [ 'Window', ] path = "../../crates/web-sys" + +[lints] +workspace = true diff --git a/examples/wasm-audio-worklet/Cargo.toml b/examples/wasm-audio-worklet/Cargo.toml index 6a0fae91946..0a9306fb468 100644 --- a/examples/wasm-audio-worklet/Cargo.toml +++ b/examples/wasm-audio-worklet/Cargo.toml @@ -31,3 +31,6 @@ features = [ "Window", ] path = "../../crates/web-sys" + +[lints] +workspace = true diff --git a/examples/wasm-in-wasm-imports/Cargo.toml b/examples/wasm-in-wasm-imports/Cargo.toml index ff98763f802..94e385f53a3 100644 --- a/examples/wasm-in-wasm-imports/Cargo.toml +++ b/examples/wasm-in-wasm-imports/Cargo.toml @@ -12,3 +12,6 @@ crate-type = ["cdylib"] js-sys = { path = "../../crates/js-sys" } wasm-bindgen = { path = "../../" } wasm-bindgen-futures = { path = "../../crates/futures" } + +[lints] +workspace = true diff --git a/examples/wasm-in-wasm/Cargo.toml b/examples/wasm-in-wasm/Cargo.toml index ce9f72ceff8..62babf8d6a4 100644 --- a/examples/wasm-in-wasm/Cargo.toml +++ b/examples/wasm-in-wasm/Cargo.toml @@ -12,3 +12,6 @@ crate-type = ["cdylib"] js-sys = { path = "../../crates/js-sys" } wasm-bindgen = { path = "../../" } wasm-bindgen-futures = { path = "../../crates/futures" } + +[lints] +workspace = true diff --git a/examples/wasm-in-web-worker/Cargo.toml b/examples/wasm-in-web-worker/Cargo.toml index 8d623646fc1..b1fdb41a794 100644 --- a/examples/wasm-in-web-worker/Cargo.toml +++ b/examples/wasm-in-web-worker/Cargo.toml @@ -23,3 +23,6 @@ features = [ 'Worker', ] path = "../../crates/web-sys" + +[lints] +workspace = true diff --git a/examples/weather_report/Cargo.toml b/examples/weather_report/Cargo.toml index 1bb0a665c26..e0f59359e01 100644 --- a/examples/weather_report/Cargo.toml +++ b/examples/weather_report/Cargo.toml @@ -19,3 +19,6 @@ wasm-bindgen-futures = { path = "../../crates/futures" } [dependencies.web-sys] features = ["Document", "Element", "HtmlElement", "Window"] path = "../../crates/web-sys" + +[lints] +workspace = true diff --git a/examples/webaudio/Cargo.toml b/examples/webaudio/Cargo.toml index 4fbea599082..f1bb6757399 100644 --- a/examples/webaudio/Cargo.toml +++ b/examples/webaudio/Cargo.toml @@ -22,3 +22,6 @@ features = [ 'OscillatorType', ] path = "../../crates/web-sys" + +[lints] +workspace = true diff --git a/examples/webgl/Cargo.toml b/examples/webgl/Cargo.toml index ebf3967e81f..89ebe247a8d 100644 --- a/examples/webgl/Cargo.toml +++ b/examples/webgl/Cargo.toml @@ -25,3 +25,6 @@ features = [ 'Window', ] path = "../../crates/web-sys" + +[lints] +workspace = true diff --git a/examples/webrtc_datachannel/Cargo.toml b/examples/webrtc_datachannel/Cargo.toml index 9773e0e94c4..dedd4ee1b7d 100644 --- a/examples/webrtc_datachannel/Cargo.toml +++ b/examples/webrtc_datachannel/Cargo.toml @@ -26,3 +26,6 @@ features = [ "RtcDataChannelEvent", ] path = "../../crates/web-sys" + +[lints] +workspace = true diff --git a/examples/websockets/Cargo.toml b/examples/websockets/Cargo.toml index 63f201d35e5..fa72697fc5c 100644 --- a/examples/websockets/Cargo.toml +++ b/examples/websockets/Cargo.toml @@ -23,3 +23,6 @@ features = [ "WebSocket", ] path = "../../crates/web-sys" + +[lints] +workspace = true diff --git a/examples/webxr/Cargo.toml b/examples/webxr/Cargo.toml index 0e2efb8a65d..69feef041d2 100644 --- a/examples/webxr/Cargo.toml +++ b/examples/webxr/Cargo.toml @@ -67,3 +67,10 @@ path = "../../crates/web-sys" [lints.rust] unexpected_cfgs = { level = "warn", check-cfg = ['cfg(web_sys_unstable_apis)'] } + +[lints.clippy] +large_enum_variant = "allow" +new_without_default = "allow" +overly_complex_bool_expr = "allow" +too_many_arguments = "allow" +type_complexity = "allow" diff --git a/examples/without-a-bundler-no-modules/Cargo.toml b/examples/without-a-bundler-no-modules/Cargo.toml index a5e70744cfe..51699060177 100644 --- a/examples/without-a-bundler-no-modules/Cargo.toml +++ b/examples/without-a-bundler-no-modules/Cargo.toml @@ -14,3 +14,6 @@ wasm-bindgen = { path = "../../" } [dependencies.web-sys] features = ['Document', 'Element', 'HtmlElement', 'Node', 'Window'] path = "../../crates/web-sys" + +[lints] +workspace = true diff --git a/examples/without-a-bundler/Cargo.toml b/examples/without-a-bundler/Cargo.toml index 07ccf676c78..a4f2a593c35 100644 --- a/examples/without-a-bundler/Cargo.toml +++ b/examples/without-a-bundler/Cargo.toml @@ -14,3 +14,6 @@ wasm-bindgen = { path = "../../" } [dependencies.web-sys] features = ['Document', 'Element', 'HtmlElement', 'Node', 'Window'] path = "../../crates/web-sys" + +[lints] +workspace = true diff --git a/src/closure.rs b/src/closure.rs index 25186da42cb..95cf2250a89 100644 --- a/src/closure.rs +++ b/src/closure.rs @@ -340,7 +340,7 @@ where #[inline(never)] #[cfg_attr(wasm_bindgen_unstable_test_coverage, coverage(off))] unsafe fn breaks_if_inlined(a: usize, b: usize) -> u32 { - super::__wbindgen_describe_closure(a as u32, b as u32, describe:: as u32) + super::__wbindgen_describe_closure(a as u32, b as u32, describe:: as usize as u32) } let idx = unsafe { breaks_if_inlined::(a, b) }; @@ -596,7 +596,7 @@ macro_rules! doit { ret.return_abi().into() } - inform(invoke::<$($var,)* R> as u32); + inform(invoke::<$($var,)* R> as usize as u32); unsafe extern fn destroy<$($var: FromWasmAbi,)* R: ReturnWasmAbi>( a: usize, @@ -614,7 +614,7 @@ macro_rules! doit { fields: (a, b) }.ptr)); } - inform(destroy::<$($var,)* R> as u32); + inform(destroy::<$($var,)* R> as usize as u32); <&Self>::describe(); } @@ -656,7 +656,7 @@ macro_rules! doit { ret.return_abi().into() } - inform(invoke::<$($var,)* R> as u32); + inform(invoke::<$($var,)* R> as usize as u32); unsafe extern fn destroy<$($var: FromWasmAbi,)* R: ReturnWasmAbi>( a: usize, @@ -670,7 +670,7 @@ macro_rules! doit { fields: (a, b) }.ptr)); } - inform(destroy::<$($var,)* R> as u32); + inform(destroy::<$($var,)* R> as usize as u32); <&mut Self>::describe(); } @@ -793,7 +793,7 @@ where ret.return_abi().into() } - inform(invoke:: as u32); + inform(invoke:: as usize as u32); #[cfg_attr(wasm_bindgen_unstable_test_coverage, coverage(off))] unsafe extern "C" fn destroy(a: usize, b: usize) { @@ -805,7 +805,7 @@ where FatPtr:: R> { fields: (a, b) }.ptr, )); } - inform(destroy:: as u32); + inform(destroy:: as usize as u32); <&Self>::describe(); } @@ -843,7 +843,7 @@ where ret.return_abi().into() } - inform(invoke:: as u32); + inform(invoke:: as usize as u32); #[cfg_attr(wasm_bindgen_unstable_test_coverage, coverage(off))] unsafe extern "C" fn destroy(a: usize, b: usize) { @@ -855,7 +855,7 @@ where FatPtr:: R> { fields: (a, b) }.ptr, )); } - inform(destroy:: as u32); + inform(destroy:: as usize as u32); <&mut Self>::describe(); } diff --git a/src/convert/closures.rs b/src/convert/closures.rs index 0e2f59ee5db..1f45f90f58b 100644 --- a/src/convert/closures.rs +++ b/src/convert/closures.rs @@ -57,7 +57,7 @@ macro_rules! stack_closures { #[cfg_attr(wasm_bindgen_unstable_test_coverage, coverage(off))] fn describe() { inform(FUNCTION); - inform($invoke::<$($var,)* R> as u32); + inform($invoke::<$($var,)* R> as usize as u32); inform($cnt); $(<$var as WasmDescribe>::describe();)* ::describe(); @@ -112,7 +112,7 @@ macro_rules! stack_closures { #[cfg_attr(wasm_bindgen_unstable_test_coverage, coverage(off))] fn describe() { inform(FUNCTION); - inform($invoke_mut::<$($var,)* R> as u32); + inform($invoke_mut::<$($var,)* R> as usize as u32); inform($cnt); $(<$var as WasmDescribe>::describe();)* ::describe(); @@ -183,7 +183,7 @@ where #[cfg_attr(wasm_bindgen_unstable_test_coverage, coverage(off))] fn describe() { inform(FUNCTION); - inform(invoke1_ref:: as u32); + inform(invoke1_ref:: as usize as u32); inform(1); <&A as WasmDescribe>::describe(); ::describe(); @@ -240,7 +240,7 @@ where #[cfg_attr(wasm_bindgen_unstable_test_coverage, coverage(off))] fn describe() { inform(FUNCTION); - inform(invoke1_mut_ref:: as u32); + inform(invoke1_mut_ref:: as usize as u32); inform(1); <&A as WasmDescribe>::describe(); ::describe(); diff --git a/tests/wasm/classes.rs b/tests/wasm/classes.rs index e590cf7e2eb..d701e2088ed 100644 --- a/tests/wasm/classes.rs +++ b/tests/wasm/classes.rs @@ -533,7 +533,7 @@ mod works_in_module { use wasm_bindgen::prelude::wasm_bindgen; #[wasm_bindgen] - pub struct WorksInModule(u32); + pub struct WorksInModule(#[allow(dead_code)] u32); #[wasm_bindgen] impl WorksInModule { diff --git a/tests/wasm/closures.rs b/tests/wasm/closures.rs index 4cf7b21e737..d8bd2e92357 100644 --- a/tests/wasm/closures.rs +++ b/tests/wasm/closures.rs @@ -499,7 +499,9 @@ fn test_closure_returner() { js_test_closure_returner(); #[wasm_bindgen] - pub struct ClosureHandle(Closure); + pub struct ClosureHandle { + _closure: Closure, + } #[wasm_bindgen] pub struct BadStruct {} @@ -518,7 +520,7 @@ fn test_closure_returner() { Reflect::set( &o, &JsValue::from("handle"), - &JsValue::from(ClosureHandle(some_fn)), + &JsValue::from(ClosureHandle { _closure: some_fn }), ) .unwrap(); diff --git a/tests/wasm/simple.rs b/tests/wasm/simple.rs index fdef34c68fd..5d060ca8962 100644 --- a/tests/wasm/simple.rs +++ b/tests/wasm/simple.rs @@ -71,6 +71,9 @@ pub fn simple_return_raw_pointer_u8(value: u8) -> *const u8 { Box::into_raw(Box::new(value)) } +/// # Safety +/// +/// Pointers have to be valid. #[wasm_bindgen] pub unsafe fn simple_raw_pointers_work(a: *mut u32, b: *const u8) -> *const u32 { (*a) = (*b) as u32; @@ -82,6 +85,9 @@ pub fn simple_return_option_null_pointer() -> Option<*const u32> { Some(ptr::null()) } +/// # Safety +/// +/// Pointers have to be valid. #[wasm_bindgen] pub unsafe fn simple_option_raw_pointers_work( a: Option<*mut u32>, @@ -113,11 +119,17 @@ pub fn simple_return_option_non_null(value: u32) -> Option> { Some(NonNull::from(Box::leak(Box::new(value)))) } +/// # Safety +/// +/// Pointer has to be generated by [`Box::leak()`] on a `Box`. #[wasm_bindgen] pub unsafe fn simple_nonnull_work(a: NonNull) -> u32 { *Box::from_raw(a.as_ptr()) } +/// # Safety +/// +/// Pointer has to be generated by [`Box::leak()`] on a `Box`. #[wasm_bindgen] pub unsafe fn simple_option_nonnull_work(a: Option>) -> Option { a.map(|ptr| *Box::from_raw(ptr.as_ptr()))