From f3adee7056a71fdbdcdf9ad4f641d6c58fde3665 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 3 Jun 2019 08:23:49 -0700 Subject: [PATCH 1/2] Squash warnings about unused variables Make sure when compiling for non-wasm targets we don't issue tons of warnings about unused variables which can't be squashed. --- crates/backend/src/codegen.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/crates/backend/src/codegen.rs b/crates/backend/src/codegen.rs index 98e749fea64..99defaf26dd 100644 --- a/crates/backend/src/codegen.rs +++ b/crates/backend/src/codegen.rs @@ -210,7 +210,7 @@ impl ToTokens for ast::Struct { } #[cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"))))] - unsafe fn #new_fn(ptr: u32) -> u32 { + unsafe fn #new_fn(_: u32) -> u32 { panic!("cannot convert to JsValue outside of the wasm target") } @@ -719,7 +719,7 @@ impl ToTokens for ast::ImportType { fn #instanceof_shim(val: u32) -> u32; } #[cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"))))] - unsafe fn #instanceof_shim(val: u32) -> u32 { + unsafe fn #instanceof_shim(_: u32) -> u32 { panic!("cannot check instanceof on non-wasm targets"); } unsafe { @@ -997,6 +997,7 @@ impl TryToTokens for ast::ImportFunction { let attrs = &self.function.rust_attrs; let arguments = &arguments; let abi_arguments = &abi_arguments; + let abi_argument_names = &abi_argument_names; let doc_comment = match &self.doc_comment { None => "", @@ -1032,6 +1033,7 @@ impl TryToTokens for ast::ImportFunction { } #[cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"))))] unsafe fn #import_name(#(#abi_arguments),*) -> #abi_ret { + drop((#(#abi_argument_names),*)); panic!("cannot call wasm-bindgen imported functions on \ non-wasm targets"); } From 82467f9793031c61273c5ec9fdb8351942708c87 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 3 Jun 2019 08:26:14 -0700 Subject: [PATCH 2/2] Use `dyn` with all trait objects Fixes new warnings showing up on nightly nowadays. --- crates/backend/src/codegen.rs | 32 ++++++------ crates/backend/src/error.rs | 4 +- crates/cli-support/src/js/mod.rs | 2 +- crates/futures/src/lib.rs | 12 ++--- crates/js-sys/src/lib.rs | 36 ++++++------- crates/test/src/rt/mod.rs | 8 +-- crates/webidl-tests/simple.rs | 6 +-- crates/webidl/src/error.rs | 2 +- examples/raytrace-parallel/src/lib.rs | 2 +- examples/request-animation-frame/src/lib.rs | 4 +- src/closure.rs | 52 +++++++++---------- src/convert/closures.rs | 32 ++++++------ src/convert/impls.rs | 56 ++++++++++----------- src/convert/slices.rs | 28 +++++------ src/convert/traits.rs | 12 ++--- 15 files changed, 144 insertions(+), 144 deletions(-) diff --git a/crates/backend/src/codegen.rs b/crates/backend/src/codegen.rs index 99defaf26dd..4fb6642e88e 100644 --- a/crates/backend/src/codegen.rs +++ b/crates/backend/src/codegen.rs @@ -166,7 +166,7 @@ impl ToTokens for ast::Struct { impl wasm_bindgen::convert::IntoWasmAbi for #name { type Abi = u32; - fn into_abi(self, _extra: &mut wasm_bindgen::convert::Stack) + fn into_abi(self, _extra: &mut dyn wasm_bindgen::convert::Stack) -> u32 { use wasm_bindgen::__rt::std::boxed::Box; @@ -179,7 +179,7 @@ impl ToTokens for ast::Struct { impl wasm_bindgen::convert::FromWasmAbi for #name { type Abi = u32; - unsafe fn from_abi(js: u32, _extra: &mut wasm_bindgen::convert::Stack) + unsafe fn from_abi(js: u32, _extra: &mut dyn wasm_bindgen::convert::Stack) -> Self { use wasm_bindgen::__rt::std::boxed::Box; @@ -242,7 +242,7 @@ impl ToTokens for ast::Struct { unsafe fn ref_from_abi( js: Self::Abi, - _extra: &mut wasm_bindgen::convert::Stack, + _extra: &mut dyn wasm_bindgen::convert::Stack, ) -> Self::Anchor { let js = js as *mut wasm_bindgen::__rt::WasmRefCell<#name>; wasm_bindgen::__rt::assert_not_null(js); @@ -257,7 +257,7 @@ impl ToTokens for ast::Struct { unsafe fn ref_mut_from_abi( js: Self::Abi, - _extra: &mut wasm_bindgen::convert::Stack, + _extra: &mut dyn wasm_bindgen::convert::Stack, ) -> Self::Anchor { let js = js as *mut wasm_bindgen::__rt::WasmRefCell<#name>; wasm_bindgen::__rt::assert_not_null(js); @@ -637,7 +637,7 @@ impl ToTokens for ast::ImportType { type Abi = ::Abi; #[inline] - fn into_abi(self, extra: &mut Stack) -> Self::Abi { + fn into_abi(self, extra: &mut dyn Stack) -> Self::Abi { self.obj.into_abi(extra) } } @@ -656,7 +656,7 @@ impl ToTokens for ast::ImportType { type Abi = ::Abi; #[inline] - unsafe fn from_abi(js: Self::Abi, extra: &mut Stack) -> Self { + unsafe fn from_abi(js: Self::Abi, extra: &mut dyn Stack) -> Self { #rust_name { obj: JsValue::from_abi(js, extra).into(), } @@ -672,7 +672,7 @@ impl ToTokens for ast::ImportType { type Abi = <&'a JsValue as IntoWasmAbi>::Abi; #[inline] - fn into_abi(self, extra: &mut Stack) -> Self::Abi { + fn into_abi(self, extra: &mut dyn Stack) -> Self::Abi { (&self.obj).into_abi(extra) } } @@ -682,7 +682,7 @@ impl ToTokens for ast::ImportType { type Anchor = core::mem::ManuallyDrop<#rust_name>; #[inline] - unsafe fn ref_from_abi(js: Self::Abi, extra: &mut Stack) -> Self::Anchor { + unsafe fn ref_from_abi(js: Self::Abi, extra: &mut dyn Stack) -> Self::Anchor { let tmp = ::ref_from_abi(js, extra); core::mem::ManuallyDrop::new(#rust_name { obj: core::mem::ManuallyDrop::into_inner(tmp).into(), @@ -838,7 +838,7 @@ impl ToTokens for ast::ImportEnum { wasm_bindgen::convert::IntoWasmAbi>::Abi; #[inline] - fn into_abi(self, extra: &mut wasm_bindgen::convert::Stack) -> Self::Abi { + fn into_abi(self, extra: &mut dyn wasm_bindgen::convert::Stack) -> Self::Abi { wasm_bindgen::JsValue::from(self).into_abi(extra) } } @@ -850,7 +850,7 @@ impl ToTokens for ast::ImportEnum { unsafe fn from_abi( js: Self::Abi, - extra: &mut wasm_bindgen::convert::Stack, + extra: &mut dyn wasm_bindgen::convert::Stack, ) -> Self { #name::from_js_value(&wasm_bindgen::JsValue::from_abi(js, extra)).unwrap_or(#name::__Nonexhaustive) } @@ -1127,7 +1127,7 @@ impl ToTokens for ast::Enum { type Abi = u32; #[inline] - fn into_abi(self, _extra: &mut wasm_bindgen::convert::Stack) -> u32 { + fn into_abi(self, _extra: &mut dyn wasm_bindgen::convert::Stack) -> u32 { self as u32 } } @@ -1139,7 +1139,7 @@ impl ToTokens for ast::Enum { #[inline] unsafe fn from_abi( js: u32, - _extra: &mut wasm_bindgen::convert::Stack, + _extra: &mut dyn wasm_bindgen::convert::Stack, ) -> Self { #(#cast_clauses else)* { wasm_bindgen::throw_str("invalid enum value passed") @@ -1333,7 +1333,7 @@ impl ToTokens for ast::Dictionary { impl IntoWasmAbi for #name { type Abi = ::Abi; #[inline] - fn into_abi(self, extra: &mut Stack) -> Self::Abi { + fn into_abi(self, extra: &mut dyn Stack) -> Self::Abi { self.obj.into_abi(extra) } } @@ -1341,7 +1341,7 @@ impl ToTokens for ast::Dictionary { impl<'a> IntoWasmAbi for &'a #name { type Abi = <&'a Object as IntoWasmAbi>::Abi; #[inline] - fn into_abi(self, extra: &mut Stack) -> Self::Abi { + fn into_abi(self, extra: &mut dyn Stack) -> Self::Abi { (&self.obj).into_abi(extra) } } @@ -1349,7 +1349,7 @@ impl ToTokens for ast::Dictionary { impl FromWasmAbi for #name { type Abi = ::Abi; #[inline] - unsafe fn from_abi(abi: Self::Abi, extra: &mut Stack) -> Self { + unsafe fn from_abi(abi: Self::Abi, extra: &mut dyn Stack) -> Self { #name { obj: Object::from_abi(abi, extra) } } } @@ -1372,7 +1372,7 @@ impl ToTokens for ast::Dictionary { type Anchor = ManuallyDrop<#name>; #[inline] - unsafe fn ref_from_abi(js: Self::Abi, extra: &mut Stack) -> Self::Anchor { + unsafe fn ref_from_abi(js: Self::Abi, extra: &mut dyn Stack) -> Self::Anchor { let tmp = ::ref_from_abi(js, extra); ManuallyDrop::new(#name { obj: ManuallyDrop::into_inner(tmp), diff --git a/crates/backend/src/error.rs b/crates/backend/src/error.rs index 0154675782a..6c66ba95b14 100644 --- a/crates/backend/src/error.rs +++ b/crates/backend/src/error.rs @@ -52,7 +52,7 @@ impl Diagnostic { } } - pub fn spanned_error>(node: &ToTokens, text: T) -> Diagnostic { + pub fn spanned_error>(node: &dyn ToTokens, text: T) -> Diagnostic { Diagnostic { inner: Repr::Single { text: text.into(), @@ -89,7 +89,7 @@ impl From for Diagnostic { } } -fn extract_spans(node: &ToTokens) -> Option<(Span, Span)> { +fn extract_spans(node: &dyn ToTokens) -> Option<(Span, Span)> { let mut t = TokenStream::new(); node.to_tokens(&mut t); let mut tokens = t.into_iter(); diff --git a/crates/cli-support/src/js/mod.rs b/crates/cli-support/src/js/mod.rs index 1e32518a36d..da1eea84fd4 100644 --- a/crates/cli-support/src/js/mod.rs +++ b/crates/cli-support/src/js/mod.rs @@ -1086,7 +1086,7 @@ impl<'a> Context<'a> { fn bind( &mut self, name: &str, - f: &Fn(&mut Self) -> Result, + f: &dyn Fn(&mut Self) -> Result, ) -> Result<(), Error> { if !self.wasm_import_needed(name) { return Ok(()); diff --git a/crates/futures/src/lib.rs b/crates/futures/src/lib.rs index c5025e53f1c..3cf9b9c0903 100644 --- a/crates/futures/src/lib.rs +++ b/crates/futures/src/lib.rs @@ -130,7 +130,7 @@ use wasm_bindgen::prelude::*; pub struct JsFuture { resolved: oneshot::Receiver, rejected: oneshot::Receiver, - callbacks: Option<(Closure, Closure)>, + callbacks: Option<(Closure, Closure)>, } impl fmt::Debug for JsFuture { @@ -152,11 +152,11 @@ impl From for JsFuture { let mut tx1 = Some(tx1); let resolve = Closure::wrap(Box::new(move |val| { drop(tx1.take().unwrap().send(val)); - }) as Box); + }) as Box); let mut tx2 = Some(tx2); let reject = Closure::wrap(Box::new(move |val| { drop(tx2.take().unwrap().send(val)); - }) as Box); + }) as Box); js.then2(&resolve, &reject); @@ -233,7 +233,7 @@ where // // This isn't necessarily the greatest future executor in the world, but it // should get the job done for now hopefully. -fn _future_to_promise(future: Box>) -> Promise { +fn _future_to_promise(future: Box>) -> Promise { let mut future = Some(executor::spawn(future)); return Promise::new(&mut |resolve, reject| { Package::poll(&Arc::new(Package { @@ -247,7 +247,7 @@ fn _future_to_promise(future: Box>) -> P struct Package { // Our "spawned future". This'll have everything we need to poll the // future and continue to move it forward. - spawn: RefCell>>>, + spawn: RefCell>>>, // The current state of this future, expressed in an enum below. This // indicates whether we're currently polling the future, received a @@ -379,7 +379,7 @@ fn _future_to_promise(future: Box>) -> P let myself = slot2.borrow_mut().take(); debug_assert!(myself.is_some()); Package::poll(&me); - }) as Box); + }) as Box); promise.then(&closure); *slot.borrow_mut() = Some(closure); } diff --git a/crates/js-sys/src/lib.rs b/crates/js-sys/src/lib.rs index cbefb58e1cb..bdf73ad9f90 100644 --- a/crates/js-sys/src/lib.rs +++ b/crates/js-sys/src/lib.rs @@ -158,7 +158,7 @@ extern "C" { /// /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every) #[wasm_bindgen(method)] - pub fn every(this: &Array, predicate: &mut FnMut(JsValue, u32, Array) -> bool) -> bool; + pub fn every(this: &Array, predicate: &mut dyn FnMut(JsValue, u32, Array) -> bool) -> bool; /// The fill() method fills all the elements of an array from a start index /// to an end index with a static value. The end index is not included. @@ -172,27 +172,27 @@ extern "C" { /// /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter) #[wasm_bindgen(method)] - pub fn filter(this: &Array, predicate: &mut FnMut(JsValue, u32, Array) -> bool) -> Array; + pub fn filter(this: &Array, predicate: &mut dyn FnMut(JsValue, u32, Array) -> bool) -> Array; /// The `find()` method returns the value of the first element in the array that satisfies /// the provided testing function. Otherwise `undefined` is returned. /// /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find) #[wasm_bindgen(method)] - pub fn find(this: &Array, predicate: &mut FnMut(JsValue, u32, Array) -> bool) -> JsValue; + pub fn find(this: &Array, predicate: &mut dyn FnMut(JsValue, u32, Array) -> bool) -> JsValue; /// The findIndex() method returns the index of the first element in the array that /// satisfies the provided testing function. Otherwise -1 is returned. /// /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex) #[wasm_bindgen(method, js_name = findIndex)] - pub fn find_index(this: &Array, predicate: &mut FnMut(JsValue, u32, Array) -> bool) -> i32; + pub fn find_index(this: &Array, predicate: &mut dyn FnMut(JsValue, u32, Array) -> bool) -> i32; /// The `forEach()` method executes a provided function once for each array element. /// /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach) #[wasm_bindgen(method, js_name = forEach)] - pub fn for_each(this: &Array, callback: &mut FnMut(JsValue, u32, Array)); + pub fn for_each(this: &Array, callback: &mut dyn FnMut(JsValue, u32, Array)); /// The includes() method determines whether an array includes a certain /// element, returning true or false as appropriate. @@ -246,7 +246,7 @@ extern "C" { /// /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map) #[wasm_bindgen(method)] - pub fn map(this: &Array, predicate: &mut FnMut(JsValue, u32, Array) -> JsValue) -> Array; + pub fn map(this: &Array, predicate: &mut dyn FnMut(JsValue, u32, Array) -> JsValue) -> Array; /// The `Array.of()` method creates a new Array instance with a variable /// number of arguments, regardless of number or type of the arguments. @@ -303,7 +303,7 @@ extern "C" { #[wasm_bindgen(method)] pub fn reduce( this: &Array, - predicate: &mut FnMut(JsValue, JsValue, u32, Array) -> JsValue, + predicate: &mut dyn FnMut(JsValue, JsValue, u32, Array) -> JsValue, initial_value: &JsValue, ) -> JsValue; @@ -314,7 +314,7 @@ extern "C" { #[wasm_bindgen(method, js_name = reduceRight)] pub fn reduce_right( this: &Array, - predicate: &mut FnMut(JsValue, JsValue, u32, Array) -> JsValue, + predicate: &mut dyn FnMut(JsValue, JsValue, u32, Array) -> JsValue, initial_value: &JsValue, ) -> JsValue; @@ -345,7 +345,7 @@ extern "C" { /// Note: This method returns false for any condition put on an empty array. /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some) #[wasm_bindgen(method)] - pub fn some(this: &Array, predicate: &mut FnMut(JsValue) -> bool) -> bool; + pub fn some(this: &Array, predicate: &mut dyn FnMut(JsValue) -> bool) -> bool; /// The sort() method sorts the elements of an array in place and returns /// the array. The sort is not necessarily stable. The default sort @@ -1147,7 +1147,7 @@ extern "C" { /// /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/forEach) #[wasm_bindgen(method, js_name = forEach)] - pub fn for_each(this: &Map, callback: &mut FnMut(JsValue, JsValue)); + pub fn for_each(this: &Map, callback: &mut dyn FnMut(JsValue, JsValue)); /// The get() method returns a specified element from a Map object. /// @@ -2815,7 +2815,7 @@ extern "C" { /// /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/forEach) #[wasm_bindgen(method, js_name = forEach)] - pub fn for_each(this: &Set, callback: &mut FnMut(JsValue, JsValue, Set)); + pub fn for_each(this: &Set, callback: &mut dyn FnMut(JsValue, JsValue, Set)); /// The `has()` method returns a boolean indicating whether an element with /// the specified value exists in a [`Set`] object or not. @@ -4309,7 +4309,7 @@ extern "C" { /// /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) #[wasm_bindgen(constructor)] - pub fn new(cb: &mut FnMut(Function, Function)) -> Promise; + pub fn new(cb: &mut dyn FnMut(Function, Function)) -> Promise; /// The `Promise.all(iterable)` method returns a single `Promise` that /// resolves when all of the promises in the iterable argument have resolved @@ -4352,21 +4352,21 @@ extern "C" { /// /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch) #[wasm_bindgen(method)] - pub fn catch(this: &Promise, cb: &Closure) -> Promise; + pub fn catch(this: &Promise, cb: &Closure) -> Promise; /// The `then()` method returns a `Promise`. It takes up to two arguments: /// callback functions for the success and failure cases of the `Promise`. /// /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then) #[wasm_bindgen(method)] - pub fn then(this: &Promise, cb: &Closure) -> Promise; + pub fn then(this: &Promise, cb: &Closure) -> Promise; /// Same as `then`, only with both arguments provided. #[wasm_bindgen(method, js_name = then)] pub fn then2( this: &Promise, - resolve: &Closure, - reject: &Closure, + resolve: &Closure, + reject: &Closure, ) -> Promise; /// The `finally()` method returns a `Promise`. When the promise is settled, @@ -4380,7 +4380,7 @@ extern "C" { /// /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/finally) #[wasm_bindgen(method)] - pub fn finally(this: &Promise, cb: &Closure) -> Promise; + pub fn finally(this: &Promise, cb: &Closure) -> Promise; } /// Returns a handle to the global scope object. @@ -4499,7 +4499,7 @@ macro_rules! arrays { /// `Array.prototype.forEach()`. `TypedArray` is one of the typed array /// types here. #[wasm_bindgen(method, js_name = forEach)] - pub fn for_each(this: &$name, callback: &mut FnMut($ty, u32, $name)); + pub fn for_each(this: &$name, callback: &mut dyn FnMut($ty, u32, $name)); /// The `length` accessor property represents the length (in elements) of a /// typed array. diff --git a/crates/test/src/rt/mod.rs b/crates/test/src/rt/mod.rs index 4ddbd664025..597c95c8734 100644 --- a/crates/test/src/rt/mod.rs +++ b/crates/test/src/rt/mod.rs @@ -148,7 +148,7 @@ struct State { /// How to actually format output, either node.js or browser-specific /// implementation. - formatter: Box, + formatter: Box, } /// Representation of one test that needs to be executed. @@ -157,7 +157,7 @@ struct State { /// future is polled. struct Test { name: String, - future: Box>, + future: Box>, output: Rc>, } @@ -211,7 +211,7 @@ impl Context { console_error_panic_hook::set_once(); let formatter = match node::Node::new() { - Some(node) => Box::new(node) as Box, + Some(node) => Box::new(node) as Box, None => Box::new(browser::Browser::new()), }; Context { @@ -558,7 +558,7 @@ struct TestFuture { #[wasm_bindgen] extern "C" { #[wasm_bindgen(catch)] - fn __wbg_test_invoke(f: &mut FnMut()) -> Result<(), JsValue>; + fn __wbg_test_invoke(f: &mut dyn FnMut()) -> Result<(), JsValue>; } impl> Future for TestFuture { diff --git a/crates/webidl-tests/simple.rs b/crates/webidl-tests/simple.rs index a3d29515333..6216ba72cf4 100644 --- a/crates/webidl-tests/simple.rs +++ b/crates/webidl-tests/simple.rs @@ -196,16 +196,16 @@ fn callback() { static mut HIT: bool = false; let cb = Closure::wrap(Box::new(move || unsafe { HIT = true; - }) as Box); + }) as Box); o.invoke(cb.as_ref().unchecked_ref()); assert!(unsafe { HIT }); } - let cb = Closure::wrap(Box::new(move |a, b| a + b) as Box u32>); + let cb = Closure::wrap(Box::new(move |a, b| a + b) as Box u32>); assert_eq!(o.call_add(cb.as_ref().unchecked_ref()), 3); let cb = Closure::wrap( - Box::new(move |a: String, b| a.repeat(b)) as Box String> + Box::new(move |a: String, b| a.repeat(b)) as Box String> ); assert_eq!(o.call_repeat(cb.as_ref().unchecked_ref()), "abababab"); } diff --git a/crates/webidl/src/error.rs b/crates/webidl/src/error.rs index 0984359f0f0..17f24e58a7b 100644 --- a/crates/webidl/src/error.rs +++ b/crates/webidl/src/error.rs @@ -28,7 +28,7 @@ pub struct Error { } impl Fail for Error { - fn cause(&self) -> Option<&Fail> { + fn cause(&self) -> Option<&dyn Fail> { self.inner.cause() } diff --git a/examples/raytrace-parallel/src/lib.rs b/examples/raytrace-parallel/src/lib.rs index b3eabe0ac6d..d944416f2bc 100644 --- a/examples/raytrace-parallel/src/lib.rs +++ b/examples/raytrace-parallel/src/lib.rs @@ -114,7 +114,7 @@ impl WorkerPool { pub fn new(max: u32) -> Result { let callback = Closure::wrap(Box::new(|event: Event| { console_log!("unhandled event: {}", event.type_()); - }) as Box); + }) as Box); let mut workers = Vec::new(); for _ in 0..max { // TODO: what do do about `./worker.js`: diff --git a/examples/request-animation-frame/src/lib.rs b/examples/request-animation-frame/src/lib.rs index 81def4c6368..436a2deab23 100644 --- a/examples/request-animation-frame/src/lib.rs +++ b/examples/request-animation-frame/src/lib.rs @@ -7,7 +7,7 @@ fn window() -> web_sys::Window { web_sys::window().expect("no global `window` exists") } -fn request_animation_frame(f: &Closure) { +fn request_animation_frame(f: &Closure) { window() .request_animation_frame(f.as_ref().unchecked_ref()) .expect("should register `requestAnimationFrame` OK"); @@ -61,7 +61,7 @@ pub fn run() -> Result<(), JsValue> { // Schedule ourself for another requestAnimationFrame callback. request_animation_frame(f.borrow().as_ref().unwrap()); - }) as Box)); + }) as Box)); request_animation_frame(g.borrow().as_ref().unwrap()); Ok(()) diff --git a/src/closure.rs b/src/closure.rs index ab0bcbc8b90..a0663962a68 100644 --- a/src/closure.rs +++ b/src/closure.rs @@ -378,7 +378,7 @@ where // NB: we use a specific `T` for this `Closure` impl block to avoid every // call site having to provide an explicit, turbo-fished type like // `Closure::::once(...)`. -impl Closure { +impl Closure { /// Create a `Closure` from a function that can only be called once. /// /// Since we have no way of enforcing that JS cannot attempt to call this @@ -475,19 +475,19 @@ where { type Abi = u32; - fn into_abi(self, extra: &mut Stack) -> u32 { + fn into_abi(self, extra: &mut dyn Stack) -> u32 { (&*self.js).into_abi(extra) } } fn _check() { fn _assert() {} - _assert::<&Closure>(); - _assert::<&Closure>(); - _assert::<&Closure String>>(); - _assert::<&Closure>(); - _assert::<&Closure>(); - _assert::<&Closure String>>(); + _assert::<&Closure>(); + _assert::<&Closure>(); + _assert::<&Closure String>>(); + _assert::<&Closure>(); + _assert::<&Closure>(); + _assert::<&Closure String>>(); } impl fmt::Debug for Closure @@ -541,7 +541,7 @@ macro_rules! doit { ($( ($($var:ident)*) )*) => ($( - unsafe impl<$($var,)* R> WasmClosure for Fn($($var),*) -> R + 'static + unsafe impl<$($var,)* R> WasmClosure for dyn Fn($($var),*) -> R + 'static where $($var: FromWasmAbi + 'static,)* R: ReturnWasmAbi + 'static, { @@ -559,7 +559,7 @@ macro_rules! doit { // convert `ret` as it may throw (for `Result`, for // example) let ret = { - let f: *const Fn($($var),*) -> R = + let f: *const dyn Fn($($var),*) -> R = FatPtr { fields: (a, b) }.ptr; let mut _stack = GlobalStack::new(); $( @@ -584,7 +584,7 @@ macro_rules! doit { if a == 0 { return; } - drop(Box::from_raw(FatPtr:: R> { + drop(Box::from_raw(FatPtr:: R> { fields: (a, b) }.ptr)); } @@ -594,7 +594,7 @@ macro_rules! doit { } } - unsafe impl<$($var,)* R> WasmClosure for FnMut($($var),*) -> R + 'static + unsafe impl<$($var,)* R> WasmClosure for dyn FnMut($($var),*) -> R + 'static where $($var: FromWasmAbi + 'static,)* R: ReturnWasmAbi + 'static, { @@ -612,9 +612,9 @@ macro_rules! doit { // convert `ret` as it may throw (for `Result`, for // example) let ret = { - let f: *const FnMut($($var),*) -> R = + let f: *const dyn FnMut($($var),*) -> R = FatPtr { fields: (a, b) }.ptr; - let f = f as *mut FnMut($($var),*) -> R; + let f = f as *mut dyn FnMut($($var),*) -> R; let mut _stack = GlobalStack::new(); $( let $var = <$var as FromWasmAbi>::from_abi($var, &mut _stack); @@ -634,7 +634,7 @@ macro_rules! doit { if a == 0 { return; } - drop(Box::from_raw(FatPtr:: R> { + drop(Box::from_raw(FatPtr:: R> { fields: (a, b) }.ptr)); } @@ -650,7 +650,7 @@ macro_rules! doit { $($var: FromWasmAbi + 'static,)* R: ReturnWasmAbi + 'static { - type FnMut = FnMut($($var),*) -> R; + type FnMut = dyn FnMut($($var),*) -> R; fn into_fn_mut(self) -> Box { let mut me = Some(self); @@ -682,7 +682,7 @@ macro_rules! doit { drop(option_closure); result - }) as Box R>); + }) as Box R>); let js_val = closure.as_ref().clone(); @@ -714,7 +714,7 @@ doit! { // just this one! Maybe someone else can figure out voodoo so we don't have to // duplicate. -unsafe impl WasmClosure for Fn(&A) -> R +unsafe impl WasmClosure for dyn Fn(&A) -> R where A: RefFromWasmAbi, R: ReturnWasmAbi + 'static, { @@ -732,7 +732,7 @@ unsafe impl WasmClosure for Fn(&A) -> R // convert `ret` as it may throw (for `Result`, for // example) let ret = { - let f: *const Fn(&A) -> R = + let f: *const dyn Fn(&A) -> R = FatPtr { fields: (a, b) }.ptr; let mut _stack = GlobalStack::new(); let arg = ::ref_from_abi(arg, &mut _stack); @@ -751,7 +751,7 @@ unsafe impl WasmClosure for Fn(&A) -> R if a == 0 { return; } - drop(Box::from_raw(FatPtr:: R> { + drop(Box::from_raw(FatPtr:: R> { fields: (a, b) }.ptr)); } @@ -761,7 +761,7 @@ unsafe impl WasmClosure for Fn(&A) -> R } } -unsafe impl WasmClosure for FnMut(&A) -> R +unsafe impl WasmClosure for dyn FnMut(&A) -> R where A: RefFromWasmAbi, R: ReturnWasmAbi + 'static, { @@ -779,9 +779,9 @@ unsafe impl WasmClosure for FnMut(&A) -> R // convert `ret` as it may throw (for `Result`, for // example) let ret = { - let f: *const FnMut(&A) -> R = + let f: *const dyn FnMut(&A) -> R = FatPtr { fields: (a, b) }.ptr; - let f = f as *mut FnMut(&A) -> R; + let f = f as *mut dyn FnMut(&A) -> R; let mut _stack = GlobalStack::new(); let arg = ::ref_from_abi(arg, &mut _stack); (*f)(&*arg) @@ -799,7 +799,7 @@ unsafe impl WasmClosure for FnMut(&A) -> R if a == 0 { return; } - drop(Box::from_raw(FatPtr:: R> { + drop(Box::from_raw(FatPtr:: R> { fields: (a, b) }.ptr)); } @@ -815,7 +815,7 @@ impl WasmClosureFnOnce<(&A,), R> for T A: RefFromWasmAbi + 'static, R: ReturnWasmAbi + 'static { - type FnMut = FnMut(&A) -> R; + type FnMut = dyn FnMut(&A) -> R; fn into_fn_mut(self) -> Box { let mut me = Some(self); @@ -847,7 +847,7 @@ impl WasmClosureFnOnce<(&A,), R> for T drop(option_closure); result - }) as Box R>); + }) as Box R>); let js_val = closure.as_ref().clone(); diff --git a/src/convert/closures.rs b/src/convert/closures.rs index d878d66a81d..ba33ec6f434 100644 --- a/src/convert/closures.rs +++ b/src/convert/closures.rs @@ -8,13 +8,13 @@ use crate::throw_str; macro_rules! stack_closures { ($( ($cnt:tt $invoke:ident $invoke_mut:ident $($var:ident)*) )*) => ($( - impl<'a, 'b, $($var,)* R> IntoWasmAbi for &'a (Fn($($var),*) -> R + 'b) + impl<'a, 'b, $($var,)* R> IntoWasmAbi for &'a (dyn Fn($($var),*) -> R + 'b) where $($var: FromWasmAbi,)* R: ReturnWasmAbi { type Abi = WasmSlice; - fn into_abi(self, _extra: &mut Stack) -> WasmSlice { + fn into_abi(self, _extra: &mut dyn Stack) -> WasmSlice { unsafe { let (a, b): (usize, usize) = mem::transmute(self); WasmSlice { ptr: a as u32, len: b as u32 } @@ -34,7 +34,7 @@ macro_rules! stack_closures { // Scope all local variables before we call `return_abi` to // ensure they're all destroyed as `return_abi` may throw let ret = { - let f: &Fn($($var),*) -> R = mem::transmute((a, b)); + let f: &dyn Fn($($var),*) -> R = mem::transmute((a, b)); let mut _stack = GlobalStack::new(); $( let $var = <$var as FromWasmAbi>::from_abi($var, &mut _stack); @@ -44,7 +44,7 @@ macro_rules! stack_closures { ret.return_abi(&mut GlobalStack::new()) } - impl<'a, $($var,)* R> WasmDescribe for Fn($($var),*) -> R + 'a + impl<'a, $($var,)* R> WasmDescribe for dyn Fn($($var),*) -> R + 'a where $($var: FromWasmAbi,)* R: ReturnWasmAbi { @@ -57,13 +57,13 @@ macro_rules! stack_closures { } } - impl<'a, 'b, $($var,)* R> IntoWasmAbi for &'a mut (FnMut($($var),*) -> R + 'b) + impl<'a, 'b, $($var,)* R> IntoWasmAbi for &'a mut (dyn FnMut($($var),*) -> R + 'b) where $($var: FromWasmAbi,)* R: ReturnWasmAbi { type Abi = WasmSlice; - fn into_abi(self, _extra: &mut Stack) -> WasmSlice { + fn into_abi(self, _extra: &mut dyn Stack) -> WasmSlice { unsafe { let (a, b): (usize, usize) = mem::transmute(self); WasmSlice { ptr: a as u32, len: b as u32 } @@ -83,7 +83,7 @@ macro_rules! stack_closures { // Scope all local variables before we call `return_abi` to // ensure they're all destroyed as `return_abi` may throw let ret = { - let f: &mut FnMut($($var),*) -> R = mem::transmute((a, b)); + let f: &mut dyn FnMut($($var),*) -> R = mem::transmute((a, b)); let mut _stack = GlobalStack::new(); $( let $var = <$var as FromWasmAbi>::from_abi($var, &mut _stack); @@ -93,7 +93,7 @@ macro_rules! stack_closures { ret.return_abi(&mut GlobalStack::new()) } - impl<'a, $($var,)* R> WasmDescribe for FnMut($($var),*) -> R + 'a + impl<'a, $($var,)* R> WasmDescribe for dyn FnMut($($var),*) -> R + 'a where $($var: FromWasmAbi,)* R: ReturnWasmAbi { @@ -120,14 +120,14 @@ stack_closures! { (8 invoke8 invoke8_mut A B C D E F G H) } -impl<'a, 'b, A, R> IntoWasmAbi for &'a (Fn(&A) -> R + 'b) +impl<'a, 'b, A, R> IntoWasmAbi for &'a (dyn Fn(&A) -> R + 'b) where A: RefFromWasmAbi, R: ReturnWasmAbi, { type Abi = WasmSlice; - fn into_abi(self, _extra: &mut Stack) -> WasmSlice { + fn into_abi(self, _extra: &mut dyn Stack) -> WasmSlice { unsafe { let (a, b): (usize, usize) = mem::transmute(self); WasmSlice { @@ -150,7 +150,7 @@ unsafe extern "C" fn invoke1_ref( // Scope all local variables before we call `return_abi` to // ensure they're all destroyed as `return_abi` may throw let ret = { - let f: &Fn(&A) -> R = mem::transmute((a, b)); + let f: &dyn Fn(&A) -> R = mem::transmute((a, b)); let mut _stack = GlobalStack::new(); let arg = ::ref_from_abi(arg, &mut _stack); f(&*arg) @@ -158,7 +158,7 @@ unsafe extern "C" fn invoke1_ref( ret.return_abi(&mut GlobalStack::new()) } -impl<'a, A, R> WasmDescribe for Fn(&A) -> R + 'a +impl<'a, A, R> WasmDescribe for dyn Fn(&A) -> R + 'a where A: RefFromWasmAbi, R: ReturnWasmAbi, @@ -172,14 +172,14 @@ where } } -impl<'a, 'b, A, R> IntoWasmAbi for &'a mut (FnMut(&A) -> R + 'b) +impl<'a, 'b, A, R> IntoWasmAbi for &'a mut (dyn FnMut(&A) -> R + 'b) where A: RefFromWasmAbi, R: ReturnWasmAbi, { type Abi = WasmSlice; - fn into_abi(self, _extra: &mut Stack) -> WasmSlice { + fn into_abi(self, _extra: &mut dyn Stack) -> WasmSlice { unsafe { let (a, b): (usize, usize) = mem::transmute(self); WasmSlice { @@ -202,7 +202,7 @@ unsafe extern "C" fn invoke1_mut_ref( // Scope all local variables before we call `return_abi` to // ensure they're all destroyed as `return_abi` may throw let ret = { - let f: &mut FnMut(&A) -> R = mem::transmute((a, b)); + let f: &mut dyn FnMut(&A) -> R = mem::transmute((a, b)); let mut _stack = GlobalStack::new(); let arg = ::ref_from_abi(arg, &mut _stack); f(&*arg) @@ -210,7 +210,7 @@ unsafe extern "C" fn invoke1_mut_ref( ret.return_abi(&mut GlobalStack::new()) } -impl<'a, A, R> WasmDescribe for FnMut(&A) -> R + 'a +impl<'a, A, R> WasmDescribe for dyn FnMut(&A) -> R + 'a where A: RefFromWasmAbi, R: ReturnWasmAbi, diff --git a/src/convert/impls.rs b/src/convert/impls.rs index 6b9bb9cad89..b5ef4c30de2 100644 --- a/src/convert/impls.rs +++ b/src/convert/impls.rs @@ -64,21 +64,21 @@ macro_rules! type_wasm_native { type Abi = $c; #[inline] - fn into_abi(self, _extra: &mut Stack) -> $c { self as $c } + fn into_abi(self, _extra: &mut dyn Stack) -> $c { self as $c } } impl FromWasmAbi for $t { type Abi = $c; #[inline] - unsafe fn from_abi(js: $c, _extra: &mut Stack) -> Self { js as $t } + unsafe fn from_abi(js: $c, _extra: &mut dyn Stack) -> Self { js as $t } } impl IntoWasmAbi for Option<$t> { type Abi = $r; #[inline] - fn into_abi(self, _extra: &mut Stack) -> $r { + fn into_abi(self, _extra: &mut dyn Stack) -> $r { match self { None => $r { present: 0, @@ -96,7 +96,7 @@ macro_rules! type_wasm_native { type Abi = $r; #[inline] - unsafe fn from_abi(js: $r, _extra: &mut Stack) -> Self { + unsafe fn from_abi(js: $r, _extra: &mut dyn Stack) -> Self { if js.present == 0 { None } else { @@ -122,14 +122,14 @@ macro_rules! type_abi_as_u32 { type Abi = u32; #[inline] - fn into_abi(self, _extra: &mut Stack) -> u32 { self as u32 } + fn into_abi(self, _extra: &mut dyn Stack) -> u32 { self as u32 } } impl FromWasmAbi for $t { type Abi = u32; #[inline] - unsafe fn from_abi(js: u32, _extra: &mut Stack) -> Self { js as $t } + unsafe fn from_abi(js: u32, _extra: &mut dyn Stack) -> Self { js as $t } } impl OptionIntoWasmAbi for $t { @@ -152,7 +152,7 @@ macro_rules! type_64 { type Abi = Wasm64; #[inline] - fn into_abi(self, _extra: &mut Stack) -> Wasm64 { + fn into_abi(self, _extra: &mut dyn Stack) -> Wasm64 { Wasm64 { low: self as u32, high: (self >> 32) as u32, @@ -164,7 +164,7 @@ macro_rules! type_64 { type Abi = Wasm64; #[inline] - unsafe fn from_abi(js: Wasm64, _extra: &mut Stack) -> $t { + unsafe fn from_abi(js: Wasm64, _extra: &mut dyn Stack) -> $t { $t::from(js.low) | ($t::from(js.high) << 32) } } @@ -173,7 +173,7 @@ macro_rules! type_64 { type Abi = WasmOptional64; #[inline] - fn into_abi(self, _extra: &mut Stack) -> WasmOptional64 { + fn into_abi(self, _extra: &mut dyn Stack) -> WasmOptional64 { match self { None => WasmOptional64 { present: 0, @@ -195,7 +195,7 @@ macro_rules! type_64 { type Abi = WasmOptional64; #[inline] - unsafe fn from_abi(js: WasmOptional64, _extra: &mut Stack) -> Self { + unsafe fn from_abi(js: WasmOptional64, _extra: &mut dyn Stack) -> Self { if js.present == 0 { None } else { @@ -212,7 +212,7 @@ impl IntoWasmAbi for bool { type Abi = u32; #[inline] - fn into_abi(self, _extra: &mut Stack) -> u32 { + fn into_abi(self, _extra: &mut dyn Stack) -> u32 { self as u32 } } @@ -221,7 +221,7 @@ impl FromWasmAbi for bool { type Abi = u32; #[inline] - unsafe fn from_abi(js: u32, _extra: &mut Stack) -> bool { + unsafe fn from_abi(js: u32, _extra: &mut dyn Stack) -> bool { js != 0 } } @@ -244,7 +244,7 @@ impl IntoWasmAbi for char { type Abi = u32; #[inline] - fn into_abi(self, _extra: &mut Stack) -> u32 { + fn into_abi(self, _extra: &mut dyn Stack) -> u32 { self as u32 } } @@ -253,7 +253,7 @@ impl FromWasmAbi for char { type Abi = u32; #[inline] - unsafe fn from_abi(js: u32, _extra: &mut Stack) -> char { + unsafe fn from_abi(js: u32, _extra: &mut dyn Stack) -> char { char::from_u32_unchecked(js) } } @@ -275,7 +275,7 @@ impl OptionFromWasmAbi for char { impl IntoWasmAbi for *const T { type Abi = u32; - fn into_abi(self, _extra: &mut Stack) -> u32 { + fn into_abi(self, _extra: &mut dyn Stack) -> u32 { self as u32 } } @@ -283,7 +283,7 @@ impl IntoWasmAbi for *const T { impl FromWasmAbi for *const T { type Abi = u32; - unsafe fn from_abi(js: u32, _extra: &mut Stack) -> *const T { + unsafe fn from_abi(js: u32, _extra: &mut dyn Stack) -> *const T { js as *const T } } @@ -291,7 +291,7 @@ impl FromWasmAbi for *const T { impl IntoWasmAbi for *mut T { type Abi = u32; - fn into_abi(self, _extra: &mut Stack) -> u32 { + fn into_abi(self, _extra: &mut dyn Stack) -> u32 { self as u32 } } @@ -299,7 +299,7 @@ impl IntoWasmAbi for *mut T { impl FromWasmAbi for *mut T { type Abi = u32; - unsafe fn from_abi(js: u32, _extra: &mut Stack) -> *mut T { + unsafe fn from_abi(js: u32, _extra: &mut dyn Stack) -> *mut T { js as *mut T } } @@ -308,7 +308,7 @@ impl IntoWasmAbi for JsValue { type Abi = u32; #[inline] - fn into_abi(self, _extra: &mut Stack) -> u32 { + fn into_abi(self, _extra: &mut dyn Stack) -> u32 { let ret = self.idx; mem::forget(self); ret @@ -319,7 +319,7 @@ impl FromWasmAbi for JsValue { type Abi = u32; #[inline] - unsafe fn from_abi(js: u32, _extra: &mut Stack) -> JsValue { + unsafe fn from_abi(js: u32, _extra: &mut dyn Stack) -> JsValue { JsValue::_new(js) } } @@ -328,7 +328,7 @@ impl<'a> IntoWasmAbi for &'a JsValue { type Abi = u32; #[inline] - fn into_abi(self, _extra: &mut Stack) -> u32 { + fn into_abi(self, _extra: &mut dyn Stack) -> u32 { self.idx } } @@ -338,7 +338,7 @@ impl RefFromWasmAbi for JsValue { type Anchor = ManuallyDrop; #[inline] - unsafe fn ref_from_abi(js: u32, _extra: &mut Stack) -> Self::Anchor { + unsafe fn ref_from_abi(js: u32, _extra: &mut dyn Stack) -> Self::Anchor { ManuallyDrop::new(JsValue::_new(js)) } } @@ -346,7 +346,7 @@ impl RefFromWasmAbi for JsValue { impl IntoWasmAbi for Option { type Abi = T::Abi; - fn into_abi(self, extra: &mut Stack) -> T::Abi { + fn into_abi(self, extra: &mut dyn Stack) -> T::Abi { match self { None => T::none(), Some(me) => me.into_abi(extra), @@ -357,7 +357,7 @@ impl IntoWasmAbi for Option { impl FromWasmAbi for Option { type Abi = T::Abi; - unsafe fn from_abi(js: T::Abi, extra: &mut Stack) -> Self { + unsafe fn from_abi(js: T::Abi, extra: &mut dyn Stack) -> Self { if T::is_none(&js) { None } else { @@ -369,7 +369,7 @@ impl FromWasmAbi for Option { impl IntoWasmAbi for Clamped { type Abi = T::Abi; - fn into_abi(self, extra: &mut Stack) -> Self::Abi { + fn into_abi(self, extra: &mut dyn Stack) -> Self::Abi { self.0.into_abi(extra) } } @@ -377,7 +377,7 @@ impl IntoWasmAbi for Clamped { impl FromWasmAbi for Clamped { type Abi = T::Abi; - unsafe fn from_abi(js: T::Abi, extra: &mut Stack) -> Self { + unsafe fn from_abi(js: T::Abi, extra: &mut dyn Stack) -> Self { Clamped(T::from_abi(js, extra)) } } @@ -386,7 +386,7 @@ impl IntoWasmAbi for () { type Abi = (); #[inline] - fn into_abi(self, _extra: &mut Stack) { + fn into_abi(self, _extra: &mut dyn Stack) { self } } @@ -394,7 +394,7 @@ impl IntoWasmAbi for () { impl ReturnWasmAbi for Result { type Abi = T::Abi; - fn return_abi(self, extra: &mut Stack) -> Self::Abi { + fn return_abi(self, extra: &mut dyn Stack) -> Self::Abi { match self { Ok(v) => v.into_abi(extra), Err(e) => crate::throw_val(e), diff --git a/src/convert/slices.rs b/src/convert/slices.rs index a3cb6ec90b3..7713719f3f8 100644 --- a/src/convert/slices.rs +++ b/src/convert/slices.rs @@ -32,7 +32,7 @@ macro_rules! vectors { type Abi = WasmSlice; #[inline] - fn into_abi(self, extra: &mut Stack) -> WasmSlice { + fn into_abi(self, extra: &mut dyn Stack) -> WasmSlice { let ptr = self.as_ptr(); let len = self.len(); mem::forget(self); @@ -51,7 +51,7 @@ macro_rules! vectors { type Abi = WasmSlice; #[inline] - unsafe fn from_abi(js: WasmSlice, extra: &mut Stack) -> Self { + unsafe fn from_abi(js: WasmSlice, extra: &mut dyn Stack) -> Self { let ptr = <*mut $t>::from_abi(js.ptr, extra); let len = js.len as usize; Vec::from_raw_parts(ptr, len, len).into_boxed_slice() @@ -67,7 +67,7 @@ macro_rules! vectors { type Abi = WasmSlice; #[inline] - fn into_abi(self, extra: &mut Stack) -> WasmSlice { + fn into_abi(self, extra: &mut dyn Stack) -> WasmSlice { WasmSlice { ptr: self.as_ptr().into_abi(extra), len: self.len() as u32, @@ -83,7 +83,7 @@ macro_rules! vectors { type Abi = WasmSlice; #[inline] - fn into_abi(self, extra: &mut Stack) -> WasmSlice { + fn into_abi(self, extra: &mut dyn Stack) -> WasmSlice { (&*self).into_abi(extra) } } @@ -97,7 +97,7 @@ macro_rules! vectors { type Anchor = &'static [$t]; #[inline] - unsafe fn ref_from_abi(js: WasmSlice, extra: &mut Stack) -> &'static [$t] { + unsafe fn ref_from_abi(js: WasmSlice, extra: &mut dyn Stack) -> &'static [$t] { slice::from_raw_parts( <*const $t>::from_abi(js.ptr, extra), js.len as usize, @@ -110,7 +110,7 @@ macro_rules! vectors { type Anchor = &'static mut [$t]; #[inline] - unsafe fn ref_mut_from_abi(js: WasmSlice, extra: &mut Stack) + unsafe fn ref_mut_from_abi(js: WasmSlice, extra: &mut dyn Stack) -> &'static mut [$t] { slice::from_raw_parts_mut( @@ -130,7 +130,7 @@ if_std! { impl IntoWasmAbi for Vec where Box<[T]>: IntoWasmAbi { type Abi = as IntoWasmAbi>::Abi; - fn into_abi(self, extra: &mut Stack) -> Self::Abi { + fn into_abi(self, extra: &mut dyn Stack) -> Self::Abi { self.into_boxed_slice().into_abi(extra) } } @@ -142,7 +142,7 @@ if_std! { impl FromWasmAbi for Vec where Box<[T]>: FromWasmAbi { type Abi = as FromWasmAbi>::Abi; - unsafe fn from_abi(js: Self::Abi, extra: &mut Stack) -> Self { + unsafe fn from_abi(js: Self::Abi, extra: &mut dyn Stack) -> Self { >::from_abi(js, extra).into() } } @@ -155,7 +155,7 @@ if_std! { type Abi = as IntoWasmAbi>::Abi; #[inline] - fn into_abi(self, extra: &mut Stack) -> Self::Abi { + fn into_abi(self, extra: &mut dyn Stack) -> Self::Abi { self.into_bytes().into_abi(extra) } } @@ -168,7 +168,7 @@ if_std! { type Abi = as FromWasmAbi>::Abi; #[inline] - unsafe fn from_abi(js: Self::Abi, extra: &mut Stack) -> Self { + unsafe fn from_abi(js: Self::Abi, extra: &mut dyn Stack) -> Self { String::from_utf8_unchecked(>::from_abi(js, extra)) } } @@ -182,7 +182,7 @@ impl<'a> IntoWasmAbi for &'a str { type Abi = <&'a [u8] as IntoWasmAbi>::Abi; #[inline] - fn into_abi(self, extra: &mut Stack) -> Self::Abi { + fn into_abi(self, extra: &mut dyn Stack) -> Self::Abi { self.as_bytes().into_abi(extra) } } @@ -198,7 +198,7 @@ impl RefFromWasmAbi for str { type Anchor = &'static str; #[inline] - unsafe fn ref_from_abi(js: Self::Abi, extra: &mut Stack) -> Self::Anchor { + unsafe fn ref_from_abi(js: Self::Abi, extra: &mut dyn Stack) -> Self::Anchor { str::from_utf8_unchecked(<[u8]>::ref_from_abi(js, extra)) } } @@ -210,7 +210,7 @@ if_std! { type Abi = WasmSlice; #[inline] - fn into_abi(self, extra: &mut Stack) -> WasmSlice { + fn into_abi(self, extra: &mut dyn Stack) -> WasmSlice { let ptr = self.as_ptr(); let len = self.len(); mem::forget(self); @@ -229,7 +229,7 @@ if_std! { type Abi = WasmSlice; #[inline] - unsafe fn from_abi(js: WasmSlice, extra: &mut Stack) -> Self { + unsafe fn from_abi(js: WasmSlice, extra: &mut dyn Stack) -> Self { let ptr = <*mut JsValue>::from_abi(js.ptr, extra); let len = js.len as usize; Vec::from_raw_parts(ptr, len, len).into_boxed_slice() diff --git a/src/convert/traits.rs b/src/convert/traits.rs index a1818212721..874c309a700 100644 --- a/src/convert/traits.rs +++ b/src/convert/traits.rs @@ -13,7 +13,7 @@ pub trait IntoWasmAbi: WasmDescribe { /// Convert `self` into `Self::Abi` so that it can be sent across the wasm /// ABI boundary. - fn into_abi(self, extra: &mut Stack) -> Self::Abi; + fn into_abi(self, extra: &mut dyn Stack) -> Self::Abi; } /// A trait for anything that can be recovered by-value from the wasm ABI @@ -32,7 +32,7 @@ pub trait FromWasmAbi: WasmDescribe { /// This is only safe to call when -- and implementations may assume that -- /// the supplied `Self::Abi` was previously generated by a call to `::into_abi()` or the moral equivalent in JS. - unsafe fn from_abi(js: Self::Abi, extra: &mut Stack) -> Self; + unsafe fn from_abi(js: Self::Abi, extra: &mut dyn Stack) -> Self; } /// A trait for anything that can be recovered as some sort of shared reference @@ -55,7 +55,7 @@ pub trait RefFromWasmAbi: WasmDescribe { /// # Safety /// /// Same as `FromWasmAbi::from_abi`. - unsafe fn ref_from_abi(js: Self::Abi, extra: &mut Stack) -> Self::Anchor; + unsafe fn ref_from_abi(js: Self::Abi, extra: &mut dyn Stack) -> Self::Anchor; } /// Dual of the `RefFromWasmAbi` trait, except for mutable references. @@ -65,7 +65,7 @@ pub trait RefMutFromWasmAbi: WasmDescribe { /// Same as `RefFromWasmAbi::Anchor` type Anchor: DerefMut; /// Same as `RefFromWasmAbi::ref_from_abi` - unsafe fn ref_mut_from_abi(js: Self::Abi, extra: &mut Stack) -> Self::Anchor; + unsafe fn ref_mut_from_abi(js: Self::Abi, extra: &mut dyn Stack) -> Self::Anchor; } /// Indicates that this type can be passed to JS as `Option`. @@ -120,12 +120,12 @@ pub trait ReturnWasmAbi: WasmDescribe { /// Same as `IntoWasmAbi::into_abi`, except that it may throw and never /// return in the case of `Err`. - fn return_abi(self, extra: &mut Stack) -> Self::Abi; + fn return_abi(self, extra: &mut dyn Stack) -> Self::Abi; } impl ReturnWasmAbi for T { type Abi = T::Abi; - fn return_abi(self, extra: &mut Stack) -> Self::Abi { + fn return_abi(self, extra: &mut dyn Stack) -> Self::Abi { self.into_abi(extra) } }