diff --git a/benchmarks/src/lib.rs b/benchmarks/src/lib.rs index 2b8e1736..f6c375db 100644 --- a/benchmarks/src/lib.rs +++ b/benchmarks/src/lib.rs @@ -6,7 +6,7 @@ use wasm_bindgen::JsCast; use web_sys::Node; #[wasm_bindgen(raw_module = "../globals.js")] -extern { +extern "C" { #[wasm_bindgen(js_name = jsthunk)] fn js_thunk(); #[wasm_bindgen(js_name = add)] @@ -57,8 +57,10 @@ pub fn fibonacci(n: i32) -> i32 { b += a; a = tmp; } - unsafe { FIB_HIGH = (a >> 32) as i32; } - return a as i32 + unsafe { + FIB_HIGH = (a >> 32) as i32; + } + return a as i32; } #[wasm_bindgen] @@ -97,7 +99,7 @@ pub fn call_doesnt_throw_with_catch_n_times(n: usize) { } #[wasm_bindgen] -extern { +extern "C" { pub type Element; #[wasm_bindgen(method, js_name = firstChild, final, getter)] diff --git a/crates/cli-support/src/js/js2rust.rs b/crates/cli-support/src/js/js2rust.rs index ed04ae30..dfc238b5 100644 --- a/crates/cli-support/src/js/js2rust.rs +++ b/crates/cli-support/src/js/js2rust.rs @@ -10,11 +10,19 @@ pub struct JsArgument { impl JsArgument { fn required(name: String, type_: String) -> Self { - Self { optional: false, name, type_ } + Self { + optional: false, + name, + type_, + } } fn optional(name: String, type_: String) -> Self { - Self { optional: true, name, type_ } + Self { + optional: true, + name, + type_, + } } } @@ -237,7 +245,8 @@ impl<'a, 'b> Js2Rust<'a, 'b> { } if arg.is_anyref() { - self.js_arguments.push(JsArgument::required(name.clone(), "any".to_string())); + self.js_arguments + .push(JsArgument::required(name.clone(), "any".to_string())); if self.cx.config.anyref { if optional { self.cx.expose_add_to_anyref_table()?; @@ -387,7 +396,8 @@ impl<'a, 'b> Js2Rust<'a, 'b> { } if let Some(s) = arg.rust_struct() { - self.js_arguments.push(JsArgument::required(name.clone(), s.to_string())); + self.js_arguments + .push(JsArgument::required(name.clone(), s.to_string())); self.assert_class(&name, s); self.assert_not_moved(&name); if arg.is_by_ref() { @@ -401,7 +411,8 @@ impl<'a, 'b> Js2Rust<'a, 'b> { } if arg.number().is_some() { - self.js_arguments.push(JsArgument::required(name.clone(), "number".to_string())); + self.js_arguments + .push(JsArgument::required(name.clone(), "number".to_string())); if self.cx.config.debug { self.cx.expose_assert_num(); @@ -419,7 +430,8 @@ impl<'a, 'b> Js2Rust<'a, 'b> { self.cx.expose_uint64_cvt_shim() }; self.cx.expose_uint32_memory(); - self.js_arguments.push(JsArgument::required(name.clone(), "BigInt".to_string())); + self.js_arguments + .push(JsArgument::required(name.clone(), "BigInt".to_string())); self.prelude(&format!( " {f}[0] = {name}; @@ -436,7 +448,8 @@ impl<'a, 'b> Js2Rust<'a, 'b> { } if arg.is_ref_anyref() { - self.js_arguments.push(JsArgument::required(name.clone(), "any".to_string())); + self.js_arguments + .push(JsArgument::required(name.clone(), "any".to_string())); if self.cx.config.anyref { self.anyref_args.push((self.rust_arguments.len(), false)); self.rust_arguments.push(name); @@ -469,7 +482,8 @@ impl<'a, 'b> Js2Rust<'a, 'b> { self.rust_arguments.push(format!("{}", name)); } Descriptor::Char => { - self.js_arguments.push(JsArgument::required(name.clone(), "string".to_string())); + self.js_arguments + .push(JsArgument::required(name.clone(), "string".to_string())); self.rust_arguments.push(format!("{}.codePointAt(0)", name)) } _ => bail!( @@ -751,10 +765,12 @@ impl<'a, 'b> Js2Rust<'a, 'b> { let mut ret: String = self .js_arguments .iter() - .map(|a| if a.optional { - format!("@param {{{} | undefined}} {}\n", a.type_, a.name) - } else { - format!("@param {{{}}} {}\n", a.type_, a.name) + .map(|a| { + if a.optional { + format!("@param {{{} | undefined}} {}\n", a.type_, a.name) + } else { + format!("@param {{{}}} {}\n", a.type_, a.name) + } }) .collect(); ret.push_str(&format!("@returns {{{}}}", self.ret_ty)); diff --git a/crates/cli-support/src/js/mod.rs b/crates/cli-support/src/js/mod.rs index 4cf6cb00..1e32518a 100644 --- a/crates/cli-support/src/js/mod.rs +++ b/crates/cli-support/src/js/mod.rs @@ -249,7 +249,12 @@ impl<'a> Context<'a> { format!("{}{}\n", export, contents) } else { assert_eq!(export_name, definition_name); - format!("{}const {name} = {};\n__exports.{name} = {name};", export, contents, name = export_name) + format!( + "{}const {name} = {};\n__exports.{name} = {name};", + export, + contents, + name = export_name + ) } } }; @@ -1163,8 +1168,7 @@ impl<'a> Context<'a> { }} }}); ", - name, - name, + name, name, )); } diff --git a/crates/cli-support/src/js/rust2js.rs b/crates/cli-support/src/js/rust2js.rs index 50eb8d37..877b3396 100644 --- a/crates/cli-support/src/js/rust2js.rs +++ b/crates/cli-support/src/js/rust2js.rs @@ -731,8 +731,7 @@ impl<'a, 'b> Rust2Js<'a, 'b> { throw e; }}\ ", - &invoc, - shim, + &invoc, shim, ); } diff --git a/crates/futures/src/futures_0_3.rs b/crates/futures/src/futures_0_3.rs index 4c939158..24f71b34 100644 --- a/crates/futures/src/futures_0_3.rs +++ b/crates/futures/src/futures_0_3.rs @@ -1,14 +1,14 @@ -use std::fmt; -use std::pin::Pin; use std::cell::{Cell, RefCell}; -use std::sync::Arc; -use std::future::Future; -use std::task::{Poll, Context}; use std::collections::VecDeque; +use std::fmt; +use std::future::Future; +use std::pin::Pin; +use std::sync::Arc; +use std::task::{Context, Poll}; -use futures_util::task::ArcWake; -use futures_util::future::FutureExt; use futures_channel::oneshot; +use futures_util::future::FutureExt; +use futures_util::task::ArcWake; use lazy_static::lazy_static; @@ -112,14 +112,12 @@ where Promise::new(&mut |resolve, reject| { // TODO change Promise::new to be FnOnce - spawn_local(future.take().unwrap_throw().map(move |val| { - match val { - Ok(val) => { - resolve.call1(&JsValue::undefined(), &val).unwrap_throw(); - }, - Err(val) => { - reject.call1(&JsValue::undefined(), &val).unwrap_throw(); - }, + spawn_local(future.take().unwrap_throw().map(move |val| match val { + Ok(val) => { + resolve.call1(&JsValue::undefined(), &val).unwrap_throw(); + } + Err(val) => { + reject.call1(&JsValue::undefined(), &val).unwrap_throw(); } })); }) @@ -147,7 +145,10 @@ where impl Task { #[inline] - fn new(future: F) -> Arc where F: Future + 'static { + fn new(future: F) -> Arc + where + F: Future + 'static, + { Arc::new(Self { future: RefCell::new(Some(Box::pin(future))), is_queued: Cell::new(false), @@ -171,7 +172,6 @@ where } } - struct NextTick { is_spinning: Cell, promise: Promise, @@ -180,7 +180,10 @@ where impl NextTick { #[inline] - fn new(mut f: F) -> Self where F: FnMut() + 'static { + fn new(mut f: F) -> Self + where + F: FnMut() + 'static, + { Self { is_spinning: Cell::new(false), promise: Promise::resolve(&JsValue::null()), @@ -205,7 +208,6 @@ where } } - struct Executor { // This is a queue of Tasks which will be polled in order tasks: RefCell>>, @@ -265,6 +267,5 @@ where }; } - ArcWake::wake_by_ref(&Task::new(future)); } diff --git a/src/convert/impls.rs b/src/convert/impls.rs index 4b0900c7..6b9bb9ca 100644 --- a/src/convert/impls.rs +++ b/src/convert/impls.rs @@ -134,12 +134,12 @@ macro_rules! type_abi_as_u32 { impl OptionIntoWasmAbi for $t { #[inline] - fn none() -> u32 { 0xFFFFFFu32 } + fn none() -> u32 { 0x00FF_FFFFu32 } } impl OptionFromWasmAbi for $t { #[inline] - fn is_none(js: &u32) -> bool { *js == 0xFFFFFFu32 } + fn is_none(js: &u32) -> bool { *js == 0x00FF_FFFFu32 } } )*) } @@ -165,7 +165,7 @@ macro_rules! type_64 { #[inline] unsafe fn from_abi(js: Wasm64, _extra: &mut Stack) -> $t { - (js.low as $t) | ((js.high as $t) << 32) + $t::from(js.low) | ($t::from(js.high) << 32) } } @@ -199,7 +199,7 @@ macro_rules! type_64 { if js.present == 0 { None } else { - Some((js.low as $t) | ((js.high as $t) << 32)) + Some($t::from(js.low) | ($t::from(js.high) << 32)) } } } @@ -229,14 +229,14 @@ impl FromWasmAbi for bool { impl OptionIntoWasmAbi for bool { #[inline] fn none() -> u32 { - 0xFFFFFFu32 + 0x00FF_FFFFu32 } } impl OptionFromWasmAbi for bool { #[inline] fn is_none(js: &u32) -> bool { - *js == 0xFFFFFFu32 + *js == 0x00FF_FFFFu32 } } @@ -261,14 +261,14 @@ impl FromWasmAbi for char { impl OptionIntoWasmAbi for char { #[inline] fn none() -> u32 { - 0xFFFFFFu32 + 0x00FF_FFFFu32 } } impl OptionFromWasmAbi for char { #[inline] fn is_none(js: &u32) -> bool { - *js == 0xFFFFFFu32 + *js == 0x00FF_FFFFu32 } } @@ -311,7 +311,7 @@ impl IntoWasmAbi for JsValue { fn into_abi(self, _extra: &mut Stack) -> u32 { let ret = self.idx; mem::forget(self); - return ret; + ret } } @@ -386,7 +386,7 @@ impl IntoWasmAbi for () { type Abi = (); #[inline] - fn into_abi(self, _extra: &mut Stack) -> () { + fn into_abi(self, _extra: &mut Stack) { self } } diff --git a/src/lib.rs b/src/lib.rs index 458b84e5..30279ff0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -702,9 +702,7 @@ pub fn throw_val(s: JsValue) -> ! { /// } /// ``` pub fn anyref_heap_live_count() -> u32 { - unsafe { - __wbindgen_anyref_heap_live_count() - } + unsafe { __wbindgen_anyref_heap_live_count() } } /// An extension trait for `Option` and `Result` for unwraping the `T` @@ -984,16 +982,14 @@ pub mod __rt { } #[no_mangle] - pub extern "C" fn __wbindgen_realloc(ptr: *mut u8, old_size: usize, new_size: usize) -> *mut u8 { + pub unsafe extern "C" fn __wbindgen_realloc(ptr: *mut u8, old_size: usize, new_size: usize) -> *mut u8 { let align = mem::align_of::(); debug_assert!(old_size > 0); debug_assert!(new_size > 0); if let Ok(layout) = Layout::from_size_align(old_size, align) { - unsafe { - let ptr = realloc(ptr, layout, new_size); - if !ptr.is_null() { - return ptr - } + let ptr = realloc(ptr, layout, new_size); + if !ptr.is_null() { + return ptr } } malloc_failure(); diff --git a/tests/headless/main.rs b/tests/headless/main.rs index c2b2ed2d..80730f27 100755 --- a/tests/headless/main.rs +++ b/tests/headless/main.rs @@ -47,9 +47,9 @@ pub fn import_export_same_name() { import_export_same_name(); } -pub mod snippets; -pub mod modules; pub mod anyref_heap_live_count; +pub mod modules; +pub mod snippets; pub mod strings; #[wasm_bindgen_test] diff --git a/tests/wasm/getters_and_setters.rs b/tests/wasm/getters_and_setters.rs index cb693e11..5a89a13e 100644 --- a/tests/wasm/getters_and_setters.rs +++ b/tests/wasm/getters_and_setters.rs @@ -1,5 +1,5 @@ -use std::rc::Rc; use std::cell::Cell; +use std::rc::Rc; use wasm_bindgen::prelude::*; use wasm_bindgen_test::*; @@ -136,7 +136,9 @@ struct GetterCompute; #[wasm_bindgen] impl GetterCompute { #[wasm_bindgen(getter)] - pub fn foo(&self) -> u32 { 3 } + pub fn foo(&self) -> u32 { + 3 + } } #[wasm_bindgen_test]