Skip to content

Commit

Permalink
Merge pull request #1571 from alexcrichton/less-warnings
Browse files Browse the repository at this point in the history
Use `dyn` with all trait objects
  • Loading branch information
alexcrichton authored Jun 3, 2019
2 parents c876bd6 + 82467f9 commit 618b5d3
Show file tree
Hide file tree
Showing 15 changed files with 148 additions and 146 deletions.
38 changes: 20 additions & 18 deletions crates/backend/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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")
}

Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -637,7 +637,7 @@ impl ToTokens for ast::ImportType {
type Abi = <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)
}
}
Expand All @@ -656,7 +656,7 @@ impl ToTokens for ast::ImportType {
type Abi = <JsValue 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 {
#rust_name {
obj: JsValue::from_abi(js, extra).into(),
}
Expand All @@ -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)
}
}
Expand All @@ -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 = <JsValue as RefFromWasmAbi>::ref_from_abi(js, extra);
core::mem::ManuallyDrop::new(#rust_name {
obj: core::mem::ManuallyDrop::into_inner(tmp).into(),
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
}
Expand All @@ -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)
}
Expand Down Expand Up @@ -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 => "",
Expand Down Expand Up @@ -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");
}
Expand Down Expand Up @@ -1125,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
}
}
Expand All @@ -1137,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")
Expand Down Expand Up @@ -1331,23 +1333,23 @@ impl ToTokens for ast::Dictionary {
impl IntoWasmAbi for #name {
type Abi = <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)
}
}

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)
}
}

impl FromWasmAbi for #name {
type Abi = <Object as FromWasmAbi>::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) }
}
}
Expand All @@ -1370,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 = <Object as RefFromWasmAbi>::ref_from_abi(js, extra);
ManuallyDrop::new(#name {
obj: ManuallyDrop::into_inner(tmp),
Expand Down
4 changes: 2 additions & 2 deletions crates/backend/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl Diagnostic {
}
}

pub fn spanned_error<T: Into<String>>(node: &ToTokens, text: T) -> Diagnostic {
pub fn spanned_error<T: Into<String>>(node: &dyn ToTokens, text: T) -> Diagnostic {
Diagnostic {
inner: Repr::Single {
text: text.into(),
Expand Down Expand Up @@ -89,7 +89,7 @@ impl From<Error> 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();
Expand Down
2 changes: 1 addition & 1 deletion crates/cli-support/src/js/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1086,7 +1086,7 @@ impl<'a> Context<'a> {
fn bind(
&mut self,
name: &str,
f: &Fn(&mut Self) -> Result<String, Error>,
f: &dyn Fn(&mut Self) -> Result<String, Error>,
) -> Result<(), Error> {
if !self.wasm_import_needed(name) {
return Ok(());
Expand Down
12 changes: 6 additions & 6 deletions crates/futures/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ use wasm_bindgen::prelude::*;
pub struct JsFuture {
resolved: oneshot::Receiver<JsValue>,
rejected: oneshot::Receiver<JsValue>,
callbacks: Option<(Closure<FnMut(JsValue)>, Closure<FnMut(JsValue)>)>,
callbacks: Option<(Closure<dyn FnMut(JsValue)>, Closure<dyn FnMut(JsValue)>)>,
}

impl fmt::Debug for JsFuture {
Expand All @@ -152,11 +152,11 @@ impl From<Promise> for JsFuture {
let mut tx1 = Some(tx1);
let resolve = Closure::wrap(Box::new(move |val| {
drop(tx1.take().unwrap().send(val));
}) as Box<FnMut(_)>);
}) as Box<dyn FnMut(_)>);
let mut tx2 = Some(tx2);
let reject = Closure::wrap(Box::new(move |val| {
drop(tx2.take().unwrap().send(val));
}) as Box<FnMut(_)>);
}) as Box<dyn FnMut(_)>);

js.then2(&resolve, &reject);

Expand Down Expand Up @@ -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<Future<Item = JsValue, Error = JsValue>>) -> Promise {
fn _future_to_promise(future: Box<dyn Future<Item = JsValue, Error = JsValue>>) -> Promise {
let mut future = Some(executor::spawn(future));
return Promise::new(&mut |resolve, reject| {
Package::poll(&Arc::new(Package {
Expand All @@ -247,7 +247,7 @@ fn _future_to_promise(future: Box<Future<Item = JsValue, Error = JsValue>>) -> 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<Box<Future<Item = JsValue, Error = JsValue>>>>,
spawn: RefCell<Spawn<Box<dyn Future<Item = JsValue, Error = JsValue>>>>,

// The current state of this future, expressed in an enum below. This
// indicates whether we're currently polling the future, received a
Expand Down Expand Up @@ -379,7 +379,7 @@ fn _future_to_promise(future: Box<Future<Item = JsValue, Error = JsValue>>) -> P
let myself = slot2.borrow_mut().take();
debug_assert!(myself.is_some());
Package::poll(&me);
}) as Box<FnMut(JsValue)>);
}) as Box<dyn FnMut(JsValue)>);
promise.then(&closure);
*slot.borrow_mut() = Some(closure);
}
Expand Down
Loading

0 comments on commit 618b5d3

Please sign in to comment.